Inverted Normal Studio

Sharp Stencil Shadows

Documentation for Sharp Stencil Shadows, a URP renderer feature for hard, pixel-exact stencil shadow volumes.

How Stencil Shadow Volumes Work

Home › Overview

A short explanation of the technique, for understanding what the settings control.

Shadow volumes

For each caster and light, the asset builds a shadow volume: a closed mesh enclosing the space the caster blocks from the light. It is made of:

  • Silhouette quads, extruded away from the light along the caster's silhouette edges.
  • A near cap from the caster's light-facing triangles, and a far cap at the end of the extrusion.

Directional light volumes extrude at least Minimum Extrusion Distance and far enough to close beyond the camera's view. Point and spot light volumes end at twice the light's range.

Finding silhouette edges needs each mesh's edge adjacency, its topology. See Mesh Topology.

Z-fail counting

Volumes are drawn into the stencil buffer without color. Where a volume's back faces are hidden behind scene geometry the stencil counter goes up, and where its front faces are hidden it goes down. A visible pixel with a non-zero count lies inside the volume and is in shadow.

This z-fail method (Carmack's Reverse) stays correct when the camera is inside a shadow volume, which is why volumes must be closed.

The owned stencil bits

The feature uses only the low stencil bits set by Stencil Mask (default 0x0F) and leaves every other bit untouched.

  • The union bit is the highest owned bit and accumulates every finished caster's shadow.
  • The counter is the lower bits: each caster's volume is counted there, then folded into the union bit and cleared, so casters never corrupt each other's counts.

The counter wraps around. With the default mask in Overlay mode, a pixel covered by a multiple of 8 layers of one caster's volume counts back to zero and loses that caster's shadow. A wider mask, URP Lighting mode, or splitting the mesh fixes it. URP Lighting counts in its own stencil target with all eight bits, so it wraps only at 128 layers. See Stencil Mask.

Self-shadow cancellation

A caster's own volume would also darken the caster's visible surface. Before folding into the union bit, each caster's visible surface is redrawn to clear its own count. This removes the caster's self-shadow artifacts without removing shadows other casters throw onto it.

See Receivers and Materials.

The final composite

  • Overlay: after opaques, pixels in the union bit are blended toward Shadow Color by Shadow Strength, in one pass.
  • URP Lighting: before opaques, each light's result is written to the shadow textures URP's lit shaders already read, so a shadow removes only its own light's contribution.

See Lights and Lighting Modes.

Beyond solid geometry

A volume only knows a mesh's shape, not its texture holes or opacity. Alpha-clipped and transparent casters can instead be drawn into a light-space caster atlas. See Transparent and Translucent Casters.

Where the work happens

Volumes are generated on the CPU with Burst jobs or on the GPU with compute shaders. A volume is only regenerated when its caster, pose, or light changes, so static scenes cost little beyond drawing. Each caster's stencil work is scissored to its screen area. See Performance.