Jump to content
  • Advertisement
Sign in to follow this  
repeat4

stencil buffer?

This topic is 4306 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

stencil buffer is used in many specific techniques,but I can't understand it at all. can anybody explain stencil buffer for me?

Share this post


Link to post
Share on other sites
Advertisement
The stencil buffer is made of a few bits from the z buffer (usually 8 bits). Altrough you can't access the stencil buffer directly or output a stencil value in the pixel shader, you can still use some render states to change its behavior (D3DRS_STENCIL*). There are mainly two things you can do with the stencil:

1. Write to it. Using the render states, you can enable Draw*Primitive() calls to write to the stencil buffer. This usually allows you to mark certain regions of the screen for later operations. It allows you to modify stencil in three different situations (when the pixel fails the stencil test [see D3DRS_STENCILZFAIL], when the pixel fails the z test [see D3DRS_STENCILFAIL] and when the pixel passes the z test [see D3DRS_STENCILPASS]). For all of these situations, you can specify that you want to keep the stencil value [D3DSTENCILOP_KEEP], set it to zero [D3DSTENCILOP_ZERO], replace with the current reference value [D3DSTENCILOP_REPLACE using D3DRS_STENCILREF to set the reference value], increment or decrement the value that is already there [look at the D3DSTENCILOP type for more details about the stencil operations]. You can select which bits to write to using D3DRS_STENCILWRITEMASK. For all of these, you need to enable D3DRS_STENCILENABLE.

2. Use it to discard/allow pixels to be written. There is a stencil test that can be enabled to reject pixels based on the value stored in the stencil buffer and the current reference value. Check out (The following render states D3DRS_STENCILENABLE, D3DRS_STENCILFUNC, D3DRS_STENCILREF & D3DRS_STENCILMASK).

I hope this will be a good starting point to understand the stencil buffer.

- Aldenar

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!