Cascaded Shadow Mapping

From C4 Engine Wiki
Jump to navigation Jump to search

Cascaded shadow mapping is the method used by the C4 Engine to cast real-time dynamic shadows over very large areas for an infinite light source. This article describes the settings that control the sizes of the cascades and the transition areas between them, which affect the resolution of the shadows and the smoothness involved in changing from one cascade to another.

Shadow Settings

The infinite light generates up to four separate shadows maps during every frame in which it is visible. These four shadow maps are rendered at different resolutions for four cascades of space corresponding to increasing distance ranges from the camera position. This concept is illustrated in the following diagram, where the camera is located at the position c and points to the right.

The sizes of the cascades are specified by four maximum distance settings in the Node Info window for the infinite light. As shown in the figure, these four distances determine the far planes for the four shadow cascades. Shadow maps for cascades closer to the camera are rendered at higher resolutions, and the distance between adjacent lower numbered cascades is typically lower than the distance between adjacent higher numbered cascades. If smaller distances are used, then the shadows are rendered at higher resolution, but the coverage of the shadowing is reduced as well.

The four cascades overlap by a little bit so that a smooth transition from one resolution to the next can be rendered for objects that straddle a cascade boundary. The three transition lengths specify how much distance each cascade extends into the one preceding it. A short distance means a quick transition, and longer distances mean more gradual transitions. The transition length can be any distance smaller than the higher-resolution cascade's overall size, but it typically covers only a fraction of the whole cascade.

Shadow Casting and Receiving

Each cascade has its own shadow map. Because cascades overlap, shadow castors may contribute to more than one of these shadow maps, and in fact could contribute to all of the cascades. An object must be rendered into the shadow map n times if it crosses into n cascades, so this should be considered when designing your worlds.

An object can also receive shadows in all four shadow cascades. Which shadow map to use is determined on a per-pixel basis in the shader, so the highest-resolution shadow map covering an object is always used wherever possible. In the transition area between cascades, samples from both cascades' shadow maps are blended together in order to produce a smooth transition from one resolution to the next. The number of cascades into which a shadow-receiving object crosses does not affect rendering performance. Whether an object falls completely in one cascade or extends through all four cascades, the rendering speed is the same.

See Also

Further Reading