Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

DirectX9 was the last revision to support alpha-testing.

For DirectX10+:
In fact, transparent pixels do have an influence on the stencil buffer. In order to avoid altering the depth/stencil, you omit the pixel:

if (pixel.a < 0.1) discard;

clip(pixel.a < 0.1f ? -1 : 1); //omit if parameter evaluates to less than 0

clip(pixel.a - 0.1f);

This uses 0.1f to determine "close enough" similar to float.Epsilon.

Be aware: This disables early-z testing and may cause significant and/or unacceptable performance loss.

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? – thumbmunkeys 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:… – thumbmunkeys 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.