Garry's Mod Wiki

Revision Difference

render_stencils#561346

<cat>Don'tListMePlease Dev</cat> <title>Render Reference - Stencils</title> # Render Library References These pages seek to provide helpful insight into the groups of functions provided by the <page text="Render Library">render</page>. The major function groups are: * <page text="Beams">render_beams</page> * <page text="Minification and Magnification Texture Filters">render_min_mag_filters</page> * <page text="Render Targets">render_rendertargets</page> * **Stencils** ⤶ # A Brief Preamble⤶ It's going to be very helpful to you if you already have a grasp on <page text="Render Targets">render_rendertargets</page> before learning about Stencils. It's not necessarily a hard requirement, but you will have a much easier time mentally "Connecting the dots."⤶ ⤶ To avoid repetition, the shorthand term `byte` is used throughout this page to mean "An <page>Number</page> with an integer value between `0` and `255`, representing 8 bits of data." While this is not a term used in Lua, it is commmon in programming.⤶ # What are Stencils? Stencil Buffers (or simply "Stencils") are one of the three (3) layers that make up a <page text="Render Target">render_rendertargets</page>. ⤶ Whenever anything is drawn to a Render Target (Including the main game view,) the Stencil Buffer performs logical checks (More on these later) for each pixel that is about to be drawn to and determines whether or not that pixel should be allowed to change. This functionality gives powerful control over where and when 2D and 3D elements are drawn.**Stencils are a system to constrain drawing to <page text="Render Targets">render_rendertargets</page> on a per-pixel basis.** Whenever anything is drawn to a Render Target, including the main game view, the Stencil performs logical checks (More on these later) for each pixel that is about to be drawn to and determines whether or not that pixel should be allowed to change. Stencils are a powerful tool that gives fine-grained control over where and when 2D and 3D elements are drawn.⤶ **Stencils are a multi-part system** ⤶ The **Stencil Buffer** holds a `byte` for every individual pixel on the Render Target it belongs to. By default, every pixel's Stencil value is `0`.⤶ ⤶ The **Reference Value** is a `byte` that all Stencil Buffer values are compared against during draw operations.⤶ ⤶ The **Compare Function**⤶ ⤶ The **Fail Operation**⤶ ⤶ The **Pass Operation**⤶ ⤶ The **Z Fail Operation**⤶ ⤶ The **Test Mask**⤶ ⤶ The **Write Mask**