page_title: Stencil buffer
hierarchical_section_title: Stencil buffer
caption_attribution_description: English: A screenshot from a program which uses that stencil buffer to change the color of shapes as they pass over other shapes. The stencil buffer is filled with 1s where-ever a white stripe is drawn and 0s elsewhere. Two versions of each oval, square, or triangle are then drawn, and the stencil buffer is used to decide per-pixel which object to draw. A black colored shape is drawn where the stencil buffer is 0, and a white shape is drawn where the buffer is 1.
context_page_description: A stencil buffer is an extra data buffer, in addition to the color buffer and Z-buffer, found on modern graphics hardware. The buffer is per pixel, and works on integer values, usually with a depth of one byte per pixel. The Z-buffer and stencil buffer often share the same area in the RAM of the graphics hardware.
  In the simplest case, the stencil buffer is used to limit the area of rendering. More advanced usage of the stencil buffer makes use of the strong connection between the Z-buffer and the stencil buffer in the rendering pipeline. For example, stencil values can be automatically increased/decreased for every pixel that fails or passes the depth test.
  The simple combination of depth test and stencil modifiers make a vast number of effects possible though they often require several rendering passes and, therefore, can put a heavy load on the graphics hardware.
  The most typical application is still to add shadows to 3D applications. It is also used for planar reflections.
context_section_description: A stencil buffer is an extra data buffer, in addition to the color buffer and Z-buffer, found on modern graphics hardware. The buffer is per pixel, and works on integer values, usually with a depth of one byte per pixel. The Z-buffer and stencil buffer often share the same area in the RAM of the graphics hardware.
  In the simplest case, the stencil buffer is used to limit the area of rendering (stenciling). More advanced usage of the stencil buffer makes use of the strong connection between the Z-buffer and the stencil buffer in the rendering pipeline.  For example, stencil values can be automatically increased/decreased for every pixel that fails or passes the depth test.
  The simple combination of depth test and stencil modifiers make a vast number of effects possible (such as stencil shadow volumes, Two-Sided Stencil, compositing, decaling, dissolves, fades, swipes, silhouettes, outline drawing or highlighting of intersections between complex primitives) though they often require several rendering passes and, therefore, can put a heavy load on the graphics hardware.
  The most typical application is still to add shadows to 3D applications. It is also used for planar reflections.
  Other rendering techniques, such as portal rendering, use the stencil buffer in other ways; for example, it can be used to find the area of the screen obscured by a portal and re-render those pixels correctly.
  The stencil buffer and its modifiers can be accessed in computer graphics by using APIs like OpenGL and Direct3D.
caption: In this image, there are white regions and black regions, representing 1s and 0s in the stencil buffer respectively. Shapes are then drawn on top of the stripes by inverting the value of the stencil buffer. If the buffer at that pixel has a value of 0 (black), color the pixel white (1) and vice versa.
exif: {}