Jump to content
  • Advertisement
Sign in to follow this  
parroteye

Pre-process shader code from file before compile

This topic is 994 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!