Stencil buffers, say WHAT?
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]
quote:Original post by Basiror
as far as i know the stencil buffer is part of the z buffer buti may be wrong so
So why give an answer at all?
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).
http://www.back2roots.org/Demos/Files/Daydreamer%2C2/
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.
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).
http://www.back2roots.org/Demos/Files/Daydreamer%2C2/
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement