i
i
i
i
i
i
i
i
1
IV
Variance Shadow Maps
Light-Bleeding Reduction Tricks
Wojciech Sterna
1.1 Introduction
Variance Shadow Maps (VSMs) were first introduced in [Donnelly and Lau-
ritzen 06] as an alternative to bilinear percentage closer filtering (PCF) to speed
up rendering of smoothed shadows. The algorithm is relatively inexpensive, easy
to implement, and very effective in rendering shadows with large penumbra re-
gions. However, VSM has one major drawback—apparent light-bleeding—which
occurs when two or more shadow casters cover each other in light-space. This ar-
ticle will show techniques that help to reduce the light-bleeding artifacts in VSM.
1.2 VSM Overview
The idea of variance shadow mapping is to store in the shadow map, instead
of a single depth value, a distribution of depth values over some region and to
use elementary statistics to evaluate the shadowing term. This approach makes
it possible to use filtering methods (bilinear, trilinear, blurring) on the shadow
map. A common option is to use Gaussian blur on the shadow map to achieve
soft shadows in O(n) time. This is a great advantage over traditional PCF which
requires O(n
2
) time to achieve the same effect.
To generate the variance shadow map, two values must be written into it.
The first is simply a distance from a light source to a pixel, as with traditional
shadow mapping (one thing that is important here is that this distance should
have a linear metric). The second component of the shadow map is a square of
the first component.
Once the shadow map has been prepared (it contains both depth and a square
of depth), additional filtering can be applied to it. To achieve good-looking soft
shadows, a separable Gaussian filter with 5 ×5 taps can be used.
207
i
i
i
i
i
i
i
i
208 IV Shadows
To estimate the shadow contribution from such a defined VSM, so-called
Chebyshev’s inequality (one-tailed version) can be used to estimate the shad-
owing term:
P (O R) p
max
(R)
σ
2
σ
2
+ (R µ)
2
, where µ < R (1.1)
The variable O is an occluder’s depth (shadow map’s texel), R is a receiver’s depth
(distance from a pixel being shaded to a light source), σ
2
is the variance and µ is
the mean. The term P (O R) can roughly be interpreted as a probability of a
point (at distance R) being lit (unshadowed by a point at distance O), which is
the exact value we wish to know, and Chebyshev’s inequality gives us an upper-
bound to this value.
The mean and variance in Equation (1.1) are computed from the first and
second statistical moments:
M
1
= E(O)
M
2
= E(O
2
)
µ = M
1
= E(O)
σ
2
= M
2
M
1
2
= E(O
2
) E(O)
2
In fact, the first moment is what is actually stored in the first channel of the
shadow map, and the second moment in the second channel of the shadow map.
That’s why the shadow map can be additionally prefiltered before its use—the
moments are defined by the expectation operator which is linear and can thus be
linearly filtered.
A sample implementation of standard VSM is shown in Listing 1.1.
f l o a t VSM( fl o a t 2 projTexCoord , f l o a t depth , f l o a t b i a s )
{
f l o a t 2 moments = tex2D ( shadowMa p linear , projTexCoord ) . r g ;
i f ( moments . x >= depth b i a s )
return 1 . 0 f ;
f l o a t v a r ia n c e = moments . y moments . xmoments . x ;
f l o a t d e l t a = depth moments . x ;
f l o a t p max = v a r ia n c e / ( v a r i an c e + d e l t a d e l t a ) ;
return s at u r a t e ( p max ) ;
}
Listing 1.1. Standard VSM implementation.
i
i
i
i
i
i
i
i
1. Variance Shadow Maps Light-Bleeding Reduction Tricks 209
Note that the given Chebyshev’s inequality (its one-tailed version) is undefined
for cases in which µ R. Of course, in such a case a point is fully lit, so the
function returns 1.0; otherwise, p
max
is returned.
1.3 Light-Bleeding
Light-bleeding (see Figure 1.1) occurs when two or more shadow casters cover
each other in light-space, causing light (these are actually soft edges of shadows
of the objects closest to the light) to bleed onto the shadows of further (from the
light) objects. Figure 1.2 shows this in detail.
As can be seen from the picture in Figure 1.2, object C is lit over a filter
region. The problem is that when estimating the shadow contribution for pixels
of object C over this region, the variance and mean that are used are actually
based on the samples from object A (red line) and visible samples from object B
(green line) (the shadow map consists of pixels colored by red and green lines),
whereas they should be based on samples from object B only (green and blue
lines). Moreover, the greater the ratio of distances
x
y
(see Figure 1.2), the more
apparent the light-bleeding is on object C.
The VSM is not capable of storing more information (about occluded pixels
of object B for instance). This is not even desirable since we want to keep the
Figure 1.1. Light-bleeding.
i
i
i
i
i
i
i
i
210 IV Shadows
Figure 1.2. How light-bleeding occurs.
algorithm simple and don’t want to raise its memory requirements. Fortunately,
the following sections in this chapter will present a few very simple tricks that
can greatly reduce the problem.
1.4 Solutions to the Problem
1.4.1 Cutting the Tail Off
The first way of reducing light-bleeding was simply cutting off the tail of the p
max
function. Put simply, it’s about subtracting some fixed value from the result of
p
max
. This way, incorrect penumbra regions will get darker but so will the correct
ones. However, intensities of incorrect penumbra regions never reach 1 (as shown
in [Lauritzen 07]) so the final result can still look good when the cutting value is
chosen wisely.
Figure 1.3 shows a side-by-side comparison of standard VSM implementation
and the same VSM but with p
max
cut off by a value of 0.15. Although the
light-bleeding is still present it’s much less obvious.
As we mentioned earlier, the light-bleeding gets more noticeable when the
ratio
x
y
is big. In such a scenario (high depth complexity) it is next to impossible
to eliminate the problem by applying only a cutting value. More sophisticated
methods are necessary.
i
i
i
i
i
i
i
i
1. Variance Shadow Maps Light-Bleeding Reduction Tricks 211
Figure 1.3. VSM and VSM with p
max
cut off by 0.15.
1.4.2 Applying VSM to Shadow Boundaries
One of the possibilities for reducing the problem of light-bleeding is, simply to
avoid it. The trick is to combine standard depth-comparison shadow mapping
with VSM applied only to regions that really need it—shadow boundaries.
The problem with this idea is that the greater the penumbra region, the
harder it gets to properly detect shadow boundaries, since more samples are
needed. However, if one decides not to blur the shadow map and to rely only
on standard hardware linear (or trilinear) filtering, four samples are enough to
detect shadow boundaries; light-bleeding free VSM is achieved with the resulting
performance comparable to that from standard VSM.
Figure 1.4 shows a side-by-side comparison of standard VSM and the combi-
nation of classic shadow mapping with VSM applied only to shadow boundaries.
Figure 1.4. VSM and VSM applied to shadow boundaries.
1.4.3 Exponential Variance Shadow Maps
EVSM is a combination of two techniques—variance shadow maps and exponen-
tial shadow maps, which were described in [Salvi 08]. The idea was first presented
in [Lauritzen 08] and it is surprising that it is not recognized among developers,
for it is able to almost completely eliminate the light-bleeding.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.134.111.124