Blending problems

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:

  1. Run it as it is. Both planes are opaque. You will see NO PROBLEMS here, just note the actual colors - pure GREEN & BLUE.
  2. 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.
  3. 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.

Anybody tried to run the test? I just encourage you to try it and confirm at least that you see the same as I see…

I don’t mind to track the problem down myself, the only is if anybody can help and advice whose problem is it?
OGL, JOGL or Xith’s? Since I have no experience with first two, if anybody can confirm that it definitely isn’t OGL/JOGL problem, then I can try dig it on Xith level… I already did tried actualy, but with no luck so far…

I ran the test just as you suggested and encountered the same problems. But so far I cannot say, if this is a Xith related problem. But I guess it is :(. When I stumble over somthing in the rendering code, that maybe is the reason, I’ll tell you.

Marvin

Thanks Marvin!

Yep, I thing it is Xith, but… I have little of suspisious as well, that it actually might be not… because strange thing is that it seems it have something to do with relative positions (coordinates), of the objects, camera, and objects (planes in this case) sizes… How this parameters can make diference for Xith? Strange…

This is simple test, but I can post as well other test, yet even more strange, when you changing camera position so that the picture on screen become just perfectly mirrored - and it became rendered improperly, you put camera back to original position - blahhh… everything perfect… where is Xith role in this? Have no idea… Very strange…

In other words imagine: You have two flat (all geom is on plane) shapes totaly symetrical in regards to (0,0,0). You have camera at (1, 0, 2) and looking at (0,0,0), picture is perfect as it should be, you just put you camera to (-1, 0, 2) still looking at (0,0,0) - everything looks totaly mess. And difference between to pictures should be just that they are ideally mirrored one to another… Driving you crazy, tell you… :-\

Bohdan.

hmm… no idea, sorry. :frowning:

When I’ve some spare time, I’ll have a closer look.

Interesting…

With this code


Shape3D planeBOTTOM_GREEN = new Shape3D(TestUtils.
                createPlane(0, 0, -1, 5, 5), plane_BOTTOM_GREEN);
        Shape3D planeTOP_BLUE =  new Shape3D(TestUtils.
                createPlane(1, 0, -2, 5, 5), plane_TOP_BLUE);

(and the remaining, of course), the top blue plane disappear when it’s near the observer.

I have no idea of what it can be but it’s related to my wrong Z-buffer tests.

Also, SCREEN_DOOR transparency doesn’t work.

Now that’s a really really interesting one.

In the view setup just replace (-4) with (4) and the transparency is wrong when the top blue plane is far from the observer : SO this is a point-of-view related issue. Could it have something to do with view culling ? Really strange ? Is it related to the bug we fixed with appearance not being changed when it’s outside from the view ?

[quote="<MagicSpark.org [ BlueSky ]>,post:8,topic:28353"]
Now that’s a really really interesting one.

In the view setup just replace (-4) with (4) and the transparency is wrong when the top blue plane is far from the observer : SO this is a point-of-view related issue. Could it have something to do with view culling ? Really strange ? Is it related to the bug we fixed with appearance not being changed when it’s outside from the view ?
[/quote]
Yep, that is the reason why I have little of suspection about jogl or ogl as well… that strange coordinate related staff… hmmm…
Btw, what you mean by view culling? Frustrum culling? If so, I tried without frustrum culling - seems nothing to do with that…
Anyhow frustrum culling can just cull the whole node, but will not cause visual efects anyhow.
Just wondering, if anybody familiar with jogl can reproduce that really simple test case with jogl only, just to confirm on wich side the problem resides…
It will help a lot in localization of the problem, then we can concentrate on killing that bug in Xith, if it appeared to be Xith problem.