Why Doom 3 needed a different shadow count
A shadow-volume renderer does not paint a dark patch directly onto a surface. It builds a three-dimensional region behind an object that blocks the light, then tests whether each visible pixel lies inside that region. A stencil buffer—a small per-pixel counter—tracks how many times the view ray crosses the volume’s boundary. The count tells the renderer whether the pixel is in shadow.
The fragile case comes when the camera is inside a shadow volume, or the volume crosses the camera’s near clipping plane. A conventional approach counts boundary crossings between the camera and the visible surface. But if clipping hides part of the volume’s boundary, the crossings no longer balance correctly. The stencil count can say “lit” where the pixel should be shadowed, or the reverse.
Count from the far side instead
Carmack’s reverse, also called z-fail shadow volumes, changes where the count is made. Rather than counting crossings from the camera toward the surface, it counts boundary crossings between the surface and the far end of the view. In effect, it traces backward from far away toward the light-facing scene. If the camera happens to be inside the volume, that no longer ruins the count: the relevant crossings are on the other side of the surface.
The method depends on the renderer being able to handle the volume’s far boundary reliably. In practice, depth-clamping or a projection that represents the far end appropriately can keep that boundary from being cut off. The technique shifts the vulnerable point; it does not make shadow volumes free of geometric or performance costs.
A fix with a rendering tradeoff
The name can be confused with shadow mapping, which stores light-view depth in a texture and compares it with scene depth. Carmack’s reverse belongs to stencil shadow volumes, a different technique based on enclosing geometry and counting boundary crossings. Its value in Doom 3 was practical: scenes where the camera entered a shadow could be rendered without the clipping error that broke the ordinary count. A camera passing through darkness could therefore remain inside the shadow volume without making the shadow calculation lose track of which side of its boundary it was on.






