Sign in to follow this  
repeat4

stencil buffer?

Recommended Posts

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this