Single-pass midpoint shadow maps May 10th, 2011

Here's a little idea I had today. I haven't seen this posted anywhere else so I thought I'd note it down.

How to generate a midpoint shadow map in one pass:

The trick is, in the shader, simply check the VFACE semantic and based on the result, either write r=depth, g=+inf or r=+inf, g=depth out (where +inf is the far-clip value).

There's probably other ways too to work out if it's a backfacing triangle instead of VFACE.

To test against this, when you read the shadowmap simply average the R and G channels to obtain the midpoint depth. You can run a pass to do this first if you like, or you can do it as you sample the texture.


I do not claim that this will stop shadowmaps from making you cry yourself to sleep at night.

Written by Richard Mitton,

software engineer and travelling wizard.

Follow me on twitter: