Shadow Mapping

ExampleShadowMap_64x64

Figure 1 – A scene with severely undersampled shadows (64×64 shadow map).

Standard shadow mapping algorithm consist of two main steps:

  1. Generating the shadow map
    Figure 2 - Shadow map 64x64 samples, upscaled 4x.

    Figure 2 – Shadow map 64×64 samples, upscaled 4x. Uniform sample distribution.

    A shadow map is generated by rendering “shadow casting” geometry from the light-view-perspective and saving the distance to the nearest surface (from the light-view) into the depth-buffer. So the “shadow map” is basically a texture containing rays. Ray-position and direction is represented by the pixel-coordinate multiplied by the light-view-matrix and ray-length is the depth.

  2. Light Visibility Test
    The light-visibility test is performed by comparing the distance between camera-view sample and the light-position against projected shadow map sample. If the distance between the camera-view-sample and the light position is greater than the ray-length (provided by the corresponding shadow map sample, projected onto the camera-view-surface), then the light-source is not visible.

Aliasing

Broad utilization of shadow mapping algorithm is to thank to it’s extreme compatibility with the modern hardware rasterization technology (GPU). Modern GPUs can easily render and execute light visibility test in real-time. However, rasterization is also the main cause of shadow aliasing.

Figure 3 - Uniform sample distribution from light-view-space (directional light). Red lines indicate camera view angle.

Figure 3 – Uniform sample distribution from light-view-space (directional light). Red lines indicate camera view angle.

Perspective aliasing - From the light-view-space, a standard shadow mapping algorithm has a uniform sampling distribution (can be seen on figure 2 and 3). For the visibility test, the shadow map is projected into the camera-view-space. The transformation from the light to the camera-view-space results in a non-uniform sample distribution. High sample-destiny far from the camera and low near the camera (figure 3, the near-camera-face has only 2 samples and  far-camera-face has 14 samples). When a shadow map sample becomes larger than a single screen-space pixel, perspective aliasing starts to appear.

Figure 4 - Shadow map grid in screen-space.

Figure 4 – Shadow map sample-grid in screen-space.

On figure 4, a single grid-cell represents one shadow map sample (in screen-space). All shadow map samples are clearly larger than a single screen-space pixel, demonstrating perspective aliasing.

bias_example

Figure 5 – Left no bias offset, right with bias offset. A single column represents a shadow map sample. Only the center of the sample area represents the correct depth.

Projection aliasing - A single shadow map sample is only able to describe a  2D-plane (surface area) which is parallel-aligned to the light. However, usually the surface is not a flat 2D-plane and thus contains more depth information that a single shadow map sample is able to describe. Because of this limitation some of the surface area projected in the camera space from the light space is incorrectly described and results in incorrect visibility tests (see figure 1, bottom-right surface of the yellow cube). A common “solution” to this problem is to use a small offset which will reduce the visible aliasing (see figure 5, right).

Comments are closed.