【问题标题】:Keeping Texture2D object(s) for interpolation HLSL为插值 HLSL 保留 Texture2D 对象
【发布时间】:2017-12-08 03:49:49
【问题描述】:

最近有人向 OBS Studio 添加了一个模块,允许任何人将自己的着色器合并到 OBS 中。我从来没有接触过编写着色器,但是在阅读了一些材料之后,我明白了要点,它是一个返回一些内存的函数,表示特定像素的 RGBA 值。

这就是问题所在,我对此太陌生了,在我看来好像有几种不同的高级着色器语言?我不知道 OBS Studio 使用的是哪一个,https://github.com/nleseul/obs-shaderfilter 的作者似乎也不知道。任何指向什么语法/什么文档的指针当然都会非常感激。

我的目标是做一个非常愚蠢的运动模糊。也就是说,虽然我的目标是我想在某种缓冲区中保留几帧以供使用,但我认为这对于其他效果来说是一件非常有用的事情......这就是我卡住的地方.这是我从Shaders for Game Programmers and Artists pg.87 得到的内容,适用于使用着色器插件*

uniform float4 blur_factor;
texture2d previmage;
//texture2d image; //this is the input data we're playing around with

float4 mainImage(VertData v_in) : TARGET
{   
    float4 originalFrame = image.Sample(textureSampler, v_in.uv);
    float4 oldFrame = previmage.Sample(textureSampler, v_in.uv);

    //this function's going pixel by pixel, I should be pushing
    //to the frame buffer here* or there should be some way of modifying
    //the frame buffer pixel by pixel, second option makes more sense to do
    if(v_in.uv.x == 1 && v_in.uv.y == 1){
        //it couldn't have been this easy...it's never this easy
        //uncommenting the line below clearly causes a problem, I don't have a debugger for this
        //previmage = image;
        //this doesn't work either, wishful thinking
        //previmage = texture2d(image);
    }
    //this may not actually be the function to use for a motion blur but at the very least it's mixing two textures together so that I'd have a proof of concept working*
    return lerp(originalFrame,oldFrame,blur_factor);
}

【问题讨论】:

    标签: hlsl


    【解决方案1】:

    所以,幸运的是,当着色器失败时,错误实际上会输出到 OBS 的日志中。我有一种直觉,在全局声明变量时发生了一些事情。对于我写的初始代码,我得到了这个:

    10:53:49.413: C:\Program Files (x86)\obs-studio\bin\64bit\ (Pixel shader, technique Draw, pass 0)(38,40-50): error X3004: undeclared identifier 'blur_factor'
    10:53:49.413: C:\Program Files (x86)\obs-studio\bin\64bit\ (Pixel shader, technique Draw, pass 0)(38,12-51): error X3013: 'lerp': no matching 3 parameter intrinsic function
    10:53:49.413: C:\Program Files (x86)\obs-studio\bin\64bit\ (Pixel shader, technique Draw, pass 0)(38,12-51): error X3013: Possible intrinsic functions are:
    10:53:49.413: C:\Program Files (x86)\obs-studio\bin\64bit\ (Pixel shader, technique Draw, pass 0)(38,12-51): error X3013:     lerp(float|half|min10float|min16float, float|half|min10float|min16float, float|half|min10float|min16float)
    

    所以简而言之...lerp 实际上不是我想要使用的,一开始就没有用正确的数据类型正确调用它。因此,在折腾之后,我决定编写着色器,假设我可以制作一组 texture2d...

    texture2d previmage[8];
    
    float4 mainImage(VertData v_in) : TARGET{
       //...etc etc
       //manipulating the array, copying over the texture2d OBS provides
    }
    

    然后我明白了:

    11:12:46.880: C:\Program Files (x86)\obs-studio\bin\64bit\ (Pixel shader, technique Draw, pass 0)(27,3-31): error X3025: global variables are implicitly constant, enable compatibility mode to allow modification
    

    哦...所以...HLSL 中的全局变量有一个我不知道的奇怪行为,它使这种方法有点静音...不能修改常量值,我需要一些帧缓冲区。

    潜在的解决方案?静态变量!

    float4 mainImage(VertData v_in) : TARGET
    {   
        int i = 0;
        static texture2d previmage[8] = {image,image,image,image,image,image,image,image};
    
        if(v_in.uv.x == 1 && v_in.uv.y == 1){
            for(i = 0; i <= 6; i++){
                previmage[i+1] = previmage[i];
            }
            previmage[0] = image;
        }
    
        float4 sum = 0;
        float4 samples[8];
    
        for(i = 0; i < 8; i++){
            samples[i] = previmage[i].Sample(textureSampler, v_in.uv);
            sum += samples[i];
        }
    
        return sum / 8.0;
    }
    

    现在...好吧,至少事情没有抛出错误,而是渲染到屏幕上,不幸的是...我看不到/看不到效果...这里可能存在语义错误*或者...也许 8 帧不足以真正产生明显的运动模糊。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-26
      • 2011-07-21
      • 2019-01-28
      • 2016-07-08
      • 2020-04-22
      • 1970-01-01
      相关资源
      最近更新 更多