Alpha Sorting in same Mesh broken

Hey guys,

first off, there is a lot of talk on this topic already but there are no true solutions to this problem.

We got a mesh with a TextureArray and the textures are mostly opaque and some are translucent.

The opaque faces disappear if you look through the translucent textures. It seems that that it is either Alpha-Sorting or Depth-Buffer Sorting problem.

On this page Tutorial 10 : Transparency the guy explains how it is done generally in the correct way.

- Draw the opaque part of the world so that the depth buffer already can reject hidden transparent triangles - Sort transparent triangles, from the furthest to the closest - Draw the transparent triangles

So far we’ve tried everything we could find in the JME-Forum in every possible combination with no luck.

[java]

geom.setQueueBucket(Bucket.Translucent);
geom.setQueueBucket(Bucket.Transparent);
…
mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
…
mat.getAdditionalRenderState().setDepthWrite(…);
mat.getAdditionalRenderState().setDepthTest(…);
…
mat.getAdditionalRenderState().setAlphaTest(…);
mat.getAdditionalRenderState().setAlphaFallOff(0.5f);
…
mat.getAdditionalRenderState().setDepthFunc(TestFunction.LessOrEqual);
mat.getAdditionalRenderState().setAlphaFunc(TestFunction.Greater);
[/java]

Is this a general JME-problem or is there no other way of rendering translucent textures in combination with opaque ones on a single mesh?

A solution would be to generate a single mesh for all translucence faces and one for the opaque ones, but due to the sheer size of meshes we would have way too much drawcalls which would affect the FPS and the rendertime for meshes in a very negative way.

Kind regards

This is a general OpenGL Transparency problem. If you draw one pixel at z=100 that is semitransparent then this will block any pixels drawn after at z=100+.

I don’t understand the “way too much draw calls” issue since at best it would double the draw calls. Maybe you are already draw call limited. First it sounded like there was only one object and now you make it sound like there are actually lots of them.

@h1ghst0r3y said: Is this a general JME-problem or is there no other way of rendering translucent textures in combination with opaque ones on a single mesh?
That's a general issue with transparency, not only a JME issue. The thing is geometry are sorted as a whole, faces are not sorted with each other in the same mesh. so you may have inconsistency when for example a transparent object is inside another transparent object or that 2 transparent faces are intersecting with each other.

You’d better split your mesh in several for this particular issue, because there is no right solution for this keeping one mesh. Except maybe this http://hub.jmonkeyengine.org/forum/topic/multi-layer-alpha-blending-order-independent-transparency/ but it’s kind of difficult to achieve.

Guess we will have to look into splitting it up into 2 meshes each … but thanks for your response.

1 Like

I have one more question. Why can I see the faces behind a face which is transparent (value <= threshold) if I discard pixels in the shader? Is there a way so keep informations from discarded pixels?

@alrik said: I have one more question. Why can I see the faces behind a face which is transparent (value <= threshold) if I discard pixels in the shader? Is there a way so keep informations from discarded pixels?

Discarded means those pixels aren’t drawn. So nothing goes into the color buffer… but more importantly, nothing goes into the Z-buffer.

…it’s all about the z buffer.