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 Answer 1

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\$
1
  • \$\begingroup\$ Wow indeed, thanks a lot! I have missed this part :/ \$\endgroup\$
    – user30088
    Commented Nov 15, 2014 at 9:31

You must log in to answer this question.

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