Grass rendering

Hi, i am trying to test grass rendering in JME, but i find a small problem. For first, i test grass which is made with 3 quad in star formation (my english is so bad  :smiley: ). Quads use a blend state for transparency.



From front view (front face) everything are perfect. Quads are transparent - no problem. But in back view (back face) the transparency of quads is like from front view - so one quads repaint other. It like the back face transparency of quad is same as front face transparency.



See images for understanding.



Font good view:





Back ugly view:





Quad creation:


Quad grass1 = new Quad("Grass quad", 30f, 30f);
      grass1.setLocalTranslation(50f, terrain.getHeight(50f, 50f)
            + (grass1.getHeight() / 2), 50f);

      TextureState ts = display.getRenderer().createTextureState();
      ts.setEnabled(true);

      Texture t0 = TextureManager.loadTexture(Game.class.getClassLoader()
            .getResource("media/textures/grass.png"),
            MinificationFilter.Trilinear, MagnificationFilter.Bilinear);

      ts.setTexture(t0, 0);

      grass1.setRenderState(ts);

      BlendState bs = display.getRenderer().createBlendState();
      bs.setBlendEnabled(true);
      bs.setSourceFunctionAlpha(BlendState.SourceFunction.SourceAlpha);
      bs.setDestinationFunctionAlpha(BlendState.DestinationFunction.One);
      bs.setBlendEquation(BlendState.BlendEquation.Add);
      bs.setTestEnabled(true);
      bs.setEnabled(true);

      grass1.setRenderState(bs);
      
      grass1.setRenderQueueMode(Renderer.QUEUE_TRANSPARENT);
      grass1.updateRenderState();

Your problem is depth sorting, you should find something about alpha killing on the forum search.

Try this:


        BlendState as = DisplaySystem.getDisplaySystem().getRenderer().createBlendState();
        as.setBlendEnabled(false);
        as.setTestEnabled(true);
        as.setTestFunction(BlendState.TestFunction.GreaterThan);
        as.setReference(0.5f);
        as.setEnabled(true);

Its like a charm. Thank yoy, it works perfect now. I will search something about alpha killing.



For others people, some information about problem:

http://www.opengl.org/wiki/index.php/Alpha_Blending#Alpha_blending_and_the_Z_buffer