Stencil buffer

From Wikipedia, the free encyclopedia

In this program the stencil buffer is filled with 1's where-ever a white stripe is drawn and 0's elsewhere. Two versions of each oval, square, or triangle are then drawn. A black colored shape is drawn where the stencil buffer is 0, and a white shape is drawn where the buffer is 1.
In this program the stencil buffer is filled with 1's where-ever a white stripe is drawn and 0's elsewhere. Two versions of each oval, square, or triangle are then drawn. A black colored shape is drawn where the stencil buffer is 0, and a white shape is drawn where the buffer is 1.

A stencil buffer is an extra buffer, in addition to the color buffer (pixel buffer) and depth buffer (z-buffer) found on modern computer graphics hardware. The buffer is per pixel, and works on integer values, usually with a depth of one byte per pixel. The depth 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 make use of the strong connection between the depth buffer and the stencil buffer in the rendering pipeline (for example, stencil values can be automatically increased/decreased for every pixel that failed or passed the depth test).

The simple combination of depth test and stencil modifiers make a vast number of effects possible (such as shadows, 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.

The stencil buffer and its modifiers can be accessed in computer graphics APIs like OpenGL and Direct3D.

[edit] See also


In other languages