PDA

View Full Version : viewport for shadow mapping



JanHH
12-21-2004, 05:48 PM
Hello,

I am trying to work through shadow mapping (with the tutorial from paulsprojects), and there is (at least) one point that I don't understand: How is the viewport configured correctly, so that the scene, rendered from the light's point of view, is completely visible (nothing cut off at the sides) and also large enough that it (more or less) uses the entire screen/depth map (to avoid loss of precision)?

Another question: Can you combine shadow mapping with fragment programs (to use bump mapping)? I guess, this is possibly?

Thanks
Jan

jwatte
12-21-2004, 06:24 PM
Choosing a suitable frustum is part of the black art of shadow mapping. Note that, even with a 2048x2048 shadow map, you're not going to get perfect coverage of the entire scene. Especially the Dueling Frustum problem when you have spotlights shining into the (visible) camera is Just Plain Hard (tm), although there are hacks, like treating spotlights as directional lights (works well when far from the nearest shadow caster).

Some techniques, like Perspective Shadow Maps, and Trapezoidal Shadow Maps, attempt to skew the frustum of the rendered shadow map based on the camere relative to the light, but actually implementing these in a robust way that really works for all situations appears to be impossible, if I'm to believe those on gd-algorithms who tried and reported on it.

The most promising technique involves rendering a number of maps, with successive greater coverage. I e, render four or five 1024x1024 maps; one is centered around the 20x20 meter area in front of the player; the next on the 40x40 meter area, ... When you render, you check which area each object covers, and use the coarsest map into which it extends. (Some people have reported using two maps; the coarsest and the one after that).

Note that maps should have a border that's non-shadowed, else you'll get interesting side effects (pun intended :-)

Yes, you can use multiple shadow maps inside shaders. Texturing from a shadow map isn't really different than texturing from another texture, as far as the shader is concerned.

JanHH
12-21-2004, 07:37 PM
Thanks. The program is a rather simple terrain engine with a very simple lighting situation, just one directional light (the sun). I changed this to a positional light and now simply try to get very basic and simple shadow mapping working (as described in the tutorial). Once this is working, it is in fact planned to implement perspective shadow mapping, as this seems to give nearly perferct results in a terrain engine situation, and the shadow map has to be rendered again for each frame due to moving objects in the scene. But the tutorial does not say anything about choosing the light frustum, nor how to handle directional light. But first, I try to get the simple version running.

zed
12-21-2004, 10:30 PM
for a terrain a method i used was
find out what direction the camera is facing, ignore the y factor add this x,z direction, scaled to the size of the shadowmap (maybe u need to normalize the x,z i forget) to the camera's position, and use the resulting position as the shadowmaps target.

V-man
12-22-2004, 07:23 AM
For real time applications, shadow mapping a terrain seems inappropriate.
Why not precompute shadows. That way you can have smooth shadows for free.

Do you have screnshots of wha you have now?

>>But the tutorial does not say anything about choosing the light frustum, nor how to handle directional light<<<

I think there was a pdf at nvidia about setting up this kind of projection. It has been a while since I touch shadow maps. They are trouble and not accurate like stencil shadows.

MickeyMouse
12-22-2004, 09:49 AM
Originally posted by jwatte:
The most promising technique involves rendering a number of maps, with successive greater coverage. I e, render four or five 1024x1024 maps; one is centered around the 20x20 meter area in front of the player; the next on the 40x40 meter area, ... When you render, you check which area each object covers, and use the coarsest map into which it extends. (Some people have reported using two maps; the coarsest and the one after that).Are there any sample implementations (or at least some papers) showing this algorithm ?

Btw. TSM seems very nice for all kinds of shadows especially combined with 80% partitioning line, but I haven't seen any running implementation of it either. Did anyone?

JanHH
12-22-2004, 01:44 PM
The reasons against precomputed shadows are that there are moving objects in the scene, and that the size of the light maps would be much too large, as the terrain is quite large (for example 3 x 3 km).

Stencil shadows are not possible as there are alpha blend trees in the scene ( http://de.geocities.com/westphj2003/refl.html ).

As far as I know, perspective shadow mapping would give nearly perfect results and takes only one more rendering pass, which would be ok. So we choose that one. But as this simply is an extension of "standard" shadow mapping, and this is the first time I mess with shadows, I decided to start with the very basic stuff of the paulsprojects tutorial.

If you know of a better shadow technique, let me know :) .