Jump to content
  • Advertisement
Sign in to follow this  
Timptation

general shader question

This topic is 3326 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'm new to shaders and am just curious about how many shaders are used per game in general. For example, I have a basic vertex shader that works with position, normal, and UV elements. This however, does not play nice with my previously lit terrain, having only position and UV elements. I'll need another shader that doesn't expect normals. Although I'm sure its something to avoid, is switching shaders a large amount of overhead? Are there any suggested links/books on the matter?

Share this post


Link to post
Share on other sites
Advertisement
I am not sure if I catch your question

but if you just want current shader not dealing with NORMAL ok, just neglect it, or give some default value to it, it's totally OK, no need to write another shader.

As your title , I don't quite follow that, I think there are types of shader. as to the number I think each type one,

Share this post


Link to post
Share on other sites
This is a common problem. The perpetuation of different shader states, materials, lighting conditions, etc. can lead to a massive combinatorial explosion of shaders.

Having lots of different shaders makes for efficient shader code, but is a massive pain to manage and maintain. If you don't have a lot of different shaders, it's probably fine. If you need to deal with hundreds of slightly different shaders to cope with every different condition, then you should look towards a different solution.

A common method is called the "uber shader" approach - dump everything into one massive ("uber") shader and switch features on/off at runtime. It means your shaders aren't as hard to manage, but it sacrifices runtime performance.

Share this post


Link to post
Share on other sites
It sounds like having multiple shaders per game is normal. I would imagine that to be the case, and we just try to need as few as possible. For clarification, I was curious how many shaders (I'm doing vertex shaders at the moment, perhaps its different for pixel shaders) would be typical for any given game. After writing a vertex shader, I see its obviously dependent on the vertex declaration. After that realization came the fact that I have geometry that doesnt need lighting calculations (terrain textures had static lighting precalculated), and so it doesnt have normals attached to it's verticies. Thus, I need a seperate shader for "unlit" verticies. I suppose lit and unlit geometry is 99% of what is needed though. Perhaps textured and multitextured geometery would multiply that to 4 different shaders....? Then again, that's probably what pixel shaders are for. So much to learn, but I want to know it all NOW. LOL

Share this post


Link to post
Share on other sites
I don't know exactly, but I presume a big game like Crysis would have hundreds (if not thousands) of individual combinations they needed to deal with.

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!