I'm all set to set up shadow mapping in my 3d engine but there is one thing I am struggling to understand. The scene needs to be rendered from the light's point of view so I simply first move my camera to the light's position but then I need to find out which direction the light is looking. Since its a point light its not shining in any particular direction. How do I figure out what the orientation for the light point of view is?
1 Answer
Generally, the approach for a point light which is shining light in all directions is to produce 6 shadow maps one for each axis.
So you have your camera look along the +x, -x, +y, -y,+z and -z axes to make 6 shadow maps to create a cube map. Each axis's 'view' will be rendered with a 45deg field of view.
[edit]
You can of course check each of the light's 'view' frustums for collision against the real view frustum. If it doesn't collide, then no need to generate the SM for that side of the cube map.
A lot of this work can be handled quite quickly by the geometry shader see here, but there is no such thing as a free lunch.
Realistically, if you have many lights, you will need to somehow limit the number of lights which are casting shadows either by;
- sort your lights in some priority order, perhaps based on brightness or some game context
- have you lights cast shadows only over a limited distance, so only lights within a certain radius of the camera cast shadows
- combination of 1 & 2 (2 is really a special case of 1 anyway)
-
\$\begingroup\$ width*height*6n if n is the number of point lights sounds like allot of pixels. This sounds computationally expensive. Are you sure I have to render 6 shadow maps per light because most of those shadows generated this way will be frustum culled anyways. \$\endgroup\$– PgrAmCommented Oct 15, 2012 at 19:52
-
\$\begingroup\$ I have read about something called Dual-Paraboloid Shadow Mapping that only uses two maps per light does anyone have any details about implementing this in OpenGL? \$\endgroup\$– PgrAmCommented Oct 15, 2012 at 20:04
-
\$\begingroup\$ maybe you should make a new question about that technique? \$\endgroup\$– KenCommented Oct 15, 2012 at 20:58