PDA

View Full Version : Shadow map and spot light parameters



aronsatie
03-02-2009, 11:16 AM
Hi,

I have just implemented shadow maps in my application for spot lights (which is, of course, the easiest type for shadows).

My problem is: For shadow map generation, I use the cutoff parameter of the spotlight to calculate the perspective projection (fovy=2*cutoff). This way all objects that are relevant for the shadow map should be visible.

At least in theory, because in practice this is not true. If I rotate/move the light, objects that are still lit by the light are at least partially off the shadow map which makes their shadow incorrect (long dark lines or rectangles appear).

Is this logical? If it is, what can I do about it (other than to increase fovy which I would be reluctant to do because it also decreases shadow map detail)? Or is there a mistake somewhere?

Thanks.

ZbuffeR
03-02-2009, 12:15 PM
Unless you do per-vertex lighting (and not per pixel), it certainly means there is a mistake somewhere.

Are your completely sure you do the light transformations correctly ? For easier debug, try drawing a wireframe cone to materialise the cutoff, and check for discrepencies when moving the light and its cone.

aronsatie
03-03-2009, 02:58 PM
Thanks, that helped a lot. It took some time for me to adjust a glut cone to the proper position, but at least now I know there is something wrong, the projection parameters are correct, fovy is set to the correct value.

Somehow I calculate the transformations of the light wrong when I render the shadow map. I define rotations with Euler angles (rotx, roty and rotz) and I placed the light directly above the scene, looking down (rotx=-90, roty=0, rotz=0). There is nothing on the shadow map which is wrong. If I change roty to 180 or -180 I get the correct shadow map which is definitely wrong, changing roty of the light should not change anything.

What can cause this? Is this gimbal lock?

Thanks.

zed
03-03-2009, 05:44 PM
Im guessing the errors are cause the shadowmap borders
try GL_REPEAT (+ there should be a mess)

solution use GL_CLAMP_TO_BORDER for the shadowmap + set the border to something that wont get showup on screen

aronsatie
03-03-2009, 11:31 PM
Hi,

Yes, I already did that. My first solution was to use clamp_to_edge and set the viewport of the shadowmap to 1 pixel less than its dimensions so the depth at the edges remained 'white'. Clamp_to_border is even better.

However, the problem really is the projection matrix. Since the light is over the scene (rotx=-90), the y and z axes are switched, but only in rendering the shadow map. The light itself still behaves as it should, so when I rotate the light (around y or z), the light cone moves one way and the shadow in a completely different way.