PNG transparency

Hi,

Im having a problem when using a PNG texture

i tried the smoke example in jmetest.effects.RenParticleEditor.java, it worked just fine, so i saved a .jme smoke file and imported it inside my little game… the PNG image edges are not being rendered correctly please take a look at the image below



and this is the code im using:




Node smoke = ModelLoader.loadModel("smoke.jme");
smoke.setLocalScale(0.01f);
smoke.setRenderQueueMode(Renderer.QUEUE_TRANSPARENT);
rootNode.attachChild(smoke);

smoke.updateRenderState();
smoke.updateGeometricState(0, false);



PS: the same problem happens when I use com.jmex.effects.LensFlare.java inside my game :S
what am I missing here??

Oh and btw ... Im using RenderPasses to draw my scene ...

Do you have a Blendstate correctly Set up in your scene?



edit: Empire Phoenix is right of course, its rather a zbuffer issue

It might be a zbuffer problem, try to add one wich does dissallow object from being dranw, cause even if it is transparent for you, for the zbuffer it is not, so it might not render the ones behind the transparent ones complelty, cause the zbuffer tells it not to do.

thanks guys for your replies …

I solved the LensFlare problem, it turned out to be color depth problem :slight_smile: … i set the color depth to 32 and its working now perfectly



as for the smoke things it's still doing the same …





Core-Dump: do i have to set a BlendState explicitly for my scene node?



i tried this (not sure if it make any sense hehe)



            smoke = ModelLoader.loadModel("smoke.jme");
            smoke.setLocalScale(0.01f);
            scene.attach(smoke);
            smoke.setRenderQueueMode(Renderer.QUEUE_TRANSPARENT);

            BlendState as1 = display.getRenderer().createBlendState();
            as1.setBlendEnabled(true);
            as1.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
            as1.setDestinationFunction(BlendState.DestinationFunction.One);
            as1.setTestEnabled(true);
            as1.setTestFunction(BlendState.TestFunction.GreaterThan);
            as1.setEnabled(true);
            smoke.setRenderState(as1);

            smoke.setLightCombineMode(Spatial.LightCombineMode.Off);
            smoke.setTextureCombineMode(TextureCombineMode.Replace);

            smoke.updateRenderState();
            smoke.updateGeometricState(0, false);



and still its not working out  :?

Empire Phoenix: what you said makes a lot of sense ... how can i modify the zbuffer to render what's behind transparent objects? is there any example or piece of code related to this?

Add this to your particle effect, and try out the different combinations untill it looks right



ZBufferState buf = display.getRenderer().createZBufferState();

            buf.setEnabled( true );

            buf.setFunction( ZBufferState.TestFunction.LessThanOrEqualTo );



There is also a function set writeable or so, when i remember right it was also on of the key points to the solution.




THANK YOU Empire Phoenix!  :D



this solved it!


            ZBufferState buf = display.getRenderer().createZBufferState();
            buf.setEnabled( true );
            buf.setFunction( ZBufferState.TestFunction.Always );
            smoke.setRenderState(buf);



What could i do without you?? hehe

oh wait…bad news …



now i can see the smoke from behind a wall (see the pic)

and i tried all the ZBufferState.TestFunction different possibilities



please take a look at the code


        CullState cs = display.getRenderer().createCullState();
        cs.setCullFace(CullState.Face.Back);
        scene.setRenderState(cs);

        ZBufferState buf = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
        buf.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);
        scene.setRenderState(buf);

            scene.updateRenderState();
            scene.updateGeometricState(0, false);

            ZBufferState buf = display.getRenderer().createZBufferState();
            buf.setEnabled( true );
            buf.setFunction( ZBufferState.TestFunction.NotEqualTo );
            smoke.setRenderState(buf);

            smoke.updateRenderState();
            smoke.updateGeometricState(0, false);

Ok the last issue was a render pass problem

i solved it by creating a new renderpass, adding the smoke effect to it and putting this pass at index 0



            RenderPass pass1 = new RenderPass();
            pass1.add(smoke);
            passManager.insert(pass1, 0);



I hope this thread can be useful to anyone who might run into the same problem :)