Jump to content
  • Advertisement
Sign in to follow this  

Management of multiple shaders

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

I would like to know some tips on how to manage multiple shader effects for my game

currently I have a basic shader going which only transforms vertices and applies texture data...

so what if I want to have some nice shader effects also? I have not tried to implement any of this yet but I can already see that changing shader programs will not allow me to continue rendering my quad system unless I just bring over the new shader all of what I have

so yeah I just want to hear tips on how to design this.

Share this post

Link to post
Share on other sites
I implemented 3-level object structure:

Shader - container of single OpenGL shader object
Program - collection of Shaders - container for OpenGL program object
Material - specific rendering implementation - parameters + Program

Each mesh fragment refers to one material. In rendering phase, this material virtual ::bind() method will be called:
- it detects, whether that material is already bound to render context, if yes do nothing
- if it is not bound, a ::bind() method of Program will be called
- after that, uniforms will be set

In ::bind() method of program:
- If shaders are not yet compiled, ask Shaders to compile their code (creating OpenGL shader objects)
- If program is not yet linked, a new OpenGL program is created and OpenGL shader objects linked
- OpenGL program object is bound (GLUseProgram)

So basically whenever a object with new material is used, the OpenGL state is updated by relevant container objects.
You still should sort your objects by Material/Program while rendering because switching programs is expensive - but this can be optimized later.

Share this post

Link to post
Share on other sites
Its difficult to determine what you mean from your question. Do you mean you are worried about duplicating functionality in each of your shaders, or about how to manage assigning different shaders to different meshes?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!