I was just wondering whether to use D3D_SHADER_MACROor not to
control different effects in the same shader. unfortunatley in order to
change the effect via macro the shader needs to be rebuilt. Is there any
reason (performance wise) why I shouldn’t just use a boolas it would
provide more flexibility as far as changing effects runtime where
different meshes share the same effect though different parts of the
shader (i.e turning on\off culling or different light counts in use
etc…), or should I just create a seperate VS,HS etc… for each
effect, though that would mean more/repeating code being built at
startup with only slight changes however I’m assuming faster runtime.
also if wanting to precompile my shaders would I just need to use the 2
following functions, D3DCompile() and D3DWriteBlobToFile().
then for loading is it just D3DReadFileToBlob() before calling
thanks for any insight into the best way to go about this.
Please log in or register to post a reply.
You can use bools for this, however you probably want to make sure
they’re uniform bools to ensure that you don’t end up creating a
dynamic branch in the shader - which can be quite slow even if all of
the threads (vertices/pixels) are branching the same direction. You’d
set up multiple techniques, each of which calls the shaders with a
different combination of bools, then select the correct technique to
render with. The shader compiler will optimize away the uniform bools in
this case, producing separate compiled versions of the shader for each
As for the functions to call, yes, I think you’ve got it right. You can
also use D3DCompileFromFile if your HLSL source is in a file.
Thanks Reedbeta for the explanation, sounds like it will work out great
using that method. turns out I’ll have to pass on D3DWriteBlobToFile()
and D3DReadFileToBlob() as I just realised they are part of the windows
developer preview, but D3DCompileFromFile() works great, thanks again!