Pre-process shader code from file before compile

Started by
1 comment, last by LandonJerre 8 years ago

First of all sorry if it is a stupid question, but I am very new to D3D and first round of googling didn't help much (maybe I did it with wrong keywords).

So I have a shader with a bunch of #define I want to set at load time and have different version of the shader depending on the value set this way. What is the best way to preprocess the shader source before compiling it into a shader? Looking at tutorials online all I can find is D3DCompileFromFile or variants like that. This apparently is not friendly to what I want to do.

Is there something like "D3DCompileFromString" ? Or anyway, what is the best way to do that?

Thank you!

Advertisement

Would this help https://msdn.microsoft.com/en-us/library/windows/desktop/dd607324(v=vs.85).aspx

The first parameter could be your string of HLSL code.

D3DCompileFromFile, D3DCompile both have a parameter called pDefines (D3D_SHADER_MACRO* type, it is an array), which is a list of defines that will be used during the compilation. Apart from these, there's a D3DPreprocess call too that just runs the preprocessor on your source, and again this take a D3D_SHADER_MACRO array as an input. With these, and using classic C/C++ style conditional compilation directives, you should be able to achieve what you want.

This topic is closed to new replies.

Advertisement