PDA

View Full Version : Shadow Mapping



wheelerbarry
09-13-2006, 01:36 PM
Is it possible to apply shadow mapping to a scene using a while using a directional light. All examples that i have seen use point or spot lights, and as the first step is render from the lights perspective, im not sure it is possible.

If it is, could someone please enlighten me on how it is done (or a usefull link), or are there any methods of rendering shadows using a directional light.

Thanks.

k_szczech
09-13-2006, 02:28 PM
Actually, shadowmaps from directional lights are the easiest :)
When you render to shadowmap you use glOrtho projection matrix.
And when you apply depth texture to objects then you just use linear texgens.

AlexN
09-13-2006, 02:34 PM
It's just the same as with a point or spot light, except that you render using an orthographic projection (in the most simplistic case) facing down the light direction. You'll have to keep this in mind when projecting the texture and comparing depth values...I have done it with manually encoded depth through a fragment shader, but I haven't tried it with depth textures so I don't know if there are any special issues there (I wouldn't think there are).

You're going to run into a lot of the same problems as you would with spot lights when it comes to shadow map resolution, because for larger scenes an orthographic projection probably isn't good enough to get sharp shadows. Look into PSM, TSM, LiSPSM (http://www.cg.tuwien.ac.at/research/vr/lispsm/), and PSSM (http://appsrv.cse.cuhk.edu.hk/~fzhang/pssm_vrcia/)

PSSM might go by another name like composite shadow maps, it looks like a good implementation from the multiple shadow maps approach. PSM and TSM probably aren't worth your time, they are overly difficult to get right and still end up with lots of problems. LiSPSM is similar to PSM and TSM but easier to implement and gives nice results, if you want something from that group of implementations. I would recommend PSSM or something similar where you have multiple shadow maps of different spatial resolutions.

If your camera is very limited, something like a top-down viewpoint, you can probably get away with just using an orthographic projection and that saves you a lot of trouble :)

Mars_999
09-13-2006, 05:26 PM
Not to intrude, but has anyone here implemented the PSSM in OpenGL as of yet?

wheelerbarry
09-14-2006, 12:37 AM
Thanks for the info. Much appreciated. :)

mogumbo
09-14-2006, 05:06 PM
Yes, directional lights are possible, and they represent the sun well so I prefer them for outdoor scenes.

AlexN, after a lot of reading, I agree that PSSM is the best for large outdoor scenes. Even LiSPSM can look blocky under some circumstances.

Mars, I've done PSSM with a directional light source and perspective view frustum in OpenSceneGraph, which is based on OpenGL. It's functional and looks pretty good, but I'm still doing some refining. Currently I'm choosing the shadow map using conditionals in a shader, but I would like to test the performance of rendering the scene in slices with one shadow map per slice. I have no idea which method would perform the best.