Why do variance and exponential shadow maps leak light where occluders overlap, and what do the usual fixes for that light bleeding cost?
answer
- store something you can blur
- mean and mean of squares
- an upper bound, not the answer
- two occluders inflate the spread
basics
~20 sThey store blurrable depth statistics, depth and depth squared or an exponential of depth, and estimate visibility from them. Overlapping occluders at different depths inflate the variance, and occluders near the receiver defeat the exponential, so shadowed points read partly lit.
solid answer
~50 s**Variance shadow maps** store depth and depth squared. Both are linear in the samples, so they can be blurred, mipmapped and anisotropically filtered like a colour texture. A lookup recovers a mean `mu` and variance `sigma^2 = E[d^2] - mu^2`, and Chebyshev's one-tailed inequality bounds the lit fraction for a receiver at depth `t > mu`: `pMax = sigma^2 / (sigma^2 + (t - mu)^2)`. The bound is exact for one planar occluder over a parallel planar receiver but loose when the filter spans occluders at different depths: their gap inflates the variance, so a receiver behind both reads partly lit. The usual fix remaps `pMax` so values below a threshold become zero, which darkens and narrows penumbrae. **Exponential shadow maps** store `exp(c * d)`; they leak where occluders sit close to the receiver, and a larger `c` helps until the float range overflows.
code
pseudocode · 10 lines// variance shadow map lookup; depth grows away from the light
function vsmLitFraction(uv, t):
m = filteredRead(varianceMap, uv) // m.x = E[d], m.y = E[d^2]
mu = m.x
if t <= mu:
return 1.0 // receiver in front of the average occluder
variance = max(m.y - mu * mu, minVariance) // guard against cancellation going negative
delta = t - mu
pMax = variance / (variance + delta * delta)
return clamp((pMax - k) / (1 - k), 0, 1) // light-bleeding reduction, k between 0 and 1go deeper
Recall that variance shadow maps store depth and depth squared so the map can be blurred like a texture, and that their known artefact is light leaking into shadows.
Explain how mean and variance come from the two channels and what Chebyshev's bound returns for a receiver behind the mean.
Work the overlapping-occluder case to show the leak, then weigh the remap, warped moments and precision against what each costs.
Decide whether prefiltered maps or per-pixel PCF fit the project's look, budget and bandwidth, given the leaks content will expose.
## The goal: filter once, not per pixel This answer assumes **depth grows away from the light**. Percentage-closer filtering softens edges by running many comparisons per pixel per light, and the cost grows with the penumbra. **Prefiltered shadow maps** take the opposite route: store a function of depth that is safe to filter, blur it once per texel with a separable filter, build mipmaps, and let ordinary texture filtering do the rest. A lookup then costs about the same however soft the shadow. The price is that the stored statistic only *estimates* visibility, and the estimate fails in a recognizable way: **light bleeding**, where a region that should be fully shadowed glows faintly. ## Variance shadow maps A **variance shadow map** stores two channels per texel: depth `d` and depth squared `d^2`. After filtering, a lookup returns their averages over the filter region, `E[d]` and `E[d^2]`, which give: - the **mean** `mu = E[d]` - the **variance** `sigma^2 = E[d^2] - mu^2` For a receiver at depth `t` with `t > mu`, **Chebyshev's one-tailed inequality** bounds the probability that a sample from the region is at least as deep as the receiver, which is the lit fraction: `pMax = sigma^2 / (sigma^2 + (t - mu)^2)` If `t <= mu` the receiver is treated as fully lit. The bound is **exact** for the common case of one planar occluder over a parallel planar receiver. This scenario's check: occluder at 0.2 over half the region, receiver at 0.7 over the other half, receiver depth 0.7. Then `mu = 0.45`, `E[d^2] = (0.04 + 0.49) / 2 = 0.265`, `sigma^2 = 0.0625`, `(t - mu)^2 = 0.0625`, and `pMax = 0.5`, exactly the half-lit value an edge should get. ## Where the bound leaks Now let two occluders overlap: one at 0.2 fills half the region, another at 0.6 fills the other half, and the receiver at 0.7 sits behind both, so it should be **fully shadowed**: 1. `mu = 0.4`, `E[d^2] = (0.04 + 0.36) / 2 = 0.20`, `sigma^2 = 0.20 - 0.16 = 0.04`. 2. `(t - mu)^2 = 0.3^2 = 0.09`. 3. `pMax = 0.04 / (0.04 + 0.09)`, about **0.31**. The gap between the two occluders created variance that has nothing to do with the receiver, and Chebyshev's bound, which is only an upper bound, reports 31 percent light. Bleeding is worst when the occluders are far apart in depth and the receiver sits close behind the deeper one, a pattern common where a tall caster's shadow falls across a low wall or a crate standing on the ground. ## Fixing the bleeding, and what it costs - **Light-bleeding reduction.** Remap `pMax` with `linstep(k, 1, pMax)`, which sends everything below `k` to zero and rescales the rest. With `k = 0.35` the 0.31 above becomes 0, but a true half-lit edge drops from 0.5 to about 0.23, so penumbrae get darker and narrower. `k` is a tuning compromise per scene. - **Exponentially warped variance (EVSM).** Warp depth with positive and negative exponentials before storing moments; the bound tightens sharply. It costs two to four channels of 32-bit floats per texel. - **Moment shadow maps.** Store four moments and reconstruct a tighter bound, again for more memory and arithmetic. - **Precision.** `sigma^2` is a difference of two nearly equal numbers, so 16-bit storage breaks down; 32-bit channels, a minimum variance clamp and a tight depth range are standard. ## Exponential shadow maps An **exponential shadow map** stores `exp(c * d)` for a constant `c`. Filtering gives `E[exp(c * dOcc)]`, and visibility is estimated as `visibility = min(1, E[exp(c * dOcc)] * exp(-c * t)) = min(1, E[exp(c * (dOcc - t))])`. When every occluder is well in front of the receiver, each term is tiny and the result is dark. It leaks where an occluder sits **close to the receiver**, near contact, because `exp(c * (dOcc - t))` stays near 1. A larger `c` sharpens it, but with depth in 0..1 a 32-bit float overflows near `c = 88` (`ln` of the largest finite value is about 88.7), and 16-bit storage near 11. | Method | Stored per texel | Leaks where | Main cost | |---|---|---|---| | Variance | `d`, `d^2` | overlapping occluders at different depths | 2 channels, precision | | Exponential | `exp(c * d)` | occluders near the receiver | overflow limits `c` | | Exponentially warped variance | warped moments | much less | 2 to 4 float channels | | PCF (for contrast) | `d` | none from statistics | samples per pixel |
- Why do variance shadow maps need high-precision storage?Variance is computed as the mean of squares minus the square of the mean. Over a flat region those two are nearly equal, so low precision leaves noise or even negative variance, which shows as speckled acne. Implementations store 32-bit floats, clamp the variance to a small minimum, and keep the light's depth range tight.
- What does a variance shadow map buy that justifies the bleeding?Its filtering is linear, so a wide blur costs a separable pass per texel instead of many comparisons per pixel, and mipmaps and anisotropic filtering work, which keeps distant and grazing shadows smooth. Very soft shadows cost the same as sharp ones at lookup, which suits large, soft area-like lights.
- Light bleeding happens because the variance shadow map's resolution is too low.
- Chebyshev's inequality gives the exact lit fraction for any arrangement of occluders.
- Half-precision floats are enough to store depth and depth squared reliably.
- Raising the exponential constant in an exponential shadow map has no practical limit.
- The light-bleeding remap removes leaks without changing the look of real penumbrae.