Hi!
Here is very simple test case:
Two non-coinsiding planes (far enough from each other) of same size; Bottom one - GREEN, top one - BLUE.
Top plane is in the TransformGroup, and it is oscilating forward and backward (on Y axis) (you will see later why this is needed).
Two bug-like situations you can see here. To get better picture of what is happening please follow this steps:
- Run it as it is. Both planes are opaque. You will see NO PROBLEMS here, just note the actual colors - pure GREEN & BLUE.
- Find the line marked “play here”, and uncoment transparency for TOP plane (BLUE one) only. So we have opague GREEN plane and on top of it there is transparent BLUE plane. As you can see, no matter what is the translation of BLUE plane - it is always BLENDED with BACKGROUND in some reason and never with the opaque GREEN plane!!! This is WRONG.
- Now, uncoment transparency for GREEN plane as well. So we have two transparent planes. If you run the test you will see that depending on the translation of BLUE plane we are getting either RIGHT or WRONG blending efect - this is the most strange case for me…
Here is the code (also, screenshots attached).
import java.awt.Color;
import javax.swing.JFrame;
import javax.vecmath.Color3f;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;
import org.xith3d.test.util.TestUtils;
import com.xith3d.render.CanvasPeer;
import com.xith3d.render.jsr231.RenderPeerImpl;
import com.xith3d.scenegraph.Appearance;
import com.xith3d.scenegraph.BranchGroup;
import com.xith3d.scenegraph.Canvas3D;
import com.xith3d.scenegraph.ColoringAttributes;
import com.xith3d.scenegraph.Locale;
import com.xith3d.scenegraph.Shape3D;
import com.xith3d.scenegraph.Transform3D;
import com.xith3d.scenegraph.TransformGroup;
import com.xith3d.scenegraph.TransparencyAttributes;
import com.xith3d.scenegraph.View;
import com.xith3d.scenegraph.VirtualUniverse;
public class Bleeding_BlendingTest {
public Bleeding_BlendingTest() {
JFrame frame = new JFrame("Bleeding BlendingTest");
frame.setSize(500, 500);
//======= setting up Universe ===============
VirtualUniverse My_Universe = new VirtualUniverse();
Locale locale = new Locale();
My_Universe.addLocale(locale);
BranchGroup scRootBG = new BranchGroup();
locale.addBranchGraph(scRootBG);
//------------------------------
CanvasPeer canvasPeer = new RenderPeerImpl().makeCanvas(
frame.getContentPane(), 0, 0, 32, false);
Canvas3D scrCanvas = new Canvas3D();
scrCanvas.set3DPeer(canvasPeer);
//------------------------------
View scView = new View();
scView.addCanvas3D(scrCanvas);
My_Universe.addView(scView);
//------------------------------
Appearance plane_BOTTOM_GREEN = new Appearance();
plane_BOTTOM_GREEN.setColoringAttributes(
new ColoringAttributes(new Color3f(Color.GREEN),0));
Appearance plane_TOP_BLUE = new Appearance();
plane_TOP_BLUE.setColoringAttributes(new ColoringAttributes(new Color3f(Color.BLUE),0));
TransparencyAttributes ta = new TransparencyAttributes(
TransparencyAttributes.BLENDED, 0.7f);
//-------------------------------------------
Shape3D planeBOTTOM_GREEN = new Shape3D(TestUtils.
createPlane(0, 0, -2, 5, 5), plane_BOTTOM_GREEN);
Shape3D planeTOP_BLUE = new Shape3D(TestUtils.
createPlane(1, 0, -1, 5, 5), plane_TOP_BLUE);
//__________________________________________________
//*************** play here ************************
//plane_BOTTOM_GREEN.setTransparencyAttributes(ta);
//plane_TOP_BLUE.setTransparencyAttributes(ta);
//**************************************************
TransformGroup translateY_TG = new TransformGroup();
translateY_TG.addChild(planeTOP_BLUE);
scRootBG.addChild(planeBOTTOM_GREEN);
scRootBG.addChild(translateY_TG);
//======= running =============================
Point3f camL = new Point3f(0,-4f,3f);
Point3f lookAtV = new Point3f();
Vector3f upV = new Vector3f(0,0,1);
scView.getTransform().lookAt(camL,lookAtV,upV);
float transalteY = 0;
float speed = 0.05f;
frame.setVisible(true);
long currTime = System.currentTimeMillis();
long lastTime = currTime;
while (frame.isVisible()) {
scView.renderOnce();
//--------------------
currTime = System.currentTimeMillis();
if (currTime - lastTime > 30) {
lastTime = currTime;
transalteY += speed;
Transform3D t3d = new Transform3D();
t3d.setTranslation(new Vector3f(0,transalteY,0));
translateY_TG.setTransform(t3d);
if (Math.abs(transalteY) > 3f) speed = -speed;
}
//--------------------
}
System.exit(0);
}
public static void main(String args[]) {
new Bleeding_BlendingTest();
}
}
Note, that the plane sizes, camera location, amplitude of oscilations etc - where purposly adjusted so that these problems poping up. In many other cases you will see no problems!!!
Anybody can advice on that?
Bohdan.