PDA

View Full Version : Shadow maps for infinite light sources

flamz
12-17-2003, 08:53 AM
Anybody have any insight on how I can calculate the view matrix for an infinite light source to create a shadow map?

Since an infinite light source has a direction but no position, Im a bit puzzled and wondering if its even possible.

thanks

12-17-2003, 09:11 AM
setup the projection matrix to do orthogonal projection. (glOrtho instead of glFrustrum) that's all.

flamz
02-10-2004, 09:32 AM
I don't get it.
Since the light has no position, where do I "place" the camera to render from the light's point of view??

MikeC
02-10-2004, 09:58 AM
Originally posted by flamz:
where do I "place" the camera to render from the light's point of view??

It shouldn't matter, should it? Imagine an infinitely long line stretching between your scene origin and your light source. Placing the POV anywhere along that line ought to work; in an ortho projection there's obviously no perspective divide, so the distance doesn't really make any difference.

jwatte
02-10-2004, 02:47 PM
Ortho doesn't have a camera position.

You place the near plane right before the closest point of the object closest to the (infinite) light (direction). You place the far plane right after the furthest point. You orient the near plane (and thus Ortho cube) to have a plane normal that's the same as the vector towards the light.

Won
02-11-2004, 03:54 AM
You can (and should!) think about an ortho camera (or directional light) as being infinitely far away. Using projective geometry, this is actually a well-defined position specified in homogeneous coordinates.

A good exercise that helped me learn a bit about the bizarre properties of projective geometry was to figure out how to parameterize the camera (actually, a mix of projection and modelview matrices) so that you can continuously go from a frustum to an ortho projection while keeping roughly the same extent in the view volume. Visually, this is exactly the over-dramatic shot they use in movies where it looks like the foreground and background change distance. In fact, it is accomplished the same way with a virtual camera as it is with a real camera.

-Won

Relic
02-11-2004, 04:28 AM
>>over-dramatic shot they use in movies where it looks like the foreground and background change distance<<

Off topic, I know. http://www.opengl.org/discussion_boards/ubb/wink.gif
Called Vertigo-effect after the Alfred Hitchcock movie where it was used to dramatize fear of heights.

flamz
02-17-2004, 02:44 PM
Imagine an infinitely long line stretching between your scene origin and your light source. Placing the POV anywhere along that line ought to work

OK, but any suggestion on choosing the scene origin? What I mean is that: if the camera is looking at a part of a scene which is nowhere near (0,0,0), I would have to place my camera way, way up on the vector streching from 0,0,0 which would result in terrible shadow map resolution. no?

not sure I'm clear... it's late.
http://www.opengl.org/discussion_boards/ubb/frown.gif

robosport
05-15-2004, 05:07 PM
Thank you for this thread. I came to the forum tonight with the same question.

One 'search' later my question is answered and a few minutes later the answer is verified in implementation.

robosport
05-15-2004, 05:15 PM
flamz,

The shadow map resolution is obviously set independent of light/cam position.

If you are talking about making the most of the resolution by filling it as effectively as possible with shadowing/shadowed objects during the shadow map render, then it seems like that is controlled with your ortho settings (once you are using ortho instead of perspective for shadow map projection), not light/camera distance.

With a static light position, I'm using ortho settings to tweak the position/size of objects in the final rendered shadow/depth map. Previously, when using perspective projection, I had to use camera placement and field of view.

robo

plasmonster
05-16-2004, 01:20 AM
Originally posted by flamz:
OK, but any suggestion on choosing the scene origin? What I mean is that: if the camera is looking at a part of a scene which is nowhere near (0,0,0), I would have to place my camera way, way up on the vector streching from 0,0,0 which would result in terrible shadow map resolution. no?
Perhaps some artwork would help here

subject origin
| | |
| v |
here | ^ |
| | |
eye here

------------------>
------------------> light direction
------------------>It doesn't really matter where the eye is, as long as the near and far parameters in the glOrtho(...) call are consistent with the choice; the choice itself is completely arbitrary.

I think that using the subject's origin is a safe bet for the eye origin, and a near, far sufficient to view the subject completely, say, -/+ the subject's bounding sphere radius, assuming the model is reasonably symmetric. For a square depth buffer image, this would not be an unreasonable assumption.

jwatte
05-16-2004, 08:20 AM
Is this static or dynamic shadow maps?

For static, you have to choose origin based on your geometry, because the camera will move.

For dynamic, you could decide how far into the scene the shadow map reaches (say, 200m) and then choose an origin that's half that in front of the eye. You might want to quantize that to some known pixel snap position, to avoid crawlies in the shadow outline.

Also, with ortho shadows, the resolution behaves like W buffers, so a 1024x1024 map that covers a 200x200 m area will
1) have a lot of wasted space where the frustum doesn't intersect it
2) have a texel size of about 25 centimeters, which is overkill for far shadows, but jaggy for near shadows

The "projective shadow maps" technique promised to make this better, but has so many problems in implementation that it doesn't appear likely to actually be used in its pure form. I know some people are slicing the frustum in multiple pieces and covering them with multiple maps, to get rid of some of these artifacts.