As your game get's bigger and bigger, you will use more and more different shader effects. Let's take an easy example:

I have clouds in my voxel-based world, and I want to give it a blue-ish tint with a shader. Do I create a new shader, disable the default shader, enable the cloud-shader, draw the cloud, disable the cloud shader and enable the default one again?

If your game starts to get huge, how on earth can you use 300 shader effects enabled for 1 voxel and disabled for the other?

I know the question may sound strange, but it really makes me think.

I now have a Vertex- and Fragmentshader, for the matrix calculations, and basic lighting. If I want to add a shading-effect for for example water blocks, what to do?

I hope someone can help me with this mystery.


1 Answer 1


This is solved in diffrent ways, some solve it by using #ifdefs, some solve it by branching And some solve it by having input values that updates per every object so you store an overall painting scheeme for the defualt shader.

and when it comes to scale of the game, it´s actualy no way around this. You will need more shaders for diffrent materials and diffrent objects. I Usualy go with the "per material" shaders. which means that i have some common vertex shaders that i can plugin depending on what you are doing with the vertex. and then you have a specific material shader, like wood, metal, stone and water. i have found this to be quite efficent. you may endup with diffrent customshaders but thats just okay!

  • \$\begingroup\$ If my voxel-world is made of chunk VBO's, how would I use a seperate shader for each material? \$\endgroup\$
    – Basaa
    May 23, 2013 at 11:30
  • \$\begingroup\$ you could for instance pack propertys like flags and pass them to the gpu. there is many ways to do it, but you have to find the best one for your current game. \$\endgroup\$
    – Tordin
    May 23, 2013 at 11:31
  • \$\begingroup\$ You should consider having an 'uber' shader with all the basics per 'block', then conditionally compile and cache (memory or disk) the various shader combinations; you should do this the first time the game starts which will result in a small performance hit in terms of loading times. Then in your 'scene' graph or 'render world' you group and sort all blocks by material and bind the 'shader', draw all blocks, bind second 'shader' draw all blocks, etc. \$\endgroup\$
    – c0d3rguy
    May 27, 2013 at 14:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .