Sunday, May 24, 2009

Shadows

The keywords in shadowing process are light sources, shadow casters and shadow receivers. The light source can be a point source or area source. Calculating the shadow for point sources is easier compared that for area sources.
Point light sources generate only fully shadowed regions, while area light sources produce a fully shadowed region (umbra), and a partially shadowed region (penumbra).
Fully shadowed regions are called hard shadows and partially shadowed region are called soft shadows.
A basic technique for shadowing is projected planar shadows.

It is a simple technique. First, a three points are chosen so that the triangle formed by them defines the projection plane. The four plane coefficients are calculated from the three points that define the projection plane. Light position vector and these coefficients are used to pack a matrix called shadow matrix. This matrix squishes the 3D object on to the plane. To render the shadow, this matrix is applied to the objects that should cast shadow and the objects are rendered in dark color with no lighting. In this scheme, the three-dimensional object is rendered in two passes to create a shadow. In the first pass, the scene is rendered normally with lighting and depth test switched on. Then in the second pass, the depth test is disabled to deal with the z fighting between the shadow and the projection plane. While depth testing is disabled, the things that render last lie on top. The shadow receiver is already drawn in the pass. To cast the shadow, the shadow matrix is applied as described early.

Some other techniques are:
Projected Shadows
Shadow Mapping
Vertex Projection
Shadow Volumes