Sign in to follow this  

How many dedicated Shaders to use?

This topic is 1107 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

So I've read its best to write dedicated shaders for specific purposes rather than bloat them with too many conditionals. And it makes sense. But I look at how many options are possible and it quickly becomes overwhelming:

 

1. Normal mapping

2. GPU Tesselation / Displacement mapping

3. Shadow mapping

4. Animation/Skinning

 

I could go with or without the each of these for any particular shader, resulting in 16 possible shaders. When you consider I have to write shaders for shadow passes for different types of lights (point, spot, directional, etc). the number of shaders quickly becomes ridiculous.

 

What's a smart way to cluster these and keep it reasonable?

 

 

Share this post


Link to post
Share on other sites

You don't need to write a shader for everything from scratch.

Both DirectX and OpenGL are offering to merge multiple vertex/fragment shaders to one.

I guess this has also a performance impact as only parts of a shader get changed but I don't know.

 

In OpenGL (GLSL) you can basically define two shaders with the main method as well as some shaders defining methods used by both main-shaders.

On creation you link the additional shaders together with the main shaders to one program and you are ready to go.

Share this post


Link to post
Share on other sites

"How many dedicated Shaders to use?"

 

as many as you need! Just try to minimize the work as suggested and try to see the repeating parts - don't write the same code multiple times, use include files to store common functions. 

 

Also, store all the compiled shaders to disk - as the project grows bigger the number of shaders increase and the length of shader files too, so compiling gets slower and slower. I have a shader manager which at start up loads the shader cache file (if it exists). After it checks if the non-compiled shader on disk is newer than the shader cache version - if so, the shader from the disk is loaded and compiled. This method supports also recompilation of the shaders while the program is running (very useful feature). The shader cache stores (for each shader) the shader file name, shader entry point, shader file date/time and the shader blob data. 

 

Cheers!

Share this post


Link to post
Share on other sites

This topic is 1107 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.

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