Jump to content
  • Advertisement
Sign in to follow this  
yarniso

Shadow mapping with multiple lights and shaders

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

Hi all, I am creating a little application that uses shadow mapping for shadows. One shadow works just fine, but I can't get my head around how to use multiple lights. I can create the shadowmaps and everything just fine. But there are a few issues bugging me. 1. How should the contributions of each light be combined to get correct shadows (darker when overlapping) and correct specular highlights. 2. Is there a way to allow one shader (Cg shader) to work with an arbitrary number of lights? For example when adding/removing lights from the scene? Or do I need to write a shader for every number of lights? If you guys/girls have any suggestions I would like to hear them. I think it might be quite simple, but for some reason I can't come up with an idea. Ah well, that happens sometimes. Oh, and are there any demo applications you know of that show such a multi-lights shadowmapping implementation? Thanks in advance. Yarniso

Share this post


Link to post
Share on other sites
Advertisement
The simplest approach is to do a 'pass per light' where you basically follow these steps for each light:

for each light
render your shadow map for the light
set up your scene to be rendered with this light and it's shadow map
render your scene, adding the contribution to whats already in the framebuffer
end for

Basically, you can simply additively blend each light into the scene and it will look OK. Remember you might also want ambient / emissive rendering passes outside that loop.

Once you've got that working you can try out combining multiple lights into a single pass with your shaders.

Hope that helps,

-Mezz

EDIT: I think there are multi-light shadow mapping demos at Humus's website here and at Delphi3D as well.

Share this post


Link to post
Share on other sites
Yes, having multiple shaders for multiple light scenarios is very good.
But - it is just optimization (if we can call that way your FPS.. :).
Multiple lights with SM per DIP can be made by packing SM-s into color channels of the RT for example. Lower depth-resolution, but if light radius is small, it is fine.
Making many shaders for different light scenarios can be made easily with preprocessor and defines - then producing the shader needed would be just compiling the same shader file with different macro settings.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!