i
i
i
i
i
i
i
i
9.1. Shadows 367
Variance Shadow Maps
One algorithm that allows filtering of the shadow maps generated is Don-
nelly and Lauritzen’s variance shadow map (VSM) [272]. The algorithm
stores the depth in one map and the depth squared in another map. MSAA
or other antialiasing schemes can be used when generating the maps. These
maps can be blurred, mipmapped, put in summed area tables [739], or any
other method. The ability to treat these maps as filterable textures is a
huge advantage, as the entire array of sampling and filtering techniques can
be brought to bear when retrieving data from them. Overall this a gives a
noticeable increase in quality for the amount of time spent processing, since
the GPU’s optimized hardware capabilities are used efficiently. For exam-
ple, while PCF needs more samples (and hence more time) to avoid noise
when generating softer shadows, VSM can work with just a single (high-
quality) sample to determine the entire sample area’s effect and produce
a smooth penumbra. This ability means shadows can be made arbitrarily
soft at no additional cost, within the limitations of the algorithm.
To begin, for VSM the depth map is sampled (just once) at the receiver’s
location to return an average depth of the closest light occluder. When this
average depth M
1
(also called the first moment) is greater than the depth
on the shadow receiver t, the receiver is considered fully in light. When
the average depth is less than the receiver’s depth, the following equation
is used:
p
max
(t)=
σ
2
σ
2
+(t − M
1
)
2
. (9.10)
where p
max
is the maximum percentage of samples in light, σ
2
is the vari-
ance, t is the receiver depth, and M
1
is the average (expected) depth in
the shadow map. The depth-squared shadow map’s sample M
2
(the second
moment) is used to compute the variance:
σ
2
= M
2
− M
2
1
. (9.11)
The value p
max
is an upper bound on the visibility percentage of the
receiver. The actual illumination percentage p cannot be larger than this
value. This upper bound is from Chebychev’s inequality, one-tailed version.
The equation attempts to estimate, using probability theory, how much of
the distribution of occluders at the surface location is beyond the surface’s
distance from the light. Donnelly and Lauritzen show that for a planar
occluder and planar receiver at fixed depths, p = p
max
, so Equation 9.10
can be used as a good approximation of many real shadowing situations.
Myers [915] builds up an intuition as to why this method works. The
variance over an area increases at shadow edges. The greater the difference
in depths, the greater the variance. The (t−M
1
)
2
term is then a significant
determinant in the visibility percentage. If this value is just slightly above