Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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!

share|improve this answer
    
If my voxel-world is made of chunk VBO's, how would I use a seperate shader for each material? –  Basaa May 23 '13 at 11:30
    
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. –  Tordin May 23 '13 at 11:31
    
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. –  c0d3rguy May 27 '13 at 14:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.