Jump to content
  • Advertisement
Sign in to follow this  
Migi0027

Shadow Blurring

This topic is 2114 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!