Advertisement Jump to content
Sign in to follow this  

Stencil buffer, the inner workings?

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

I'm a bit confused regarding how the stencil buffer works. I know the basic stuff but I'm a bit uncertain how the different masks are applied. Consider: D3DRS_STENCILPASS = D3DSTENCILOP_INCR D3DRS_STENCILWRITEMASK = 0xf0 I'd be under the impression that the gpu would perform: X = (X + 1) & 0xf0, right? This means that the content of the buffer will never change? Another question, about D3DRS_STENCILMASK, the docs states "Mask applied to the reference value and each stencil buffer entry to determine the significant bits for the stencil test." Does the gpu perform (X & 0xf0) op D3DRS_STENCILREF? So: D3DRS_STENCILMASK = 0xf0 D3DRS_STENCILFUNC = D3DCMP_GREATER So for all X < 0x10 the stencil test will fail, or? Can someone shed any light on the eaxact behaviour, or a link?

Share this post

Link to post
Share on other sites
Ahh.. found the following in the docs:


performed using the following steps.

1 Perform a bitwise AND operation of the stencil reference value with the stencil mask.
2 Perform a bitwise AND operation of the stencil buffer value for the current pixel with the stencil mask.
3 Compare the result of step 1 to the result of step 2, using the comparison function.

These steps are shown in the following code example:

(StencilRef & StencilMask) CompFunc (StencilBufferValue & StencilMask)

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!