Shadow map filtering experimentation.

Edit: I demonstrated some harder cases for the important filters here. I also used a brighter light so that it’s easier to see the shadow edges :)


Over the past two weeks I’ve been working on various parts of my game engine’s shadow mapping, mostly experimenting with different shadow filtering techniques.

No shadow filtering.

No shadow filtering.

For reference, above are two images of a simple test scene without any shadow map filtering applied.

I started with basic 4 tap PCF, using a simple averaging of the samples. See this filtering below.

4 tap PCF taking the mean of the samples.

Then I moved on to edge-tap smoothing of the 4 tap PCF filtering method:

4 tap PCF with edge tap smoothing (a linear blending between sample values).

Then I experimented with using more than 4 samples:

7 tap PCF with edge tap smoothing.

Below is an implementation of the dithering idea in the article Shadow Map Antialiasing from GPU Gems 1.

4 tap PCF with screenspace dithering.

The GPU Gems 1 method above selects shadow sampling positions based on the fragment’s current screenspace coordinates. So I tried rotating the 4 samples based on the current fragment position (in screen space) instead. See the image below.

4 tap PCF with screenspace based rotations.

8 tap PCF using rotated poisson disc with screenspace based rotations.

I also tried doing the rotations based on object space instead:

4 tap PCF with object space based rotations.

Then I tried using a small lookup texture (32×32) with random 2×2 matrix rotations, used to offset the 4 samples in random directions based on a screenspace sampling of the random noise texture. See below.

4 tap PCF with 202 pixel sampling area, sampling chosen by taking rotations from a lookup texture.

4 tap PCF with 50 pixel sampling area, sampling chosen by taking rotations from a lookup texture.

4 tap PCF with 50 pixel sampling area, sampling chosen by taking rotations from a lookup texture.

It’s worth noting that even though the last two methods shown are the same and both use 4 samples, the first method chooses samples from a larger area than the second. This makes the penumbra larger, hides the underlying shadow map better, but also costs more texture bandwidth due to worse cache coherency. The 202 sampling area PCF requires a large bias, to the point where even with slope-scale biasing, I couldn’t choose a small enough bias to avoid shadow peter-panning completely.

The last method shown actually produces pretty good looking shadows, and is quite efficient. It also allows for an easily modifiable sampling area, which could be very useful — more on this later.

None of these filtering methods produced particularly smooth looking static shadows. Except for the last method displayed, all of these shadows “shimmer” horribly when the camera or light source moves. The rotated disc method shadows also shimmer, but the effect is not nearly as bad as the other PCF sampling methods. And even though they are all pretty fast, they require fairly large shadow maps. All of the images so far have used 2048×2048 shadow maps.

Next I started implementing exponential shadow maps (ESMs). These allow us to blur the shadow map or otherwise filter it before drawing the light, and then we can take a single sample from the shadow map, using an approximation of the shadow penumbra. This method avoids biasing problems that large penumbra PCF sampling has. It also requires less texture bandwidth.

I started by using 2xMSAA when creating the shadow map (which effectively blurs the shadow map edges). A 2048×2048 shadow map is used, and 2xMSAA doubles the size of the texture at creation time. This makes this texture 32MB in total, which is far larger than the Xbox 360′s 10MB eDRAM, and therefore far too large to be practical on the Xbox 360. A 5×5 seperable gaussian blur is also applied to the shadow map before drawing the light.

1 tap ESM with a small shadow map and 4xMSAA + 5x5 gaussian blur.

I also tried taking 4 samples of the shadow map, creating the shadow map with 4xMSAA, and not even bothering with a prefiltering step (so there is no gaussian blurring of the shadow map). This is potentially a faster method, and is the method that I am currently using for point light shadows (which are less dominant lights than the directional light shown in all of the screenshots so far).

4 tap ESM filtering with 4xMSAA used when creating shadow map. No shadow map prefiltering.

Since the results of the ESM with a gaussian blur prefilter are quite good, I started reducing the shadow map size. Below is a 512×512 shadow map with 4xMSAA (which means that the texture easily fits into the XBox EDRAM and therefore 4xMSAA incurs very little texture bandwidth cost). A 5×5 separable gaussian blur is applied so that a single sample is enough to produce a smooth penumbra.

1 tap ESM filtering, 2xMSAA + 5x5 gaussian prefiltering of shadow map.

This technique is fast and looks good. One problem with it though, is that the penumbra size is fixed, which is not realistic. In real life, light is scattered around, and light sources are not ideal points or directional lights. Percentage closer soft shadow (PCSS) approximate real life shadow penumbras by determining where the penumbra should be sharper or softer. Shadow penumbras are typically sharper close to the occluding object, and softer further from the object — instead of soft everywhere like in the image above.

The problem with a pre-filtered shadow map using one ESM tap, is that you cannot change the size of the penumbra by expanding the sampling kernel size (as there is only 1 sample) and the shadow map prefiltering used a fixed size kernel (a 5×5 Gaussian in this case). This is something that is easier with PCF, but as we saw, PCF does not look good with only a few samples. PCSS can be expensive, and is only an approximation — and not a very good one when there are multiple layered occluders. So this is a problem that I’ll defer until later. Possible solutions include varying the ESM exponent to vary the penumbra size, or combining PCF sampling techniques shown earlier with ESM to vary the kernel size.

This entry was posted in Coding, XNA and tagged , , , , , , . Bookmark the permalink.

16 Responses to Shadow map filtering experimentation.

  1. Pingback: Exponential shadow mapping drawbacks. | Olhovsky

  2. Xiaoxiong says:

    Could you show me the code you used for Edge Tap smoothing? I am working on smoothing edge after applying PCF

  3. Watch for chewing, especially around items such as electric cords.
    Ferrets are also prone to certain illnesses – and injuries – and may also require emergency services.
    Don’t make any sudden movements as you don’t want
    your boa constrictor to bite you as boas are sensitive to humans and can easily feel threatened.

  4. Great goods from you, man. I’ve take into account your
    stuff prior to and you are just too magnificent.
    I actually like what you’ve received here, really like what you’re saying and the best way in which you are saying it.
    You’re making it enjoyable and you continue to care for to stay it
    sensible. I can’t wait to read much more from
    you. This is actually a wonderful web site.

  5. This is the first bachelorette celebration of my team so I will most definitely mazke use of Phoenix Digital Printing once more for all future
    screen printing demands.

  6. É neste âmbito que surge a gravidez, que vem como
    uma barreira no desenvolvimento regular dos jovens, das meninas em particular.

  7. Maritza says:

    I have an adventurous essence and a lust always and discovering sensual ness,
    and am adept to place tense new associates comfy at intervals
    minutes. Thhe Driver is chosen by a spoiled and shallow celebrity to drive heer to a venue.

    If you have at least 40 points in Medicine, then you ccan heeal him.

  8. He smiled even lesas when I tried tto make a joke to slip by him and he tossed me aside liie I was nothing.
    I amm Rashi Kher, a Mumbai model and best Models based inn Mumbai and also accessible for National travel.
    It is very important to check the track record for goood service, well
    trrained escott and privacy; these are certain aspects
    that you simply cannot compromise with.

  9. “Tycoon” was the llast book released (in December 2005).
    The German forces had been bogged down by the
    Russian winter, the Russian victory at Stalingrad and then thee subsequent spring rain and mud.
    A Denver home caregiver may also provide assistance with meal planning, meal preparation and cleanup, a definite help
    for those elders who are having trouble preparing meals on their own.

  10. Well you got to set the relationship tone immediately, go on dates, get in touch with her, and treat her like she is already
    your sweetheart.

  11. When a person starts dating once again, it does not mean that
    he’s ended up grieving over the loss of his sweetheart or that the relationship didn’t matter to

  12. Bonding- it’s a treatment to fix a broken or broken tooth and
    give it a wholesome look. When a sorely infected tooth eventually drove him
    to the dentist last month, it was to a center in a Mexican border
    city better understood for violent crime and drug cartels.

  13. It’s a significantly popular product that can help divorcing partners discover covert properties, ensuring a more secure monetary future on their own and their kids.

  14. This website really has all of the information I
    needed concerning this subject and didn’t know who to ask.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>