07.01.2013 Views

3D graphics eBook - Course Materials Repository

3D graphics eBook - Course Materials Repository

3D graphics eBook - Course Materials Repository

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Shadow mapping 178<br />

Algorithm overview<br />

Rendering a shadowed scene involves two major drawing steps. The first produces the shadow map itself, and the<br />

second applies it to the scene. Depending on the implementation (and number of lights), this may require two or<br />

more drawing passes.<br />

Creating the shadow map<br />

The first step renders the scene from the light's point of view. For a point light<br />

source, the view should be a perspective projection as wide as its desired<br />

angle of effect (it will be a sort of square spotlight). For directional light (e.g.,<br />

that from the Sun), an orthographic projection should be used.<br />

From this rendering, the depth buffer is extracted and saved. Because only the<br />

depth information is relevant, it is usual to avoid updating the color buffers<br />

and disable all lighting and texture calculations for this rendering, in order to<br />

save drawing time. This depth map is often stored as a texture in <strong>graphics</strong><br />

memory.<br />

This depth map must be updated any time there are changes to either the light<br />

or the objects in the scene, but can be reused in other situations, such as those<br />

where only the viewing camera moves. (If there are multiple lights, a separate<br />

depth map must be used for each light.)<br />

In many implementations it is practical to render only a subset of the objects<br />

in the scene to the shadow map in order to save some of the time it takes to<br />

redraw the map. Also, a depth offset which shifts the objects away from the<br />

light may be applied to the shadow map rendering in an attempt to resolve<br />

stitching problems where the depth map value is close to the depth of a<br />

surface being drawn (i.e., the shadow casting surface) in the next step.<br />

Scene rendered from the light view.<br />

Scene from the light view, depth map.<br />

Alternatively, culling front faces and only rendering the back of objects to the shadow map is sometimes used for a<br />

similar result.<br />

Shading the scene<br />

The second step is to draw the scene from the usual camera viewpoint, applying the shadow map. This process has<br />

three major components, the first is to find the coordinates of the object as seen from the light, the second is the test<br />

which compares that coordinate against the depth map, and finally, once accomplished, the object must be drawn<br />

either in shadow or in light.<br />

Light space coordinates

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!