Render two passes? How can I do this in JME3?

Well, I need to render a scene twice, due to zbuffer precision problems that are not other solvable.

My basic idea is:

render FarawayObject(including Skybox)

render NearObjects

in Jme2 I know how to do this, but how can I do this in jme3?

I tried:

cam.setFrustumPerspective(90, 4f/3f, 1000, 400000);
cam.setFrustumPerspective(90, 4f/3f, 0.1f, 5000);

This does now work, It seems like the renderManager is alos responsible for clearing.

Then I tried:

seccam = new Camera(cam.getWidth(), cam.getHeight());
      seccam.setFrustumPerspective(90, 4f/3f, 1000, 400000);
      fardistance = new ViewPort("FarRenderer", seccam);
      cam.setFrustumPerspective(90, 4f/3f, 0.1f, 5000);

My idea was that the fardistance one clears, renders, then the normal renders without clearing, however this does not work as well, Anyone any ideas?

yep the render manager clears the geometry list after rendering.

I added for SSAO a convenience method in the renderManager that render the scene without flushing lists.

check renderViewPortQueues in render manager

takes 2 params the viewPort and a boolean. set the boolean to false to not flush the lists.

I think what you're looking for is to only clear the depth buffer, and not the color buffer. That would allow you to render your second scene without losing the rendering of the first.

I guess this option can be added.

Okay I commited this option.

You can call ViewPort.setClearColor() to disable color clearing and do two depth passes.

To do this with your code, it will have to change a bit:

seccam = new Camera(cam.getWidth(), cam.getHeight());
      seccam.setFrustumPerspective(90, 4f/3f, 1000, 400000);
      fardistance = renderManager.createPostView("FarRenderer", seccam);
           fardistance.setClearColor(false); // disable clearing the color buffer
      cam.setFrustumPerspective(90, 4f/3f, 0.1f, 5000);

ah , cool thanks,

just one question left, is there a way I can tell jme in wich order the viewports should be renderd, or is it only the way i add them?

First the "pre" viewports are rendered, then "main", and then "post".

If you add multiple viewports to one of the groups, then they are rendered in the order you add them.

Well it works except I have one problem.

It seems to me like the depthbuffer is not cleared wvenw hen set to, because objects that are relative to the frustrum nearer than others in the nearpass are, are not overdrawn.

      seccam = new Camera(cam.getWidth(), cam.getHeight());
      seccam.setFrustumPerspective(45f, 4f/3f, 0.1f, 1000);
      neardistance = renderManager.createMainView("NearRenderer", seccam);
      neardistance.setClearColor(false); //only keep the color results rest is unimportant for the next renderpass
      viewPort.setClearEnabled(true); //clear at beginning of the rendering
      cam.setFrustumPerspective(45f, 4f/3f, 1000, 10000000);

the seccam is set to same location/rotation before the render and after the update logical&updateGeometricstate

To make sure they really render in the way I want I tried this, but it does not help

renderManager.renderViewPort(this.viewPort, tpf);
renderManager.renderViewPort(neardistance, tpf);
renderManager.renderViewPort(this.guiViewPort, tpf);

Suprisingly the skybox is not renderd in front of the station, this might be because it is far away, to make sure it is only renderd in the farpass, and never in the near one.

Sphere sky = new Sphere(32, 32, 100000f);

The planet is "only" 20000 units from the cam's position

Not sure what's going on. Did you try to debug them separately? Like, try only rendering one of the viewports, does the issue still persist?