Sign in to follow this  
Sc4Freak

Shader Combinatorial Explosion

Recommended Posts

I'm sure many of you have encountered this problem before. I've got a material which can request to have any number of effects put onto it, such as specular lighting/maps, normal maps, etc. Currently, I have 1 shader for every combination possible, and it has become clear to me that as I add more possibilities, the number of shaders needed is going to get out of hand. Currently I have 5 possibilities (normal map, specular lighting, specular maps, diffuse maps, detail maps) and as such there are 31 combinations and 31 techniques in a large .fx file. Adding one more possibility and I need to have 63. Add another and I need 127. And so on. How can I handle this combinatorial explosion?

Share this post


Link to post
Share on other sites
How about creating the techniques dynamically and using D3DXCompileShader rather than D3DXCompileShaderFromFile? You can still keep the rest of the code in the .fx file, read that in and combine that with your generated techniques.

Share this post


Link to post
Share on other sites
I build my shaders out of smaller chunks, and combine them together programmatically, like what jaafit was saying. Works out pretty well. I've posted more at length here at GameDev before, so if you're interested you can search for my posts on the matter.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this