1
\$\begingroup\$

I'm making some tests with alpha blending in a projet and I don't understand something.

In my tests I've done something like that and everything look good:

  • Draw blue box first (depth test: true, blend alpha: none, color: 1, 1, 1, 1)
  • Draw left Mario (depth test: false, blend alpha: true, color: 1, 1, 1, 0.8)
  • Draw red box (depth test: true, blend alpha: none, color: 1, 1, 1, 1)
  • Draw right Mario (depth test: false, blend alpha: true, color: 1, 1, 1, 0.8)

enter image description here

Every tutorial say that we should:

  • Draw opaque object first
  • Order transparent object back to front then draw them.

Here is the result:

enter image description here

So, I'm not sure to understand how it work/what is wrong (I've read this document).

Thanks!

\$\endgroup\$
1
\$\begingroup\$

A quote from the document you pasted:

15.070 If I draw a translucent primitive and draw another primitive behind it, I expect the second primitive to show through the first, but it's not there?

Is depth buffering enabled?

If you're drawing a polygon that's behind another polygon, and depth test is enabled, then the new polygon will typically lose the depth test, and no blending will occur. On the other hand, if you've disabled depth test, the new polygon will be blended with the existing polygon, regardless of whether it's behind or in front of it.

You shouldn't disable depth testing before drawing the transparent marios. When depth testing is enabled, it will test if the pixels are already behind the opaque (or transparent if any has been drawn) boxes you have drawn earlier, and the output should be what you want.

\$\endgroup\$
  • \$\begingroup\$ Wow indeed, thanks a lot! I have missed this part :/ \$\endgroup\$ – user30088 Nov 15 '14 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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