Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Do transparent pixels cause a stencil buffer operation (increment, decrement, etc.) to be executed?

My understanding was that only opaque pixels cause a stencil buffer operation, transparent pixels have no effect on the buffer. However in my application transparent pixels do seem to cause the stencil buffer to be written.

Do I have to set up a special blendstate in order to achieve transparent pixels to have no effect?

share|improve this question

1 Answer 1

I found the answer, although I would be happy if someone could suggest a better way.

In fact transparent pixels do have an influence on the stencil buffer. In order to avoid this influence one has to avoid having a pixel an effect directly in the pixel shader, like so:

    if(pixel.a < 0.1)
share|improve this answer
Sounds right. "Transparent" pixels by default update all ouput buffers, unless manually discard them or you have alpha testing on. –  Sean Middleditch Feb 5 '13 at 22:13
As a minor note, testing if a == 0 might be a bad idea because of texture sampling interpolation. You should do if (a < 0.01) or so, or even define a higher cutoff value like 0.5. –  maul Feb 5 '13 at 22:15
thanks for both of your comments. @Sean: If i understood correctly, alpha testing has been removed in DirectX 11, so using the shader is the only way? –  pivotnig Feb 5 '13 at 22:47
guess so. shaders are the future. –  Sean Middleditch Feb 6 '13 at 1:50
@Sean: right, it is just that an if in a shader always makes me a bit nervous. But according to this, probably there is no reason to be: stackoverflow.com/questions/5340237/… –  pivotnig Feb 6 '13 at 10:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.