How to change far frustum only for particular Spatials?

Hi.

I need to render certain nodes of my scene graph with a different far clipping plane than the rest. I can think of two ways achieving this:

  1. Register two callbacks that get called right before and right after the nodes are rendered. Inside these callbacks I could change the far frustum parameter of the camera. Problem: I cannot find any hooks suitable for registration of such callbacks.
  2. Since all the nodes that I need to render with a different far clipping plane are queued to the sky-bucket, it would be even better to use a hook on the whole bucket. Again the problem here is, that I cannot find appropriate hooks.
  3. Alternatively it would be acceptable to disable frustum culling for the nodes concerned. However I have read that this is not possible.

Please note that I do not need depth test/write on the objects that I need to render with different far clipping plane, hence precision problems are out of discussion here.

Anyone who can help me on this?
Many thanks in advance.

(1) is not possible because objects are rendered later.

Frustum culling is not really your issue, I think. But if it is, then just add a post viewport and render the far nodes as a separate scene with its own camera.

Can you point me to any documentation on “post viewports”? This is a term I haven’t read before.

Actually, you could even do it with a second main viewport. I don’t have specific links. Javadoc is probably your friend here… or I think there are a few JME tests/examples that use it. createMainViewport() is what you are searching for. You can also read about managing a scene in a second viewport if you search for ViewPortAppState or something like that.

You might also search for the four or five forum threads on “I want to make a space game, how do I render the far planets” sorts of topics, which should cover similar ground.

Thanks.

Inspired by this thread I’ve found by searching for “space game far planets”, I’ve found a solution on myself. I remembered following rule from my computer graphics class:

In OpenGL fragments are not clipped (because behind the far clipping plane) if and only if -Wc < Xc < Wc AND -Wc < Yc < Wc AND -Wc < Zc < Wc is true, where Xc, Yc, Zc, Wc is the vector of clipping coordinates.

Hence all I had to do was to adjust the vertex shader like this:

vec4 clippingCoordinates = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);
clippingCoordinates.z = 0;
gl_Position = clippingCoordinates;

Hope this helps others having same problem.

Update: I just noticed that although I’m able to render objects behind the far clipping plane now, they are still being culled away at a larger distance. Obviously JMonkey is responsible of this, since the vertex count changes, based on whether they are visible or not. Any idea what might cause this? I’ve set CullHint.Never on the objects concerned.

Further proof that it’s JMonkey doing things it shouldn’t do: If I make the whole scene larger (not all the objects, just one object is enough) they are getting visible at the same distance they weren’t visible before!