Stencil buffer help

Started by
1 comment, last by Unfadable 16 years, 11 months ago
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

Advertisement
Close. You can find more exact formulations at the "Stencil Buffer Techniques" page in the docs.
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


Thanks,

edit:
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:

Quote:
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]

This topic is closed to new replies.

Advertisement