What it does

A Stencil Buffer stores an integer marker at each screen location. One draw writes a marker and another tests it, allowing masks that restrict drawing to areas such as the inside of a window.

Figure: Write one first, then compare against one in a later draw. Writer and reader states differ.
Figure: Write one first, then compare against one in a later draw. Writer and reader states differ.

How to use it

Define writer reference, write mask, comparison and pass operation separately from reader reference, read mask and comparison. Both must use the intended shared depth/stencil target in the correct order.

A concrete example

An isolated mask example writes reference one with Replace, then reads Equal one while keeping the value. Check pipeline-reserved bits before adopting that number in a real renderer.

How to check it

  1. Inspect writer and reader passes, shared targets and intervening clears in Frame Debugger.
    Testing and writing are separate settings
    Testing and writing are separate settings
  2. Separate inverted comparisons from buffer-sharing or camera-clear problems.
    Testing and writing are separate settings
    Testing and writing are separate settings

Limitations

Check target sharing, clearing, and bits reserved by the pipeline.

References