0

3 つのグローバル変数 g_A、g_B、g_C があります。g_C = g_A * g_B

これを試しました。

technique RenderScene
{
    g_C = g_A * g_B;

    pass P0
    {          
        VertexShader = compile vs_2_0 RenderSceneVS();
        PixelShader  = compile ps_2_0 RenderScenePS(); 
    }
}

しかし、それは不適切な構文です。私は何をすべきか?

レンダリングする前に、C++ コードでこの変数を計算する必要がありますか?

4

1 に答える 1

1

DirectX 9 および 10 のエフェクトは、CPU 上で自動的に実行される静的な式が引き出される「プレシェーダー」をサポートします。

D3DXSHADER_NO_PRESHADERこの動作を抑制するフラグであるドキュメントを参照してください。Web リンクは次のとおりです: http://msdn.microsoft.com/en-us/library/windows/desktop/bb205441(v=vs.85).aspx

の宣言には、タイプ eg のg_C両方がありません。また、グローバル スコープに移動する必要があります。staticfloat

fxc でコンパイルすると、次のようになります (preshaderコメント ブロックの後のブロックに注意してください)。

technique RenderScene
{
    pass P0
    {
        vertexshader = 
            asm {
            //
            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
            //
            // Parameters:
            //
            //   float4 g_A;
            //   float4 g_B;
            //
            //
            // Registers:
            //
            //   Name         Reg   Size
            //   ------------ ----- ----
            //   g_A          c0       1
            //   g_B          c1       1
            //

                preshader
                mul c0, c0, c1

            // approximately 1 instruction used
            //
            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
                vs_2_0
                mov oPos, c0

            // approximately 1 instruction slot used
            };

        pixelshader = 
            asm {
            //
            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
                ps_2_0
                def c0, 0, 0, 0, 0
                mov r0, c0.x
                mov oC0, r0

            // approximately 2 instruction slots used
            };
    }
}

私は以下をコンパイルしました:

float4 g_A;
float4 g_B;
static float4 g_C = g_A * g_B;

float4 RenderSceneVS() : POSITION
{
    return g_C;
}

float4 RenderScenePS() : COLOR
{
    return 0.0;
}

technique RenderScene
{
    pass P0
    {          
        VertexShader = compile vs_2_0 RenderSceneVS();
        PixelShader  = compile ps_2_0 RenderScenePS();
    }
}

fxc /Tfx_2_0 t.fxリストを生成します。それらはあまり興味深いシェーダーではありません...

于 2012-07-10T22:59:23.830 に答える