PDA

View Full Version : Shadow mapping in less than 3 passes



jide
05-13-2006, 08:31 AM
Actually I need 3 passes to render a shadow mapped scene:

1. Render from the Light's POV.
2. Render the scene 'normally'.
3. Render the shadow mapped scene.

It is a quiete huge task, and for big scenes, this is definately not the thing to do. I guess I can combine the last two passes in a single one. I read somewhere I can do this, but I failed to understand how to do that.

Notes: I actually do not use shaders and would like any hints not involving shaders for the moment.

Also, how far it is possible to 'merge' the shadow mapping with lightmaps ? (I still haven't done any lightmap at all but an extremely and easy test).

Twixn
05-13-2006, 06:44 PM
Im pretty sure you can merge pass 2 with 3 by just using multi-textureing. Diffuse map for tex unit 0, shadow map for tex unit 1.

But, you dont have to update the shadow map every frame (pass 1). A good simple optimization is updating every second or perhaps third frame.
For static scenes you probably wont need to update them at all (assuming the light stays static too).

The only reasonable way i can see for merging shadow mapping and lightmapping is to have shadow mapping for dynamic objects, and lightmaps for the static scene.

Hope that helps.

-Twixn-

jide
05-13-2006, 07:34 PM
Okay, will try the multitexturing approach. It was so easy to think of that I didn't.

For the updates... I'm not sure. For static lights and objects I'm pretty sure this has to be done just once, but if objects and/or lights change, I don't think updating them evey n frames or so would help me, even if it could be a good optimization point I use elsewhere under some other cirumstancies.

So do you mean lightmaps should be done only for static scenes ?

Twixn
05-14-2006, 04:18 PM
Updating every n frames would only really be
useful for dynamic objects/lights. For static,
its a waste.

You could also try something else, like only
update the shadow map if it has moved, or
something that casts a shadow has moved.

Lightmaps can only be done for static scenes.
Lightmaps are just (precalculated) lighting
information that is loaded from a image file
and mapped to the scene. Dynamic objects will
need to use some other lighting system.

-Twixn-

Zulfiqar Malik
05-15-2006, 01:20 AM
Surely enough the last 2 passes can be merged as rightly pointed out by Twixn. However, if your scene has multiple lights then calculating the ambient pass for each light is not only expensive but can also lead to lighting errors. What we do in our engine is to do the ambient pass and then do a lighting pass for each light, additively blending with the frame buffer in each pass.
Shadow maps need not be calculated every frame, but frame is a very relative thing and basing your calculations on that can lead to visual discontinuities in the form of lighting errors, especially for moderate/fast moving objects. Surely enough, the shadow map does not need to be calculated if the light and the objects it effects remain static. However, dynamic lights and static lights with dynamic object need to recompute their shadow map. One optimization that could be done for static lights is to precompute a shadow map with static object information. Then when a dynamic object enters the scene, you simply set the precomputed shadow map as the render target and render the dynamic object's depth values. This will update the depth values only for the dynamic object and you will not need to render the static scene again. However, this can (and will) lead to an extra texture containing the static scene information. However, a good caching scheme can minimze this memory usage, where you cache the information only for a certain number of lights in or near the current scene. A cache miss for a particular light can force a render of the static objects for that light as well.
I hope i have been clear enough :) .

Zulfiqar Malik
05-15-2006, 01:25 AM
One optimization that could be done for static lights is to precompute a shadow map with static object information. Then when a dynamic object enters the scene, you simply set the precomputed shadow map as the render target and render the dynamic object's depth values.
Ofcourse you will have to check whether the new depth value is lesser than the value already present in the texture, otherwise the dynamic object will always project itself onto the scene.

jide
05-15-2006, 05:11 AM
Twixn, I was beleiving lightmaps could be used for dynamic lights. I actually don't see why there will have things against this approach (maybe DLM are slow ?).

I haven't tested the multitexturing approach yet. I fall into the shaders version yersterday evening just because I realized that, but the first pass (light POV), it might not be such a pain for me. But I'll keep it mind that multitextures in the case when I'll be wrong :)

Zulfiqar, I actually have some kind of a similar approach, but only tried it with a single light for the moment. I like the ideas you stipple for static lights optimizations, I would never have had thought about it.

Twixn
05-15-2006, 08:08 PM
Generally, lightmaps are just textures, similar to diffuse textures that are loaded from disk and applied to static geometry.

Lightmap generation is usually too slow to calculate realtime. I have seen a demo of dynamic lightmapping, but without extensive (and rather difficult) shading, its impossible to do realtime. Shadow mapping is better for dynamic lighting, far simpler to use.

-Twixn-