PDA

View Full Version : Shadow mapping and multiple lights



Mr.Nameless
08-29-2011, 04:39 AM
I'm not sure how to handle shadow mapping and multiple light sources, from what I could read I need new depth map for each light source, though, that'd very limit me, as I need also hard-positioned shadows (for cases where usual light can't reach), and only the idea I got is that I need to then make fake light for each object that needs to cast shadow, so basically for few objects like this, I'd fill up multitexture limit fast, so that's why I'm not sure about this at all, if I want to handle it right way. If somebody can explain me correct approach of handling it or to show some demo, I'd be very thankful.

Alfonse Reinheart
08-29-2011, 05:09 AM
First of all, you need to really ask yourself whether you need all of those lights to cast a shadow. If the number of lights you're considering is more than around 2, that's probably too many. If you're at all interested in real-time rendering, then more than 2 or so will be hard to work for any scene that involves real complexity.

Next, you are simply approaching the limits of what you can do in a single pass of the scene (excluding the building of lightmaps). So what you have to do is either employ composition or deferred rendering. You can look up the latter online.

For composition, what I mean is that you render the scene once for each light. Not to generate a light map, but to generate the image itself. Each time you draw the image, you add the next light's values to what is in the framebuffer. That way, each light's rendering can have its own special textures like shadow maps.

Dark Photon
08-29-2011, 06:14 PM
First of all, you need to really ask yourself whether you need all of those lights to cast a shadow. If the number of lights you're considering is more than around 2, that's probably too many.
Potentially. The OP needs to consider not only scene complexity/density but also light source intensity and how he's going to LOD-out lights. The dimmer the light, the shorter the falloff distance, the fewer objects you actually need to cull in/render into its shadow map, and the cheaper generating the shadow map will be. This also means fewer lights will cull into your scene too, further reducing overhead.

Now as to "applying" those light sources (and their shadows): For smallish numbers of light sources, you may do just fine with forward shading (sometimes you can play tricks here to reduce lighting fill, but it's often hard/expensive; depending on your scene, you may not even need to cull).

For applying lots of light sources (and their shadows) though, look to deferred rendering techniques such as Deferred Shading, Deferred Lighting, and Light-indexed Deferred Rendering. In particular, the tile-based variants. These aren't without their challenges though. So make sure you need them before you go diving off that end of the pool.