Terrain Culling

Hi,



why is my terrain culled so much that I can’t see it for more than 2 meter?



I read some threads about it but couldn’t figure out a solution for my terrain. I’m using StandardGame design and generate the terrain with ImageBasedTerrainGenerator.



its probably the cameras far frustum which is too near try to increase it and see if its better.

It is the camera far frustrum, like Core-Dump said. Also, you are standing on the edge of the terrain, too, if that is what you mean.  :smiley:

No it is not the farplane. At least it doesn't solve my problem.



It is damned importand that I can see the trerrain as I want to implement the interface to my terrain editor which can set objects dynamically.



I catched the camera from StandardGame and set the frustrum but I has NO EFFECT:


this.camera = coreGame.getCamera();
      camera.setFrustumPerspective(45.0f, (float)display.getWidth() / (float)display.getHeight(), 1.0f, 10000.0f);
      camera.setParallelProjection(false);
      camera.update();



Something else is causing this but what?. I don't understand what is cousing this problem?
mathias4u said:

What is done here?? Consider that the skybox is a node itself an the ZBuffer of the skybox node has ZBuffer disabled. BUT the skybox node is attached to the rootNode which has ZBuffer enabled. Is that the correct way and should this work :?



thats how it should work, i would try to break it down to a minimalistic example which reflects your set-up, and see if its still rendering wrong.

I need help for the culling problem.



I know the problem is not unique but first I would like to understand what the problem is.



The GamesState is built out of two classes:

-  the base class PlayState (extends GameState)

  • GamePlayState (extends PlayState)



    The terrain is built in GamePlayState and attached to the root node inherited by PlayState.




It has something to do with the Skybox because if I leave off the Skybox the terrain is painted.



Why? Has it something to do with:

  • CullState
  • updateGeometricState(0,true or false)
  • the order of attaching nodes to the rootNode
  • camera



    Also a  problem: the TerrainPage is not culled back, although i have set:


CullState cs=DisplaySystem.getDisplaySystem().getRenderer().createCullState();
         cs.setCullMode(CullState.CS_BACK);
         cs.setEnabled(true);
         tp.setRenderState(cs);   

mathias4u said:

It has something to do with the Skybox because if I leave off the Skybox the terrain is painted.

Your skybox is not set up correctly. You must render it before the rest of the scene, with ZBuffer writing disabled.
Have a look at jmetest.terrain.TestIsland.buildSkyBox() for a good example of how to init a skybox.

Tanks for the hint.



Well, I don't know how to render something (in this case the SkyBox) before the rest of the scene.



In my base class "PlayState extends GameState" I implemented the render method to draw the root node.

And the rootNode is initialitzed in the constructor with ZBuffer enabled.


r.draw(rootNode);



What is done here?? Consider that the skybox is a node itself an the ZBuffer of the skybox node has ZBuffer disabled. BUT the skybox node is attached to the rootNode which has ZBuffer enabled. Is that the correct way and should this work :?

The exmaple TestIsland uses the render queue execute command. I tested that but as a result the window is totally black. --> nothing is renedered at all. I don't get it, right : :lol:

That's how my situation looks like and I still have the same problem.

By the way is there an alternative to Sky Boxes? Maybe a Sphere? I would like also to have a sky

Thanks.

Testing the scene in a minimalistic version of the GameState is a good idea, I'll do that.



One thing that comes to my mind: I have the camera attached to the cameraNode. Might this influence the rendering?

I have found the solution!  :smiley:



I had to change the render queue of the node where the terrain is attached to:



nodeContainigTerrain.setRenderQueueMode(Renderer.QUEUE_OPAQUE);



My skybox wasn't set up incorrectly because in other examples it was working and I did it exactly as in TestIsland. My first focus was on the skybox to test every possible combination of render and cull states, but that has really nothing improved at all. The skybox was always painted correctly.

I'm happy to be able to continue my work and maybe I will be soon back with other problems  :wink:

Nevertheless I don't understand it why my other example works without invoking setRenderQueueMode(Renderer.QUEUE_OPAQUE); (it is just a single GameState instead of a Base class and a subclass).

Any Idea why I have to call the method on one hand and don't have to on the other hand?

I had this problem once, and it was because the bounding box of the terrain was not set properly, causing it to be culled when the bounding box was tested against the view frustrum.



try


terrain.setModelBound(new BoundingBox());
terrain.updateModelBound();
terrain.updateGeometricState(0,true);


after creating the terrain. 

Now I omit the skybox and use instead the Skydome as a GameState.



http://www.jmonkeyengine.com/wiki/doku.php?id=skydome