Alpha transparency and Z order problem in OpenGL or P3D

I've searched many posts going back to Processing 1 and have found this issue documented but no resolution or workaround.

The proposed "solution" to enabling alpha transparency in 3D is to use hint(DISABLE_DEPTH_TEST). However, as well documented, this destroys the Z order causing lines/objects to be rendered on top of each other incorrectly, and where an object should pass "behind" another and be obscured by it, the geometry/perspective correctly places it back there, but the visual rendering shows the far objects drawn on top of the near ones. It's like viewing layers in reverse order. In addition, it would seem that transparency is either on or off, i.e., to have an object be transparent the object seen through it is at full saturation, with no toning by different alpha values of the translucent panel in front of it. This would make sense in that it is not really showing transparency, rather rear objects are drawn on top, and therefore the object can be "seen" through the alpha fill.

Does anyone have a solution for this issue? Just disabling the depth test messes up the rest of the 3D rendering, so it's either drop any form of alpha transparency in 3D or have the scene rendered incorrectly. FWIW, I've also tried hint(ENABLE_DEPTH_MASK) and hint(ENABLE_DEPTH_SORT) plus their inverses (DISABLE...) to no avail/difference.

Thanks in advance for any insight into this

Answers

  • I have the same problem here. Did you find your answer?

  • edited March 2015

    Hello ! The only solution I know is a bit complex...

    1) the big part : You have to "convert" your mesh into a list of triangles with a z-value for each

    2) for each frame of your animation, you have to apply a z-sorting using Collection.sort (for example) on your triangle list

    3) after you did the z-sorting, you have to update the vertexBuffer of the shader (the array with the XYZ of each vertex of your mesh). To do that, you just need to loop on all yours triangles and fill the vertexBuffer using the function "vertex(X,Y,Z)" (then you have to call "vertex" 3 times by triangle )

    In other words, you have to redraw every triangles of your mesh independantly, after you applyed a z-sorting on your triangle-list.

    I really don't know if there is another solution, I always processed like that.

    And yes, it works :)

Sign In or Register to comment.