there are three global variable g_A, g_B, g_C
I want to do this; g_C = g_A * g_B
I tried this;
technique RenderScene
{
g_C = g_A * g_B;
pass P0
{
VertexShader = compile vs_2_0 RenderSceneVS();
PixelShader = compile ps_2_0 RenderScenePS();
}
}
However, it’s improper syntax.
What should I do?
Must I calculate this variable in c++ code before rendering?
DirectX 9 and 10 Effects support “preshaders”, where static expressions will be pulled out to be executed on the CPU automatically.
See
D3DXSHADER_NO_PRESHADERin the documentation, which is a flag that suppresses this behavior. Here’s a web link: http://msdn.microsoft.com/en-us/library/windows/desktop/bb205441(v=vs.85).aspxYour declaration of
g_Cis missing bothstaticand the type e.g.float. You’ll also need to move it into global scope.When you compile it with fxc, you might see something like the following (note the
preshaderblock after the comment block):I compiled the following:
with
fxc /Tfx_2_0 t.fxto generate the listing. They’re not very interesting shaders…