Alpha blending, transparence and z-ordering

1.1k views Asked by At

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!

1

There are 1 answers

0
Andon M. Coleman On

You typically disable depth writes (e.g. glDepthMask (GL_FALSE)) for the translucent objects, but the depth test itself is not something you would disable.

You need to test against the depth values generated by the opaque objects for this to function correctly, otherwise you have to sort both your opaque and translucent objects (which is exactly what you did originally).