Cascaded shadow map bug between splits

Just to wrap up this thread, that is in-fact the underlying problem (bogus texture gradients on split boundaries). Two solutions out there for this:

  1. Tweak the split indices in the shader so that pixels in the same GPU pixel quad always use the same split.
  2. Compute analytic texcoord gradients in the shader.

Both are described in:

  • Shader X7, Chapter 4.1 (Practical Cascaded Shadow Maps), “Filtering Across Splits” section, pp. 321-327
    …but the code they list for #1 (derived from a snippet by Andrew Lauritzen) is buggy.

You can find the correct, original snippet here:

  • Variance Shadow Maps Demo (D3D10) (Andrew Lauritzen, Beyond3D post, 4/25/07)
    Use log2 or his lookup table as desired. Also the dot trick for computing the split saves a surprisingly number of frag instructions.

And as we’ve both discovered, apparently texture gradients are important not only when you have MIPs (e.g. when using shadow map pre-filtering methods such as VSM), but also when you have aniso enabled on a standard, non-MIPed depth map.

Also, one final note on that. Using aniso on a standard shadow map doesn’t work very well at all. While it does soften shadow edges a bit, it essentially means integrating over a larger area of the map, which (if there’s a a depth gradient in the shadow map) causes depth texels further and further from the desired depth sample to potentially shadow it. This leads to having to apply more and more bias with increasing aniso to avoid self shadowing. And that isn’t good.