Jump to content
  • Advertisement
Sign in to follow this  

Shader Lights + Complex Materials

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

if I've got an object with some complex Shader, and it gets plop'ed into a scene that is supposed to have like 4 per pixel lights in it, what do I do. I'm terribly confused, I think I remember seeing some thing on combining shaders on the fly, but couldnt find the article, if anyone knows the article I'm talking about, kindly tell it to me, if anyone has a better solution I would be very greatfull.

Share this post


Link to post
Share on other sites
Advertisement
The main problem you're going to encounter is running out of instructions when performing per-pixel lighting with multiple lights. If you're only going to be running on SM3 hardware then you can simply loop through the lights in the pixel shader. Any other hardware though, you're going to have to use some magic...

One solution is to render the mesh with just an ambient term that writes to the z-buffer and colour buffer. Then you loop through each light that affects the mesh, turn z-write off and z-compare to "is-equal" and additive blending to "on", and re-render the mesh for each light. The disadvantage to this solution is that you have to re-render the mesh for each light, so there's lots of wastage.

Another solution is to just limit the number of lights that affect a mesh (or choose 2 of the most significant ones) and just have shaders that handle that.

Yet another solution is to use deferred-lighting (also known as deferred-shading) - google that to see how it works. This is how I hope to solve the problem.

Jim.

Share this post


Link to post
Share on other sites
For the multipass approach, aren't you best to leave the depth test at less or equal, so as not to screw up the hierarchical depth buffers?

Share this post


Link to post
Share on other sites
It's a good practice to always leave the depth test on lessequal for all passes for exactly this reason. Plus it's less state to track if the depth test is always the same.

Share this post


Link to post
Share on other sites
Thanks for the tip on Defered Shading, it looks really cool, though i think for lower end cards im still going to have to come up with a way to deal with the Lights problem from before, maybe just limit the number of lights that are active. Maybe figure a way to do like 8 lights in vertex, then only 1-2 in per pixel.

Share this post


Link to post
Share on other sites
Are you using shadows with your lights?

If so, you can only a single light per pass in general anyway, especially if targeting older hw. I target gf3+ and do three passes per light ( one to render to a shadow map, another to combine it with static shadow maps, and a third to do the lighting itself where not shadowed ).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Im still at a loss as to how to combine shaders, even if im doing multiple passes one per light, i still have to make my Different Materials work with point, spot, and directional lights. am i just supposed to write 3 versions of every shader i make? it really would be nice to be able to combine things, so i can do animation + Material + one Light, without now having NumberOfAnimationShaders * NumberofMaterials * Types of Lights + NumberOfAnimationShaders(for the Shadow mapping).

Share this post


Link to post
Share on other sites
If you use Cg you can make use of shader interfaces. This allows you to specify an interface that you can define with a struct at runtime, so you can have your shaders declare a light array, then bind concrete implementations of spotlight, pointlight etc. to each one at runtime.

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!