07.01.2013 Views

3D graphics eBook - Course Materials Repository

3D graphics eBook - Course Materials Repository

3D graphics eBook - Course Materials Repository

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Stencil buffer 195<br />

Stencil buffer<br />

A stencil buffer is an extra buffer, in addition to the<br />

color buffer (pixel buffer) and depth buffer<br />

(z-buffering) found on modern computer <strong>graphics</strong><br />

hardware. The buffer is per pixel, and works on integer<br />

values, usually with a depth of one byte per pixel. The<br />

depth buffer and stencil buffer often share the same<br />

area in the RAM of the <strong>graphics</strong> hardware.<br />

In the simplest case, the stencil buffer is used to limit<br />

the area of rendering (stenciling). More advanced usage<br />

of the stencil buffer makes use of the strong connection<br />

between the depth buffer and the stencil buffer in the<br />

rendering pipeline. For example, stencil values can be<br />

automatically increased/decreased for every pixel that<br />

fails or passes the depth test.<br />

The simple combination of depth test and stencil<br />

modifiers make a vast number of effects possible (such<br />

In this program the stencil buffer is filled with 1s wherever a white<br />

stripe is drawn and 0s elsewhere. Two versions of each oval, square,<br />

or triangle are then drawn. A black colored shape is drawn where the<br />

stencil buffer is 1, and a white shape is drawn where the buffer is 0.<br />

as shadows, outline drawing or highlighting of intersections between complex primitives) though they often require<br />

several rendering passes and, therefore, can put a heavy load on the <strong>graphics</strong> hardware.<br />

The most typical application is still to add shadows to <strong>3D</strong> applications. It is also used for planar reflections.<br />

Other rendering techniques, such as portal rendering, use the stencil buffer in other ways; for example, it can be used<br />

to find the area of the screen obscured by a portal and re-render those pixels correctly.<br />

The stencil buffer and its modifiers can be accessed in computer <strong>graphics</strong> APIs like OpenGL and Direct<strong>3D</strong>.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!