2

I have problems with Z-fighting for my moving directional light casting shadows.

I'm trying to tinker with the rasterizer config when rendering the shadowmaps. There are three fields related to depth bias (DepthBias, SlopedScaleDepthBias, DepthBiasClamp) and no matter how I tinker with them I can't find a good value - I have no idea what value range is even appropriate.

Is there a universally-acceptable / "standard" set of sloped-scale/bias values that works for most scenes? I realize there are extreme cases but I just want the general case to work fine.

Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
KaiserJohaan
  • 9,028
  • 20
  • 112
  • 199
  • You might want to double-check your depth buffer format to make sure you have enough precision there. You can also invert your view frustrum so you have a w-buffer rather than a z-buffer as it's generally better use of floating-point depth. – Chuck Walbourn Jul 25 '15 at 23:55
  • You might also want to take a look at the legacy DirectX SDK shadow samples CascadedShadowMaps11 or VarianceShadows11 on [GitHub](https://github.com/walbourn/directx-sdk-samples). They use aSlopeScaledDepthBias of 1.0. – Chuck Walbourn Jul 27 '15 at 15:44

1 Answers1

1

There isn't something like standard set of bias values. Implementing shadow maps is more like art than science :).

  • First ACME source is shadow map precision. Make sure that near and far planes of shadow casting light are as tight as possible. All objects before the near plane can be pancaked, as their exact depth isn't important.
  • Second ACME source is shadow map resolution. For a sunlight you should be doing cascaded shadow maps with at least 3 1024x1012 cascades for ~100-200m of shadow distance. It's hard to cover similar shadow distance with one shadow map with uniform projection.
  • Third ACME source are wide shadow map filters like PCF, as using a single depth depth comparison value across a wide kernel is insufficient. There are many methods to fix it, but none of them is robust.

To sum up, a tight frustum with a few cascades and some bias tweaking is enough to get the general case working. Start tweaking by disabling shadow filtering and tweak for filtering only when basic shadow maps are robust enough.

There are some additional interesting methods and most of them are implemented in the excellent demo: Matt Pettineo - "A sampling of shadow techniques".

  • Flip culling during shadow map rendering (this trades acne for Peter panning).
  • Normal offset shadow mapping does wonders for bias, but requires to have vertex normals around during shading.
  • Variance based methods (ESM,VSM,EVSM) completely remove bias issues, but have other drawbacks (light leaking and/or performance issues).