Projected water when Z axis (0,0,1) is up

I am currently trying to implement projected water in my application. I have looked at the TestProjectedWater example and that example works fine.



However, in the TestProjectedWater example, the camera is oriented such that Y (0,1,0) is the up vector.  Additionally, the water plane is is set to (0,1,0) (Y up)…  



In the application that we are adding visualization to the world is oriented such that Z is the up vector.  (So a person standing at 0,0,0 that is 6 units tall would have his head at 0,0,6).  As such, we need the water orientated such that Z is up.



The problem is that when we update the TestProjectedWater example to set the camera up to (0,0,1) in the lookAt method then (of course) the water is no longer oriented properly.  (It's sideways).  Setting the WaterPlane to:



waterEffectRenderPass.setWaterPlane(new Plane(new Vector3f(0.0f, 0.0f,1.0f), 0.0f));

doesn't seem to have any effect.



If we add a local rotation to the projectedGrid :



 Quaternion q=new Quaternion();

   q.fromAngleAxis(-FastMath.PI/2,new Vector3f(1,0,0));

   projectedGrid.setLocalRotation(q);




then the water is oriented properly but the water effects don't work properly (the water is a weird green color and fades in and out instead of having waves).



Any thoughts/advice/suggestions?





Thanks!






















you probably have to rewrite the shader the water is based on so that it does the reflections correct.

Thanks.  That's what I thought might be the case but I wanted to ask first (in case there was an easy solution that I was missing).



I assume that you mean that:


  1.  We contine to rotate the projectedGrid around the X-axis (as I showed in my initial post) to give it the proper orientation (Z up) and then:
  2. Update


com/jmex/effects/water/data/projectedwatershader
com/jmex/effects/water/data/projectedwatershader_refraction



as needed to work with Z=up.

Is this correct?  Do you think that I'll need to make any changes to either the WaterRenderPass or the ProjectedGrid?

Thanks again!

The "easiest" way might be to transform the geometry like you tried, but make sure the camera coords used are transformed by the inverse of the geometry rotation, to make it work like with y-up. Still probably have to modify the shader viewCoords handling though. Also be aware that the projected grid implementation is pretty incomplete and has been fully rewritten in Ardor3D.

MrCoder,



Thanks for the heads up about the projected grid implementation.  



I'm not entirely sure what you mean when you say that I should "make sure the camera coords used are transformed by the inverse of the geometry rotation".  Do you mean inside of the shader .vert and .frag code?  If you could elaborate a bit I would really appreciate it.



Thanks!

I don't have the jME code checked out so can't give you something fully down to the point. But basically in ProjectedGrid.update you would do something like:

getWorldTransform().applyInverse on the parts from the camera that is used in it's update. Fooling it into doing it's job like your camera were in it's space. This is what we do in our geometry clipmap terrain as well, to make it work with any transformation without adding lots of special code to handle different up vectors etc.

Apart from that the shader probably need to be modified to handle the wave fadeout correctly, since it's using the modelviewprojection directly etc.

Mrcoder:



Thank you very much.