Shaders - Simple Q&A :)

Started by
3 comments, last by Nexian 11 years, 8 months ago
I can't find anything that answers this directly, but you can only have ONE shader on a game object, correct?

i.e. I cannot make two completely separate shaders and run both on the same object without it just rendering twice.

Assuming the above is true, how do most programmers create objects with multiple shader effects?

For example:

A Wall
- Bumpmap shader
- Rain shader (streaming water)
- Lighting shader (for any nearby lights (p.s. how does it pick the dynamic lights?))
- Projectile shader (bullets hitting the wall, etc)

Also, speaking of shaders. One effect that I can't quite see how to do is a targeting effect that covers multiple objects, similar to those found on AoE abilities in WoW or LoL. I can only guess it has to use the mouse position combined with the camera position and view along with the position and normal of the surface to draw a section of the defined "target" texture?
Advertisement
I am by no means an expert, but my understanding is as follows:

  • Sometimes one bumper shader is used that has lots of features, e.g. I am writing a shader that has relief mapping, splat maps and lighting.
  • Sometimes multi-pass shaders are used, although I'm not sure how much re-usability this offers.
  • Sometimes it's suitable to just overdraw effects, e.g. you draw your bullet mark decal over your bump-mapped wall.
  • If completely different types of shaders are involved, there may be no conflict, e.g. one is a vertex shader, one is a pixel shader, one is a full-screen post-processing effect.

But essentially shaders may interfere with each other in undesirable ways if you don't think it through. For example, underwater level with bullet damage. If you draw the bullet decals last, they won't be affected by the water effect, which would look weird. That's one reason why (in my opinion) getting a game looking AAA pretty is so hard.

Assuming the above is true, how do most programmers create objects with multiple shader effects?


It completely depends on which effects you're talking about. Sometimes they would be (manually) combined in one shader, sometimes it would be done by drawing the same object again (with the current blend equation determining how the result is combined with what's currently on screen), sometimes it would be done by drawing separate objects on top.


For example:

A Wall
- Bumpmap shader
- Rain shader (streaming water)
- Lighting shader (for any nearby lights (p.s. how does it pick the dynamic lights?))
- Projectile shader (bullets hitting the wall, etc)


Typically, bumpmapping and lighting would be combined in one shader. If using deferred rendering, lighting is calculated separately, but as a post-process effect, not an effect specifically on the object.

Streaming water and projectile marks, it seems to me, would be separate things laid on top (although I've never looked into making a streaming water effect, so I'm not sure of the typical manner in which it's done).

It's a bit of an art determining how a particular effect should be implemented, so there isn't necessarily any hard and fast rule.
You can use multiple shaders via multiple-passes. (Meaning you can either use a Technique and re-iterate through all its passes, or you can manually iterate and change the effect with another pass)
Thanks all,

This has been good, direct feedback. Feels good to be a little less uncertain :P

This topic is closed to new replies.

Advertisement