Transparency in QUEUE_ORTHO?

I'm implementing parallax scrolling, so I'm using QUEUE_ORTHO for the different layers. The layers in turn are a bunch of Quads. Now, the textures are RGBA and I have an AlphaState on each layer's Node whose childs are all those quads:


         as.setBlendEnabled(true);
         as.setSrcFunction(AlphaState.SB_SRC_ALPHA);
         as.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);
         node.setRenderState(as);



Now, I would like to sort on Z like in QUEUE_TRANSPARENT to make sure that the layers are rendered back to front. Or is there some other way to make them render correctly? I can, it seems, control the order in which layers are rendered by the order in which I attach the layer's Nodes to rootNode, but that doesn't seem very robust to me... or is it robust? Am I off track?

Thanks.

You cannot sort them like in transparent queue as they have no z-location. But you can use z-order and sort them yourself according to your needs.

You're not off track, it just wasn't designed to do what you have in mind.  Ortho queue was designed as a single plane, so sorting by depth would be meaningless as they are all z=0.  I would suggest writing a simple parser that sits in your update loop and does the distance sort, altering the zorder of the quads to match.  It should be pretty easy to do, and you could even make it more efficient and targetted to your game by controlling how often the sort is done or how much of the scene is reordered, etc. based on your game's needs.

You guys mean setZOrder in Spatial, right? So in QUEUE_ORTHO the Spatials will be rendered in order of increasing zOrder, correct? If that is the case, it's perfect…

Um, I can't remember if it is increasing or decreasing at the moment. ://  But yep.  :slight_smile:

are you sure it's not just camera.setParallelProjection you really need?

Renanse & irrisor: I can’t seem to get zOrder working. I use

parallaxlayer.getNode().setZOrder(int)

but it doesn’t make any difference, the only thing that makes a difference is the order in which I attach the nodes to rootNode. I’ve looked at the RenderQueue code (including the ortho comparator) and it should be working. Well, my experience with jME is limited, but still… Any ideas?



MrCoder: Please elaborate. What I want is parallax scrolling like it was back in the good ol’ days (but with alpha blending on the edges), and I haven’t been able to find any nice information on doing it on 3D hardware. I am more than happy to revise my methods. If I use parallel projection I won’t get 1-to-1 correlation on texels to openGL units, right?

Hmm, zOrder is being read from the individual batches and you are setting it in the Scenegraph.  We should probably do something like trickle down zorder set in the scenegraph to batches, but for now, you can use something like this recursive function:



   

    public void setZOrderOnBranch(Spatial branch, int zOrder) {
        branch.setZOrder(zOrder);
        if (branch instanceof Node) {
            Node n = (Node)branch;
            for (Spatial child : n.getChildren()) {
                setZOrderOnBranch(child, zOrder);
            }
        } else if (branch instanceof Geometry) {
            Geometry g = (Geometry)branch;
            for (int i = g.getBatchCount(); --i >= 0; ) {
                g.getBatch(i).setZOrder(zOrder);
            }
        }
    }


Thanks renanse, that did the trick. I did try to set it on the individual Spatials, not on the batches though…

Right, and batches are what needs to be set (which are under Spatials…)  HTH

so that's why i never managed to get zOrder working!  :-o

I've added a version of the above method to Spatial locally.  It will be in cvs with the next checkin.