WaterrenderPass with ChaseCamera

I wanted to try out this wonderful water from Mr. Coder but having some trouble with (I THINK it’s the reason - I do not KNOW it) the ChaseCamera…

Don’t know how to explain so I show you a pic…

First pic shows you my terrain with a projectedgrid for my water surface with wthe waterrenderpass effect on it. Though there is no reflection and refraction everything seems fine. (Reflection and Refraction is working on other machines.)

But if I walk towards the water the water seems to “run away from me”…precisely from the ChaseCam (pic 2 and 3)

When I’m in the water but not under its surface, nearly up to the half of my screen the water is clipped away…

please help me Mr. Coder… (Miss Dakota??  :wink: )

I think it has something to do with the ChaseCamera or with the amount of units my cam keeps above the terrain… I don’t know

This is how I set up my waterrenderpass:

   private void setupWaterRenderPass() {
      Ground ground = new Ground("ground", 0.8f);

      Node reflectedNode = new Node("reflectNode");

      WaterRenderPass.fallbackMapTexture = "data/textures/water2.png";
      waterEffectRenderPass = new WaterRenderPass(cam, 1, true, true);
      waterEffectRenderPass.setWaterPlane(new Plane(new Vector3f(0.0f, 1.0f,
            0.0f), 0.0f));

      WaterHeightGenerator whg = new WaterHeightGenerator();

      ProjectedGrid projectedGrid = new ProjectedGrid("ProjectedGrid", cam,
            120, 70, 0.01f, whg);
      projectedGrid.setLocalTranslation(new Vector3f(0, 7f, 0));


...and the ChaseCamera:

   private void setupChaseCamera() {
      Vector3f targetOffset = new Vector3f();
      targetOffset.y = player.getLocalTranslation().y + 3;

      HashMap<String, Object> props = new HashMap<String, Object>();
      props.put(ThirdPersonMouseLook.PROP_MAXROLLOUT, "20");
      props.put(ThirdPersonMouseLook.PROP_MINROLLOUT, "15");
/*      props.put(ThirdPersonMouseLook.PROP_MINASCENT, "" + 10
            * FastMath.DEG_TO_RAD);
      props.put(ThirdPersonMouseLook.PROP_MAXASCENT, "" + 10
            * FastMath.DEG_TO_RAD);
      props.put(ChaseCamera.PROP_INITIALSPHERECOORDS, new Vector3f(0, 0,
            10 * FastMath.DEG_TO_RAD));*/
      props.put(ChaseCamera.PROP_TARGETOFFSET, targetOffset);
      props.put(ChaseCamera.PROP_DAMPINGK, "20");
      props.put(ChaseCamera.PROP_SPRINGK, "20");

      chaser = new ChaseCamera(cam, player, props);

Ok thanks in advance...


Could this be the near clipping plane on the camera?

I don't think so…

If it's the near clipping plane there would be nothing on that part of the screen, but there is something - the terrain…

We use chasecamera and water pass without this problem.  That said, to me it looks like grid generation is starting too far from your camera.  Perhaps it's the camera matrix you've setup?

What do you mean with the camera matrix?

Do you mean the frustum etc…?

I don't extend SimpleGame I wrote my own SetupGame based on BaseGame.

Here is where  I initialize my cam:

   protected final void initSystem() {
      // Die Einstellungen des Start Dialogs
      width = properties.getWidth();
      height = properties.getHeight();
      depth = properties.getDepth();
      freq = properties.getFreq();
      fullscreen = properties.getFullscreen();
        try {
            display = DisplaySystem.getDisplaySystem( properties.getRenderer() );
            display.setMinDepthBits( depthBits );
            display.setMinStencilBits( stencilBits );
            display.setMinAlphaBits( alphaBits );
            display.setMinSamples( samples );
            display.createWindow(width, height, depth, freq, fullscreen);
            cam = display.getRenderer().createCamera(width, height);
      } catch (JmeException e) {
         // Wenn beim Erstellen des Fensters ein Fehler auftritt, sofortige Beendung.
        // Hintergrund Schwarz
      // Kamera initialisieren
      cam.setFrustumPerspective(45.0f, (float)width / (float)height, 1, 200);
        /*Vector3f loc = new Vector3f( 0.0f, 0.0f, 25.0f );
        Vector3f left = new Vector3f( -1.0f, 0.0f, 0.0f );
        Vector3f up = new Vector3f( 0.0f, 1.0f, 0.0f );
        Vector3f dir = new Vector3f( 0.0f, 0f, -1.0f );
      // Move our camera to a correct place and orientation.
      cam.setFrame(loc, left, up, dir);
      // Signal that we've changed our camera's location/frustum.
      // Weise Camera diesem Renderer zu

        /** Create a basic input controller. */
        //FirstPersonHandler firstPersonHandler = new FirstPersonHandler( cam, 50,1 );
        //input = firstPersonHandler;
      timer = Timer.getTimer();
        /** Assign key P to action "toggle_pause". */
        KeyBindingManager.getKeyBindingManager().set( "toggle_pause", KeyInput.KEY_P );
        /** Assign key T to action "toggle_wire". */
        KeyBindingManager.getKeyBindingManager().set( "toggle_wire", KeyInput.KEY_T );
        /** Assign key L to action "toggle_lights". */
        KeyBindingManager.getKeyBindingManager().set( "toggle_lights", KeyInput.KEY_L );
        /** Assign key B to action "toggle_bounds". */
        KeyBindingManager.getKeyBindingManager().set( "toggle_bounds", KeyInput.KEY_B );
        KeyBindingManager.getKeyBindingManager().set( "screen_shot", KeyInput.KEY_F1 );
        KeyBindingManager.getKeyBindingManager().set( "exit", KeyInput.KEY_ESCAPE );

any ideas?

hmm…  does it matter if you are moving or not?  Some of the values the projectedgrid uses rely on the camera's projection matrix, which is only updated when apply() is called.  This would mean it could lag behind a frame if you are moving.

No difference in moving or not…

The character in Pic 3  isn't moving even if it looks like. The keyframe for the stopping animation is not set properly yet…

Which apply() do you mean?


This means there's no wokaround for that?

but I have to mention that I tried it with a quad and got the same result…

in that case, it's definitely your near-plane. you are using very "unique" scale on your stuff and hence a special near/far distances of 1 to 200. (instead of usual 1 to 20000 or so). should be fixed by setting the near distance to 0.01f or so…

Sorry it's not the same result for a quad…

with a quad everything seems fine except there are no waves floating around  :cry:

thanks anyway…

Neun, I had the same problem, let me see in my code and I'll inform you asap.

My chaser code :

        Vector3f targetOffset = new Vector3f();
        BoundingBox   playerBound = (BoundingBox) player.getDynamicPhysicsNode().getWorldBound();
        targetOffset.y = (playerBound).yExtent * 1.7f;
        HashMap<String, Object> props = new HashMap<String, Object>();
        props.put(ThirdPersonMouseLook.PROP_MAXROLLOUT, "3");
        props.put(ThirdPersonMouseLook.PROP_MINROLLOUT, "1");
        props.put(ThirdPersonMouseLook.PROP_MAXASCENT, "" + 30 * FastMath.DEG_TO_RAD);
        props.put(ChaseCamera.PROP_INITIALSPHERECOORDS, new Vector3f(5, 0, 30 * FastMath.DEG_TO_RAD));
        props.put(ChaseCamera.PROP_TARGETOFFSET, targetOffset);
        props.put(ChaseCamera.PROP_DAMPINGK, "4");
        props.put(ChaseCamera.PROP_SPRINGK, "9");
        chaser = new ChaseCamera(cam, player.getDynamicPhysicsNode(), props);       
        return chaser;

The code for WaterRenderPass :

                                waterRenderPass =  new WaterRenderPass (DisplaySystem.getDisplaySystem().getRenderer().getCamera(), 4, true, true);                      waterRenderPass.setClipBias( 0.5f );
      waterRenderPass.setWaterMaxAmplitude( 5.0f );
      waterRenderPass.setWaterPlane( new Plane( new Vector3f( 0.0f, 1.0f, 0.0f ), 0.0f ) );
      projectedGrid = new ProjectedGrid( "ProjectedGrid", DisplaySystem.getDisplaySystem().getRenderer().getCamera(), 100, 70, 0.01f, new WaterHeightGenerator() );
      waterRenderPass.setWaterEffectOnSpatial( projectedGrid );

Try this, if I rember more than nothing the point was the renderqueue and the cullmode, hope this helps you.

I was full of hope as I read your reply…but unfortunately that doesn't help  :?

Are you sure you had the same problem? If so please look into your code once more…

have you tryied with a near plane of .1f ?

Have you tryied not seting yourselve the frames for camera ?

Anyhow I don't see where you setted the zbuffer and the culling mode for rootNode.

Try disabling every kind of culling.

Try removing the localtransalation to waterPlane.

If you need remove the terrain to see if the defect disappear.

If think it should.

Well, at this point I'm trying to have the waterplane at certain height without this defect too.

Sorry that I didn't reply…

Setting the nearplane to a smaller value does not solve the problem. I'll try to remove the localtranslation and post the result.

Thank you


You're my hero!

Removing the localtranslation made it!

But there's another problem. If I translate the whole terrain, getHeight() returns the original value.

Ok I can solve this by translating the terrainPage by a static value and adding this to the result of every getHeight() in my whole code, but I don't think this is the right way to do it…

The need of translating is because of my raw terrain file. The lowest value in there is zero and thats the same height of the projectedGrid which I'm not allowed to translate.

if you translate the water, you need to update the waterPlane variable too.

waterEffectRenderPass.setWaterPlane( new Plane( new Vector3f( 0.0f, 1.0f, 0.0f ), 0.0f ) ); // first param = normal, second = translation through normal

As usual Mr Coder solve any problem :wink:

hehe, or, you could say that because i wrote the class, i actually created the problem  :smiley: