How to depth sort polys

Hello all,

is there a tutorial showing how to have jME depth sort an arbitrary number of translucent polys?

thanks!

why would you want to do that? isn't the result the same, no matter how the transluent triangles are sorted?

jME uses a renderqueue to sort translucent meshes.  See TestRenderQueue

to answer HamsterofDeath's question: if you were dealing with just a couple of polys with the same alpha value then it wouldn't really matter, but when there are many polys and/or with different alpha values, it matters



thanks for the suggestion, renanse. I created a little demo to start playing around with the renderqueue for translucent polys.



I used 4 parallelpipeds assembled in a "plus"-like formation:

the trouble in your test is that the boundings used to sort your transparent objects are so close together that the sort order changes as you spin your camera.  Sort order used to be strictly distance based, but if you search on the forums, a case was made to use the view direction as part of the calcs.  This change is why it pops on rotating the camera.

The reason is that the two pass transparency uses your set zbufferstate for front faces.  Since you haven't set one explicitly, the one in SimplePassGame is used, which writes to the depth buffer.  This means at certain angles, depending on draw order, a front facing polygon might get drawn first before a polygon behind it, which results in 0 blend.  To fix this, you could setup a no-draw zbuffer state on your boxes (or their parent).  Perhaps the renderqueue should just force the "proper" zstate for front facing quads.

Thanks for your help, renanse. I am very new to jME. What do you mean exactly by "setup a no-draw zbuffer state"? If I could totally turn of the Z-buffer for this app, that might solve the problem.



Also, since this is a very specific application of jME, would I be better off by working with BaseGame, instead of SimpleGame? Since SimpleGame does a lot of initialization that may not be useful or required with this application?



Thanks again for addressing my questions!

here's an example of an appropriate no draw ZBufferState:


        ZBufferState zs = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
        zs.setEnabled(true);
        zs.setWritable(false);
        zs.setFunction(ZBufferState.CF_LEQUAL);



states start out enabled, so that call is not really needed, but for completeness... 

Hope that helps.