You copied the Doc URL to your clipboard.

Stencil updates

Many stencil masking algorithms toggle the stencil between a few values when creating and using a mask. When designing a stencil mask algorithm that uses multiple draw calls, the aim is to minimize the number of stencil buffer updates that occur.


You must understand the following concepts:

  • Stencil masking algorithms.

How to minimize stencil buffer updates

Try using the following optimization steps:

  • If the values are the same, then use KEEP rather than REPLACE.
  • Some algorithms use pairs of draws: one to create the stencil mask, and one to color the unmasked fragments. In this case, use the second draw to reset the stencil value so it is ready for the next pair. Doing so avoids the need for a separate clear operation.

HDR rendering steps to avoid

Do not waste performance by writing a new stencil value unnecessarily.

The negative impact of implementing stencil updates incorrectly

A fragment that writes a stencil value cannot be rapidly discarded. In turn, introducing an extra fragment processing cost that affects the performance of your application.