0
\$\begingroup\$

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?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

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.

\$\endgroup\$
5
  • 2
    \$\begingroup\$ Sounds right. "Transparent" pixels by default update all ouput buffers, unless manually discard them or you have alpha testing on. \$\endgroup\$ Feb 5, 2013 at 22:13
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – maul
    Feb 5, 2013 at 22:15
  • \$\begingroup\$ 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? \$\endgroup\$ Feb 5, 2013 at 22:47
  • \$\begingroup\$ guess so. shaders are the future. \$\endgroup\$ Feb 6, 2013 at 1:50
  • \$\begingroup\$ @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/… \$\endgroup\$ Feb 6, 2013 at 10:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .