2017-12-05 19 views
0

最近誰かがOBS Studioにモジュールを追加しました。誰も自分のシェーダをOBSに組み込むことができます。私はシェイダーを書いたことは一度も触れていませんでしたが、いくつかの資料を読んだら、要点を得ました。特定のピクセルのRGBA値を表すメモリを返す関数です。補間用のTexture2Dオブジェクトを保持するHLSL

ここに問題があります。これはあまりにも新しく、いくつかの異なる高水準シェーダ言語があるように私には見えますか? OBS Studioが使用している手がかりが1つもないので、https://github.com/nleseul/obs-shaderfilterの作者はわからないようです。どのような構文/どのドキュメンテーションがもちろん大いに感謝されるでしょうへのポインタ。

私がしようとしているのは、非常にぼんやりした動きのぼやけです。つまり、いくつかのフレームをいくつかのバッファに入れておきたいのですが、他のエフェクトではそれが非常に有用なものになると思います。それが私が立ち往生した場所です。ここで私はシェーダープラグイン/ wが機能するように適合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); 
} 

答えて

0

だから、幸いにもそれはシェーダがエラーに失敗したときに実際に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は、私が使用することを探していたものを、実際にはなかった、適切に開始するために右のデータ型とそれを呼び出すことはありませんでした。ああ

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 

...そう...グローバル変数:だから...私は私がにTexture2Dの配列を作ることができると仮定すると、シェーダを書くことを決めたことを

texture2d previmage[8]; 

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

を投げた後、それから私はこれを取得します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フレームでは目に見えるモーションブラーを作るのに十分ではありません。

関連する問題