skip to content

In a sunlit open landscape, cascaded shadow map edges crawl and flicker whenever the camera turns or moves; what causes it, and how do you split, fit and stabilize the cascades?

level: seniorimportance: should knowfreq 55%

answer

  1. the fit changes every frame
  2. rotation changes the extent
  3. translation slides the texel grid
  4. sphere bounds, snapped origin

basics

~20 s

Each cascade is refit to its frustum slice every frame: camera turns change its size and moves slide its texel grid by sub-texel amounts, so edges resample and crawl. Fit a fixed-size bounding sphere and snap its origin to whole texels.

solid answer

~50 s

Cascaded shadow maps split the view frustum by distance into a few slices, usually with split distances that blend a logarithmic and a uniform scheme, and give each slice its own orthographic shadow map. Fitting a tight light-space box to the slice every frame causes the crawl. When the camera rotates, the box's size changes, so a texel's world size changes; when it moves, the box shifts by fractions of a texel, so the grid that samples the world slides, and edges shimmer. To stabilize, bound each slice with a sphere, whose size does not depend on rotation, round its radius, and snap the projection's centre to whole multiples of a texel's world size in a light space whose origin is fixed in the world. The sphere wastes some resolution. Blend or dither across a band at each split to hide the jump in texel size.

code

pseudocode · 19 lines
pseudocode
// split distances: practical scheme, i from 1 to N - 1
split[0] = near
split[N] = shadowFar
for i in 1 .. N - 1:
    p = i / N
    logSplit = near * (shadowFar / near) ^ p
    uniSplit = near + (shadowFar - near) * p
    split[i] = lambda * logSplit + (1 - lambda) * uniSplit

// stable fit for cascade c; lightRotation depends only on the light direction (origin fixed in the world)
center, radius = boundingSphere(frustumSliceCorners(split[c], split[c + 1]))
radius = ceil(radius * 16) / 16                       // round so tiny changes do not resize the map
texelSize = 2 * radius / resolution
cLight = lightRotation * center
cLight.x = floor(cLight.x / texelSize) * texelSize   // move only in whole texels
cLight.y = floor(cLight.y / texelSize) * texelSize
projection = orthographic(cLight.x - radius, cLight.x + radius,
                          cLight.y - radius, cLight.y + radius,
                          sceneNearAlongLight, cLight.z + radius)   // z runs along the light direction

go deeper

for a junior

Recall why cascades exist: near ground needs small shadow texels and far ground can live with large ones, so the view is split by distance.

for a middle

Explain the split schemes and how a cascade's orthographic projection is fitted to its slice of the view frustum.

for a senior

Diagnose the crawl from rotation and sub-texel translation, then describe sphere fitting, radius rounding and texel snapping, plus what each costs in resolution.

for a principal

Set the cascade count, shadow distance and update cadence against the budget for open worlds, and decide where contact shadows or distant shadow techniques take over.

## Why one shadow map is not enough A sunlit landscape may need shadows from half a metre to several hundred metres. A single orthographic shadow map stretched over that range gives every world-space metre the same number of texels, but the camera's perspective gives nearby ground far more screen pixels than distant ground. Near the camera one shadow texel then covers dozens of pixels and edges turn blocky. This mismatch is **perspective aliasing**. **Cascaded shadow maps** split the view frustum along its depth into a few **slices** and render one shadow map per slice, so near slices get small texels and far slices large ones. Each pixel reads the cascade that covers its depth. ## Choosing the split distances With near plane `n`, shadow distance `f` and `N` cascades, the split at index `i` (from 1 to N - 1) can be: - **Uniform**: `n + (f - n) * i / N`. Simple, but the first slice is huge and near shadows are blurry. - **Logarithmic**: `n * (f / n)^(i / N)`. Matches perspective aliasing in theory, but with a small near plane the first slice becomes tiny and wastes a whole map. - **Practical**: `lambda * log + (1 - lambda) * uniform`, with `lambda` between 0 and 1 tuned per game. This scenario's figures, with `n = 0.5 m`, `f = 400 m`, four cascades and `lambda = 0.75`: | Split | Logarithmic | Uniform | Practical | |---|---|---|---| | 1 | 2.66 m | 100.38 m | 27.09 m | | 2 | 14.14 m | 200.25 m | 60.67 m | | 3 | 75.21 m | 300.12 m | 131.44 m | ## Why the edges crawl The naive fit takes the eight corners of each slice, transforms them into the light's space and fits the tightest orthographic box around them. That box is recomputed every frame, and two things change it: 1. **Rotation changes the extent.** The light-space bounds of a frustum slice grow and shrink as the camera turns, so the world size of one texel changes from frame to frame, and every shadow edge is resampled at a new rate. 2. **Translation slides the grid.** As the camera moves, the box moves by arbitrary fractions of a texel. Casters rasterize against a texel grid that has shifted under them, so each edge texel flips between lit and shadowed. Both show as edges that crawl, swim and flicker, worst on high-contrast silhouettes such as fences and tree trunks against sunlit grass. A third cause is the light itself: if the sun moves for time of day, the grid rotates relative to the world. ## Stabilizing each cascade 1. **Bound the slice with a sphere.** A sphere's size does not depend on orientation, so camera rotation no longer changes the extent. Round the radius up to a coarse step so floating-point noise does not change it either. 2. **Fix the light's rotation and origin.** Build the light's view from its direction alone, with an origin fixed in the world, not at the camera. 3. **Snap the centre.** With texel size `2 * radius / resolution`, round the sphere centre's light-space x and y down to whole multiples of that size before building the projection. The grid then moves only in whole-texel steps, which leave every static caster on the same texels relative to the world. 4. **Extend toward the light.** Pull the near plane back to the scene's bounds, or clamp casters in front of it to it, so off-screen casters such as a hill behind the camera still write depth. This scenario's figure: a sphere of radius 20 m on a 2048-texel map gives `40 / 2048`, about 2 cm per texel. The sphere covers more area than the slice needs, so stability costs effective resolution. ## Hiding the seams between cascades - **Blend bands**: near each split, sample both cascades and interpolate, or dither between them and let temporal anti-aliasing smooth the noise. - **Selection by coverage**: instead of comparing view depth with split distances, take the first cascade whose map actually contains the point; the sphere fit makes maps overlap, so this uses the finest data available. - **Per-cascade bias and filter width** scaled by texel size, so softness and acne do not jump at the boundary. - **Staggered updates**: far cascades can be re-rendered every second or fourth frame; snapping keeps a stale cascade aligned with the world, but moving casters lag in it and its coverage needs a margin for camera movement. | Symptom | Cause | Fix | |---|---|---| | Edges swim when turning | extent changes with rotation | sphere bounds, rounded radius | | Edges crawl when walking | sub-texel translation | snap to texel multiples | | Visible line where sharpness changes | texel size jumps at a split | blend band, matched filter width | | Shadows of off-screen casters pop as the camera moves | casters outside the slice clipped | extend the near plane toward the light |

  • Why does a sun that moves for time of day still make stabilized cascades shimmer?
    Snapping assumes a fixed light rotation, so the texel grid stays locked to the world. When the light direction changes, the grid rotates relative to the world and every edge resamples, whatever the snapping does. Renderers move the sun in small discrete steps at intervals, update it rarely, or rely on filtering and temporal accumulation to hide the change.
  • How should a pixel choose which cascade to read, and how does that affect seams?
    Comparing view depth with the split distances is simplest, but sphere-fit maps cover more than their slice, so it ignores finer data that is available. Projecting the point into each cascade from the nearest and taking the first map that contains it uses the best resolution. Either way, a blend or dither band before each boundary hides the jump in texel size.
  • What goes wrong if a cascade's light-space near plane is fitted to its slice alone?
    Casters between the slice and the sun but outside the slice, such as a hill behind the camera, fall in front of the near plane and are clipped, so their shadows vanish or pop as the camera moves. The near plane is pulled back to the scene's bounds, or those casters' depth is clamped to it during the shadow pass, which keeps depth precision tight.

  • Shimmering cascades just need a higher shadow-map resolution.
  • Turning the camera changes the light direction, which is why shadows swim.
  • Snapping the cascade to texels also fixes shimmer from a moving sun.
  • A tight box around each slice is always better than a bounding sphere.
  • Purely logarithmic splits are ideal whatever the near plane distance.