I set blend mode to alpha and queue bucket to transparent but still I have a strange problem

Hi! I need help…



I have 3 planes (Quads) with a transparent texture on them.

I set blend mode to alpha and queue bucket to transparent but still I have a strange problem. The transparency works or not depending of the camera angle. I look up and the planes under the monkey’s face disappear (but i can see the background though it).







I look down and they return







This is the source code (assets are all from jme3 examples)



[java]



package alpha.main;



import com.jme3.app.SimpleApplication;

import com.jme3.material.Material;

import com.jme3.material.RenderState.BlendMode;

import com.jme3.material.RenderState.FaceCullMode;

import com.jme3.math.FastMath;

import com.jme3.math.Vector3f;

import com.jme3.renderer.queue.RenderQueue.Bucket;

import com.jme3.scene.Geometry;

import com.jme3.scene.Node;

import com.jme3.scene.Spatial;

import com.jme3.scene.shape.Quad;

import com.jme3.util.SkyFactory;



public class EjemploCuboSuelto3 extends SimpleApplication {



public static void main(String[] args) {

EjemploCuboSuelto3 app = new EjemploCuboSuelto3();

app.showSettings = false;

app.start();

}



@Override

public void simpleInitApp() {

flyCam.setMoveSpeed(20f);

cam.setLocation(new Vector3f(0, 20,0));

cam.setDirection(new Vector3f(1, 0, 0));







Material mat_stl = new Material(assetManager, “Common/MatDefs/Misc/SimpleTextured.j3md”);

mat_stl.setTexture(“m_ColorMap”, assetManager.loadTexture(“Textures/ColoredTex/Monkey.png”));

mat_stl.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); // activate transparency



Spatial plano= new Geometry(“box1”, new Quad(10,10));

plano.setMaterial(mat_stl);

plano.setLocalTranslation(6.0f,17.0f,6.0f);

plano.rotate(-FastMath.HALF_PI, 0, 0);

plano.setQueueBucket(Bucket.Transparent);

rootNode.attachChild(plano);



Spatial plano2= new Geometry(“Box2”, new Quad(10,10));

plano2.setMaterial(mat_stl);

plano2.setLocalTranslation(6.0f,18.0f,6.0f);

plano2.rotate(-FastMath.HALF_PI, 0, 0);

plano2.setQueueBucket(Bucket.Transparent);

rootNode.attachChild(plano2);



Spatial plano3= new Geometry(“Box3”, new Quad(10,10));

plano3.setMaterial(mat_stl);

plano3.setLocalTranslation(6.0f,19.0f,6.0f);

plano3.rotate(-FastMath.HALF_PI, 0, 0);

plano3.setQueueBucket(Bucket.Transparent);

rootNode.attachChild(plano3);



rootNode.attachChild(SkyFactory.createSky(assetManager, “Textures/Sky/Bright/BrightSky.dds”, false));



}



}



[/java]

this is what I do sofar for transparents



Transparent spatials:

mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off); // show back side too

mat.getAdditionalRenderState().setAlphaTest(true); // alpha on each face


geom.setQueueBucket(RenderQueue.Bucket.Transparent); // IMPORTANT



Do the italic lines help?

I don’t think there’s much to do that will help. Enabling alpha testing will fix it for completely transparent pixels, but you won’t have that “blend” effect anymore.



The issue is with the back-to-front sorting, it won’t always be correct.

You can read more about it here: http://www.opengl.org/wiki/Transparency_Sorting

The conclusion is that this is a problem that doesn’t really have a general solution, and so even engines like jME3 will fail to handle certain cases.

Well the only partly realtime solution has to wait till raytracers become usefull ^^



But kinda intresting, didn’t knew as well what kind of problems are associated with the transparent mode.

Damn it!. I was trying to create a fast voxel engine using transparent textures and i needed it to work. :frowning:

Thanks everybody. If someone comes up with a solution for this particular case I’m all ears.

I’, thinking… in my case lower quads allways have to be rendered before upper ones.



¿with JME3 can i manually specify the back-to-front sorting?

Creating a voxel engine probably would be more involved than simply stacking a bunch of quads together. You could do it maybe using geometry shaders or instancing.

When you specify Bucket.Transparent thats back-to-front sorting, but of course that doesn’t work in your case. What you want is a specific render order … But currently this is not possible.

Maybe i have a partial solution.

If i create the planes in the same geometry as a single object with “new Geometry()” constructor the planes seems to render in vertex order. Defining the faces from bottom to top seems to render the planes ok (only from one direction, backfaces culled). The material must be the same for the 3 planes (it is a single object) so if i need different textures in the planes is the shader job to render different textures in different heights.



Not useful to me because i need crossing planes with alpha but it’s a partial solution… :roll: