Cascading Shadow Maps

Global shadow system implemented using cascading shadow maps and random 8 tap PCF.

Description: I have been interested in shadow creation and effective ways to integrate them into rendering systems for a while. After exploring baked light maps, perspective shadow mapping and volume shadows I came across the cascading shadow maps technique.

It's a technique that requires minimal effort on the art side, is flexible in cost/quality and can work automatically over an entire scene.

Tools: Visual C++ Pro, OpenGL.

Topics: Shadows, multiple rendering passes, framebuffer objects, depth buffer.

Technique overview:

A subset of the scene (shadow casters) are rendered from the perspective of a directional shadow light using an orthographic projection. The rendering requires only writing to the depth buffer and stores the resulting depth into a texture that can be sampled later in the rendering process.

Later when rendering shadow receivers, the fragment's depth is transformed into the shadow light's camera space and compared to the value stored previously, if the stored value is less than the current fragment depth, we know the fragment is in shadow.

The shadow light render MVP matrix is constructed in such a way that each frustum encloses a subsection of the normal camera's frustum. You set a number of 'splits' and a split weight. The idea is to have a high resolution shadow map for objects close to the camera and less resolution further away where it's not as noticeable.

Here you can see the rendering frustum for each slice from the shadow light's perspective. Red, green and blue frustums are cropped to a subsection of the (white) camera frustum.

Shadow Image 1

Here is another perspective again red, green and blue represent pixels in the different splits.

Shadow Image 2

I also created an interactive tool to manipulate the shadow parameters in real time. Part of a larger interactive light editing tool.

Shadow Config Image 1

In this video I am manipulating the z-range which affects shadow precision. Notice the shadow boundary on his stomach. In the second half I am adjusting the polygon offset which clears up z fighting and self shadowing problems. Notice how the shadows around his eyes change.

Here is a little flythrough, in some spots you can notice the boundary between splits as the camera moves.

Here you can see some of the diagnostics in action to calibrate the shadows.

Obligatory code screen shot.

Shadow Image 3

Please contact me if you are interested in acquiring a copy of the program, seeing the source code, or have any comments.

Back to the projects page.