DirectX9 Shader - General Question

Oct 31, 2010 at 5:24pm
Hello everybody,

I hope this is the right board to post in. I'm programming a game in C++ and DirectX9 and just added a shader to my project. The shader is very simple and just modifies the color of some pixels a little. Something about 10-15 lines of HLSL code.

The variables my shader is using however appear a bit bigger to me. I'm using about 20 different colors that have to be passed from C++ to the shader before each draw call. Every color is represented by 4 float values (R, G, B and alpha).

shared float4 colors[20];

Now there are about 30 of these color sets (consisting of 20 colors each) in my project during runtime. So every time I draw an object I have to reinitialize the shader and tell it about the 20 colors it should use next. That would mean every draw call (30 per frame) would require that I copy 20 * 4 * 4 byte = 320 byte from RAM to the graphic card's memory.

myShader->SetFloatArray( /* pass my 20 * 4 floats here */);

My question is, if it is generally better to use this shader like I described and reinitialize the shared variables before each drawing call - or if it is better to create one shader for each of my color sets (in my example 30 shader instances) and initialize them all just once.

I hope my question comes clear. Thanks a lot for your help!

Greetings
Xoric
Last edited on Oct 31, 2010 at 5:27pm
Topic archived. No new replies allowed.