Shadow Blurring

Started by
3 comments, last by kalle_h 10 years, 6 months ago

Hi guys, again!

One issue that I never fixed and cared about, until today, was a problem occurring when blurring the shadow map. As you know, shadow maps have a resolution, and that affects their precision, and as you can't have unlimited precision in shadow maps, you will get some artifacts, like the stair effect. One of the suggested ways to fix this, or cover it, is to do the following:

  • Render the scene with lighting to a render target
  • Blur the render target x times to a resource
  • Sample the new resource on top of the current color, like: color *= lighting

But, when doing this, some artifacts occur, at least for me. So if you imagine a cube, which is pretty dark, and then a large plane just under it which is fully lit. When blurring this image, some of the white from the plane (in the lighting map) will be smoothed to the cube, and then in the final image it may appear as the edges of the cube to be slightly lit, which is wrong and looks terrible.

How should I tackle this problem? Am I using a wrong method?

Thanks, as usual!

-MIGI0027

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

Advertisement

You can use a bilateral blurring filter.

When taking nearby samples for blurring, you don't (just) use hard-coded weights (Gaussian, etc). You also create a second set of weights based on how "valid" the sample is, optionally multiply these with your hard-coded Gaussian weights, then renormalize the weights for all samples so that they sum to 1.0.

To determine whether a sample is valid or not, you can use a colour threshold (e.g. so if the centre is white, a black sample will be rejected, but a slightly grey sample will be accepted), a depth threshold (so if the samples differ in Z compared to the centre by too much, they're rejected), etc...

Sometimes you'll see a bilateral blur filter that's based on Z values called a Depth Sensitive Filter.

I've used this to soften SSAO before, and I implemented both the colour-threshold and depth-threshold versions, and then tweaked them both before deciding which one worked better for my game wink.png

Also, if you want to use hardware filtering, you can take a look at Variance Shadow Maps, or Exponential Shadow Maps. They have their own quirks though.

Perception is when one imagination clashes with another

Filtering in screen space for shadows is pretty bad. It sort-of works, but really you want to filter the shadow map itself instead of filtering after-the-fact. Usually this requires PCF, or using some form of Variance Shadow Maps.

Filtering in screen space for shadows is pretty bad. It sort-of works, but really you want to filter the shadow map itself instead of filtering after-the-fact. Usually this requires PCF, or using some form of Variance Shadow Maps.

Using PCF shadows and then ouputting result to unused channel of SSAO buffer to get free bilateral blur is quite handy. It's not perfect but at least it reduce certain artifacts.

This topic is closed to new replies.

Advertisement