Transparency issues / alpha channel texture

Hi



I am using a PNG image that contains complete transparent areas

as well as translucent ones. This image is applied as texture to

a simple Quad which also gets an alpha state attached.



When rendering the scene I only get complete transparent areas

and opaque ones. The transition between the opaque and the transparent

areas remains opaque:







(original image: http://img147.imageshack.us/img147/8234/alphatestgq7.png)



I load the image into a texture:



Texture texture = TextureManager.loadTexture(

AsteroidFactory.class.getResource("…/…/resources/alphaTest.png"),

Texture.MM_LINEAR_LINEAR, Texture.FM_LINEAR, 0, false);





And I also use following alpha state:



AlphaState as = m_Display.getRenderer().createAlphaState();

as.setBlendEnabled(true);

as.setSrcFunction(AlphaState.SB_SRC_ALPHA);

as.setDstFunction(AlphaState.DB_ONE);

as.setTestEnabled(true);

as.setTestFunction(AlphaState.TF_GREATER);

as.setEnabled(true);





I fiddled around with other states (DB_ONE_MINUS etc.) but get no usable results.



(I assume that this problem has been solved over and over, but I could not find any

solution in this board or via any OpenGL Faqs)

Try reading this post: Make certain colors in texture transparent

For alpha blending, this is the correct state:


as.setSrcFunction(AlphaState.SB_SRC_ALPHA);
as.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);



If your texture does not have an alpha channel you can use additive blending instead:


as.setSrcFunction(AlphaState.SB_ONE);
as.setDstFunction(AlphaState.DB_ONE);


It makes a sort of ghostly effect depending on your model, so it might not be what you're looking for.

Thanks for pointing to the right direction.



This one works now:


as.setSrcFunction(AlphaState.SB_SRC_ALPHA);
as.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);



Also the correct render queue (TRANSPARENT) is needed AND disabling
the z Buffer at the node holding the quads.


But now the quad gets rendered above everything else, no matter if i change
the order in the render function:


m_Display.getRenderer().draw(m_BackgroundNode);
m_Display.getRenderer().draw(m_RootNode);



Has it to do something with the rendering queues?
anton said:

Also the correct render queue (TRANSPARENT) is needed AND disabling
the z Buffer at the node holding the quads.

I am pretty sure that it has to do with the disabled Z buffer.

You are not supposed to disable the depth test… you need to disable depth writing, while the test must still use the usual depth function LESS.

zbuf.setFunction(ZBufferState.CF_LESS);
zbuf.setWritable(false);

Thanks again.



I ditched the TRANSPARENT render queue stuff and adjusted the zBuffering.

Right now the scene looks like this:



      root

        |

 


  |          |
backdrop  gameboard
  |          |
quad        etc.


The backdrop node uses following zBuffer:


zs.setFunction(ZBufferState.CF_LESS);
zs.setWritable(false);
zs.setEnabled(true);



And the gameboard:


zs.setFunction(ZBufferState.CF_LEQUAL);
zs.setEnabled(true);



This now works like intended. Even stuff in the gameboard node
behind the backdrop shines through the transparent quads.

Is this now like JME is meant to be used?

All transparent models must be in the TRANSPARENT render queue, with depth writing set to off and an alpha blending state enabled. Other models need to be in the OPAQUE queue with depth writing set to on.

Momoko_Fan said:

All transparent models must be in the TRANSPARENT render queue, with depth writing set to off and an alpha blending state enabled. Other models need to be in the OPAQUE queue with depth writing set to on.


I thought so too, but then then transparent backdrop gets rendered above everything else.
If I render the queues explicitly before the root node gets rendered, then the backdrop
remains where it should be, but other transparent stuff (particles) get rendered behind the
backdrop again.

Perhaps this would be the right solution:

     gameState1          gameState2
         |                   |
     backdrop            gameboard
         |                   |
quad(transparency)   etc.(transparency)


Where gameState1 should be rendered completely before gameState2 and
the transparent stuff in the TRANSPARENT render queue.