Two pass transparency rendering

Hello everybody,

I think there is a possible issue with the following code ( :

private void renderTransparentBucket() {
            for (int i = 0; i < transparentBucket.listSize; i++) {
                SceneElement obj = transparentBucket.list;

                if (twoPassTransparent && obj instanceof GeomBatch) {
                    GeomBatch batch = (GeomBatch)obj;
                    RenderState oldCullState = batch.states[RenderState.RS_CULL];
                    batch.states[RenderState.RS_CULL] = tranCull;
                    ZBufferState oldZState = (ZBufferState)batch.states[RenderState.RS_ZBUFFER];
                    batch.states[RenderState.RS_ZBUFFER] = tranZBuff;

                    // first render back-facing tris only
                    // then render front-facing tris only
                    batch.states[RenderState.RS_ZBUFFER] = oldZState;
                    batch.states[RenderState.RS_CULL] = oldCullState;
                } else {
                    // draw as usual
                obj.queueDistance = Float.NEGATIVE_INFINITY;

When rendering transparents meshes with the two pass transparency activated, if no front faces cover a back face, the ZBuffer is never updated because the "tranZBuff" disable the ZBuffer writing: the tranZBuff is initialized with setWritable(false); So, the objects that are drawn after can cover those faces even if their Z is greater.

Is the tranZBuff.setWritable(false); really useful ? What is it needed for ?

(Setting the tranZBuff.setWritable(); to true seems to solved my display problem...)

Thanks!  :)

hmm…  transparent objects should not write to the zbuffer (that would imply they block objects behind them?)  It really should not matter if things are being drawn in the right order though.  Can you describe your bug?

Hi renanse,

You're right!

I solved my problem: the background of my scene was rendered with a 2D quad in the ortho queue. Now I render the background in a render pass before my scene and everything is Ok.

Thanks for your help  ;)