Sign in to follow this  

Stencil buffer help

Recommended Posts

I'm having touble using the read and write masks with the stencil buffer and wanted to clarify how they're used. Here's my example setting: D3DRS_STENCILFUNC = D3DCMP_LESS D3DRS_STENCILPASS = D3DSTENCILOP_INCR D3DRS_STENCILFAIL = D3DSTENCILOP_KEEP D3DRS_STENCILMASK = 0x11 (0001 0001) D3DRS_STENCILWRITEMASK = 0x11 D3DRS_STENCILREF = 0x11 Is this what happens?
TestValue = StencilBuffer & StencilMask

If (TestValue < StencilRef)
  StencilBuffer = (TestValue + 1) & StencilWriteMask

Share this post

Link to post
Share on other sites
Close. You can find more exact formulations at the "Stencil Buffer Techniques" page in the docs.

Share this post

Link to post
Share on other sites
k, so it looks like the stencil test is actuall
If ((StencilBuffer & StencilMask) < (StencilRef & StencilMask))

The docs didn't explain what gets written out though,

Is it ((StencilBuffer & StencilMask) + 1) & StencilWriteMask

or just (StencilBuffer + 1) & StencilWriteMask


Also I should add that I'm using DX9. The docs say you can do this, but I have no clue how you're supposed to go about writing your own formula:


You can write your own formula for the value you want written into the stencil buffer as shown in the following example.

NewStencilBufferValue = (StencilBufferValue & ~StencilWriteMask) |
(StencilWriteMask & StencilOp(StencilBufferValue))

[Edited by - Unfadable on May 25, 2007 9:23:31 PM]

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