XNA 4.0 variance shadow mapping

I’ve just updated and refined another code sample from XNA Community, from XNA version 3.1 to 4.0. This one is on variance shadow mapping, which is basically a way to get shadow maps that are filterable- that is, you can apply any kind of texture filter onto the shadow mapping image to give it a smoother look. Optionally, and usually, a Guassian blur filter is applied. Together, variance shadow mapping improves the visual quality of the shadows as well as giving more leeway to the size and number of textures needed to produce good results.

In the sample code, the program uses one 1024×1024 texture to produce the shadow map, and applies a two-pass filtering technique for Gaussian blur. This blur is not done in screen-space, but because the original shadow map can be filtered, it is almost indistinguishable from a screen-space blur, which will produce leaking artifacts if done with normal shadow maps.. Most of the heavy image computation is done in this step.

The shadow uses a 2-channel 32-bit texture for the depth map, in contrast to a single floating-point texture format used in conventional shadow mapping. This allows us to store two “moments”, which are simply the depth and the squared depth stored in the depth texture. From here we are able to calculate the mean depth and variance of the given pixel in the map. One noticeable drawback to variance shadow mapping is light bleeding among shadows where the shadow casters are of very different depths. An easy fix to reduce this effect would be to raise the shadow amount by a certain exponent, but raised too high and the shadows dampen too much.

I plan to use some form of variance shadow mapping to my graphics engine, but in the meantime I’ll try to make improvements on it, in order to remove the light bleeding more effectively. But in the meantime, you can download current sample project here, compatible with XNA 4.0.



9 thoughts on “XNA 4.0 variance shadow mapping

  1. (sorry for my bad english)

    Hello, I am trying to download this sample, but apparently your zip file is corrupted.
    For your sample about paraboloid reflections, it search for tga image in an absolute path, So I can’t launch the project 🙂

  2. How do you find the look of the shadows generated with VSM? I see in your screenshot above that most of the boxes seem to be floating due to the lack of “shadow density” near the caster. I’ve had the same problems with my implementations, and I’ve never been satisfied with the look of VSM.

    • I too find the lack of shadow darkness close to the casters rather unsatisfying- in other articles and papers I’ve read, their screenshot examples showed nothing of the sort. In the meantime, PSSM still manages fine for me, although the appeal for VSM for me is its soft edge shadows and perspective projection.

      [Edit] I found that raising the power of the shaded regions has helped in darkening the shadows closest to the casters.

  3. Looks like the link expired, or it’s unfortunate removal from the recent takedown of file-sharing sites. I’m re-upload it to a more reliable place, maybe SkyDrive.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s