Managing viewports as layers

So started to get a grip on jme3 as a whole but not sure how to approach the follow design.



So on a few other projects/engines have used blender for doing most of the GUI layout. In Unity even though there is one scenegraph there is the concept of layers that are used to filter the view so you can render once part of the scene at a time.



Basically I want to have separate viewports/layers that render their scenes but clear the depth info before rendering the next viewport. Using the mat.getAdditionalRenderState().setDepthTest(false); isn’t really what I want because I want each scene to do its own depth sort and comp onto the main viewport.



Any ideas on how to setup this up best/most efficient would be appreciated!

Use ViewPort.setClearDepth?

Yeah I tried using that in the update() loop and also where I initialized my viewport, both didn’t work. When would I need to call?

If it is set, the ViewPort is automatically cleared before it is being rendered.

You need to create several viewports and have that flag set on them

in initialize()

[java]

Camera threeDguiCam = cam.clone();

threeDguiViewport = renderManager.createMainView(“3D Gui Viewport”, threeDguiCam);

threeDguiViewport.attachScene(threeDguiNode);

threeDguiViewport.setClearDepth(true);

guiNode.detachAllChildren();

Box b = new Box(Vector3f.ZERO, 1, 1, 1);

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

// mat.getAdditionalRenderState().setDepthTest(false);

Geometry blueGeom = new Geometry(“BlueBox”, b);

Material blue = mat.clone();

blue.setColor(“Color”, ColorRGBA.Blue);

blueGeom.setMaterial(blue);

blueGeom.setLocalTranslation(new Vector3f(1f, 0, 0));

threeDguiNode.attachChild(blueGeom);

Geometry redGeom = new Geometry(“RedBox”, b);

Material red = mat.clone();

red.setColor(“Color”, ColorRGBA.Red);

redGeom.setMaterial(red);

redGeom.setLocalTranslation(new Vector3f(-1f, 0, 0.5f));

threeDguiNode.attachChild(redGeom);



Box plane = new Box(Vector3f.ZERO, 10f, 0.1f, 10f);

Geometry greenGeom = new Geometry(“BlueBox”, plane);

Material green = mat.clone();

green.setColor(“Color”, ColorRGBA.Green);

greenGeom.setMaterial(green);

rootNode.attachChild(greenGeom);

[/java]

this gives me http://img231.imageshack.us/img231/9564/depthsettrue.jpg

So I must be doing something very wrong cause from what you said the threeDguiNode should be in front of the green plane correct?

Where are you creating the other two viewports?

In that initialization I created the threeDguiViewport and attach the red and blue cube… the green plane is attached to the rootnode which is attached to the viewport handled by Application.java. the guiNode.detach was just to remove the debug text/fps on the lower left is also in Application.java

i made a better example by breaking out the test into a new SimpleApplication

[java]



import com.jme3.app.SimpleApplication;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.renderer.ViewPort;

import com.jme3.scene.Geometry;

import com.jme3.scene.Node;

import com.jme3.scene.shape.Box;



public class DepthSortTest extends SimpleApplication

{

private Node otherMainNode;

private Node threeDguiNode;



@Override

public void simpleUpdate(float tpf)

{

super.simpleUpdate(tpf);



otherMainNode.updateLogicalState(tpf);

threeDguiNode.updateLogicalState(tpf);



otherMainNode.updateGeometricState();

threeDguiNode.updateGeometricState();

}



@Override

public void simpleInitApp()

{

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



// initialize the ‘root’ nodes

otherMainNode = new Node(“Other Root Node”);

threeDguiNode = new Node(“3D Gui Node”);



// create and init the viewports

ViewPort otherMainViewport = renderManager.createMainView(“Altenative Viewport”, cam);

otherMainViewport.attachScene(otherMainNode);



ViewPort threeDguiViewport = renderManager.createMainView(“3D Gui Viewport”, cam.clone());

threeDguiViewport.setClearDepth(true);

threeDguiViewport.attachScene(threeDguiNode);



// create some geo

Box b = new Box(Vector3f.ZERO, 1, 1, 1);

Geometry blueGeom = new Geometry(“BlueBox”, b);

Material blue = unshaded.clone();

blue.setColor(“Color”, ColorRGBA.Blue);

blueGeom.setMaterial(blue);

blueGeom.setLocalTranslation(new Vector3f(1f, 0, 0));

Geometry redGeom = new Geometry(“RedBox”, b);

Material red = unshaded.clone();

red.setColor(“Color”, ColorRGBA.Red);

redGeom.setMaterial(red);

redGeom.setLocalTranslation(new Vector3f(-1f, 0, 0.5f));

Box plane = new Box(Vector3f.ZERO, 8f, 0.1f, 8f);

Geometry greenGeom = new Geometry(“GreenBox”, plane);

Material green = unshaded.clone();

green.setColor(“Color”, ColorRGBA.Green);

greenGeom.setMaterial(green);



// attach the geo to the ‘root’ nodes

threeDguiNode.attachChild(blueGeom);

threeDguiNode.attachChild(redGeom);

otherMainNode.attachChild(greenGeom);



// move the camera

cam.setLocation(new Vector3f(0f, 1f, 5f));

cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);

}



public static void main(String[] args)

{

DepthSortTest app = new DepthSortTest();

app.start();

}

}

[/java]



I’m sure its just a small thing.

Hm apparently there’s was a bug in the setDepthClear() method and similar ones.

I have fixed it in SVN now.

Without the fix, you have to call setClearFlags instead to make it work

Confirmed! Hurray!