Stencil Test is a technical term that is extremely important in rendering and optimizing game graphics (technical art). Explanation of a high-speed culling stage that compares the integer value written to the stencil buffer with the conditional expression of the shader when the GPU draws pixels, and allows drawing only within the range of a specific pattern (mask).
Real-world analogy: determining the holes in the ``brass cutout pattern (stencil buffer)'' that you place on the wall to draw stars with spray art
No matter how much paint (object pixels) is sprayed from above, the color remains only in the holed areas of the pattern (pixels with matching stencil values), and the remaining spray is instantly repelled and disappears.This is an extremely sharp die-cutting drawing system.
Figure: Infographic that clearly illustrates the basic processing flow and mechanism of Stencil Test in Japanese.
Detailed mechanism and operating principle
Write "value: 1" to the stencil in the shader of the plate object for the mask, and set a comparison test in the shader of the other world object that "does not draw pixels other than those with a stencil value of 1 (discards like ZTest)".