Colors of terrain disappear after updateRenderState (StandardGame, z-order)

Hey all, I'm new to jME so I may be missing something. I'm trying, just to get the hang of it, to create some terrain with random colors, culling of the back sides and proper z-sorting but I haven't managed to get these three things together in one scene…



When I call rootNode.updateRenderState() at the end (and the other update method), the colors of the terrainblock are not visible (I understand that this call propagates to the children but it somehow causes the colors to disappear). I also get proper z-sorting this way (but the terrain is just gray). When I don't call it, the colors are visible but z-sorting isn't ok: it draws the visible side of hills on top of nearer hills.



I'm using StandardGame and DebugGameState (MyDebugGameState is just a trivial modification which only increases the speed of the FPS inputhandler). DebugGameState does have a ZBufferState enabled so that can't be it.



Here's the code:


   public static void main(String[] args) {
      StandardGame game = new StandardGame("Example");
      game.start();
      
      DebugGameState state = new MyDebugGameState();

      Node rootNode = state.getRootNode();

      Camera camera = game.getCamera();
      camera.setLocation(new Vector3f(0, 50, 0));
      camera.update();
      
      CullState cs = game.getDisplay().getRenderer().createCullState();
       cs.setCullMode(CullState.CS_BACK);
       cs.setEnabled(true);
      
       MidPointHeightMap map = new MidPointHeightMap(128, 1.2f);
      TerrainBlock tb = new TerrainBlock("map"
            , map.getSize(), new Vector3f(1, 0.1f, 1)
            , map.getHeightMap(), new Vector3f(0, 0, -100)
            , false);
      
      tb.setModelBound(new BoundingBox());
      tb.updateModelBound();
      tb.setRandomColors();
      tb.setRenderState(cs);
      tb.updateRenderState();

      rootNode.attachChild(tb);
      //rootNode.updateGeometricState(0, true); // <--- when uncommented, colors of terrainblock are no longer visible
      //rootNode.updateRenderState();
      
      GameStateManager.getInstance().attachChild(state);
      state.setActive(true);
   }



I've tried rearranging the calls too but that didn't really work either (like the following - I'd set the colors after the update call of the rootNode has propagated to the child but the terrain is still gray)

      tb.setModelBound(new BoundingBox());
      tb.updateModelBound();
      
      rootNode.attachChild(tb);
      rootNode.updateGeometricState(0, true);
      rootNode.updateRenderState();
      
      tb.setRandomColors();
      tb.setRenderState(cs);
      tb.updateRenderState();
      
      GameStateManager.getInstance().attachChild(state);
      state.setActive(true);



Any comments would be appreciated :)

You need to set the Terrain colors using MaterialState and Light.

With the setColor() kind of function, you only set Vertex colors(?), but as soon as you have Light in a Scene, the color is computed with Material and Light.



If you disable the LightState in the DebugGamestate you can see the random colors:


DebugGameState state = new DebugGameState();
state.getLightState().setEnabled(false);

Ah yeah, that explains it - thanks! I'll fiddle a bit with the LightState and MaterialState (and other states) for more useable terrain (the random colors were just a way to test) :slight_smile: