Alpha States - how do I get them right?

This is really embarrassing: I can’t seem to get my AlphaState to do what I want! This is what it looks like:



Obviously not right, the depth-sorting (maybe?) for the alpha is not the way I would like it. But where’s my fault?

The water, and trees, are all in QUEUE_TRANSPARENT, and here’s how my AlphaState is set up:


                AlphaState as = DisplaySystem.getDisplaySystem().getRenderer().createAlphaState();
                as.setBlendEnabled(true);
                as.setSrcFunction(AlphaState.SB_SRC_ALPHA);
                as.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);
                as.setTestEnabled(true);
                as.setTestFunction(AlphaState.TF_GREATER);
                as.setEnabled(true);


BTW, I "ripped" the tree models off Fly's "Wolkenstein", which can be found right here on the forums. Originally, they are from www.loopix-project.com.#

yes it's a sorting issue…make sure you add the water before the trees…intersecting polygons in the treebranches is nothing you can do anything about unfortunately(except from splitting them in a 3d modeler)…



or, skip alphablending all together and go for alpha killing instead, that's the usual way of drawing trees(every game does it that way).



sample:


      alphaState.setBlendEnabled( false );
      alphaState.setTestEnabled( true );
      alphaState.setTestFunction(AlphaState.TF_GREATER);
      alphaState.setReference( 0.5f );
      alphaState.setEnabled( true );

Thanks a lot, I'll go for the alpha-killing approach - I figure otherwise I'd have to split the models into some separate TriMeshes, or at least Batches, instead? I'm scared of the fps-impact of that (I am thinking of the additional overhead for applying RenderStates in the drawing loop with TriMeshes… don't know anything about Batches yet, though).

no prob!



for things that don't need semi-transparent parts like windows etc, alphakill is the way to go. specially with trees that has lots of intersecting branches that would be a pain to split(for the modeler) and to sort(for the engine)…