Stencils
Use the stencil buffer to mask parts of the screen, in a hand-coded shader or in Shader Graph.
Read time 1 minuteLast updated 5 days ago
Use the stencil buffer to control which pixels Unity draws, to hide or reveal parts of your project content for effects such as portals, mirrors, and cutaways.
You can check or write to the stencil buffer in a hand-coded shader in any render pipeline. In the Universal Render Pipeline (URP), you can also set stencil options in Shader Graph, without writing code.
Topic | Description |
|---|---|
| Introduction to the stencil buffer | Understand what the stencil buffer is, how the stencil test works, and what to consider when you use stencils in URP. |
| Choose a masking approach | Compare the ways to hide or reveal parts of objects, sprites, and UI elements in Unity, and choose the approach that suits your project. |
| Set stencil options in Shader Graph | Set stencil options in a Lit or Unlit shader graph to check or write to the stencil buffer without writing shader code. |
Render pipeline information
How you work with stencils depends on the render pipeline you use.
Feature name | Built-In Render Pipeline | Universal Render Pipeline (URP) | High Definition Render Pipeline (HDRP) | Custom Scriptable Render Pipeline (SRP) |
|---|---|---|---|---|
| Stencil | Yes Use the | Yes Use the | Yes Use the | Yes Use the |