Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Stencil buffers, say WHAT?

This topic is 5621 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

OK, I must have missed something during my courses on computer graphics What the heck are stencil buffers? Is it the same as a Z-buffer? Over and out... ************************** The best way to accelerate a Win9x machine is at 9.81m/s2 [edited by - rohde on January 29, 2003 4:03:13 PM]

Share this post

Link to post
Share on other sites
The stencil buffer is (normally) a 1- or 8-bit-per-pixel "mask" of sorts.

For example. Clear the screen, z-buffer, and stencil buffer. Draw some terrain with Z-write on, stencil-write off. Then, with Z-write set to "infinity", and with stencil-write set to "set", draw your water. Good so far? Good.

Next, take every object you want reflected in the water, mirror it across the water plane, and render it with Z-buffering, transparency, and stencil-checking on; this will render only to those areas where the stencil buffer is "set". Once that is done, render it again above the water, with stencil-checking disabled and with stencil-write set to "clear".

All of that will create pretty good reflective water. Now, what does the stencil buffer actually _do_?

The stencil buffer is a way to mask off and control which pixels on the screen get rendered to by any rendering operation (only those by Direct3D, not by DirectDraw, when using DirectX). In this way, you can render something to the stencil buffer, and then make sure that something rendered later will draw only where the stencil buffer is either "clear", or "set". Or, in the case of a more-than-1-bit stencil buffer, you can set it up to use alpha-blending based on the stencil buffer.

For a great example of this, go to the url below, and download that demo (click the screenshot).


Wait for the burning-painting scene. They are rendering the "painting" first, then rendering a bunch of circular particles, which are slowly growing, with stencil-write enabled, writing to the 8-bit stencil buffer.

They then render the scene you''ll see appear "behind" the "painting", with stencil-checking enabled and being used as the alpha-blending key.

Beware, though, that scene drags down to about 12 FPS on my GeForce3; it is pure hardware, and it takes a lot of power. You can watch it without that kind of hardware, but you''ll be watching a slideshow on a GeForce2 GO or MX.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!