I have been looking at SimpleWaterProcessor. While the example code works fine (where the water sits on the x-z plane), as soon as I try to rotate the water plane, the reflection goes nuts, as can be seen in the following image:
After looking into the code for a while, I found that inside the postQueue() method of the SimpleWaterProcessor class, the normal for the reflection camera is set as follows:
This explains why the reflection only works on the x-z plane, the normal is always set to the UNIT_Y vector.
If we recalculate the normal of the relfectionCam, then rotation would work properly, as follows:
// tempVec and calcVect are just temporary vector3f objects
tempVect.set( sceneCam.getLocation() ).addLocal( sceneCam.getUp() );
float planeDistance = plane.pseudoDistance( tempVect );
calcVect.set(plane.getNormal()).multLocal( planeDistance * 2.0f );
camReflectUp.set( tempVect.subtractLocal( calcVect ) ).subtractLocal( loc ).normalizeLocal().negateLocal();
// now set the up vector
Nothing is going nuts, you have to update the reflection plane when you move the spatial.
I did update the reflection plane. This is the code I used to rotate the waterPlane:
waterPlane.setLocalRotation(new Quaternion().fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_X));
waterProcessor.setPlane(new Plane(new Vector3f(0,0,1), 0));
The bug is with the SimpleWaterProcessor where the up vecotor of the reflectionCam is not set properly.
Oops, yeah, you’re right. Sorry… somehow I got distracted by the layout and ignored the code… Thanks, I will fix that.
Thanks! This will work great as a mirror
Ok, I added your fix pretty much as it was in svn revision 7147, thanks again.
Edit: Narf, the temp vars are already used in lookAt… have to create new ones… Wait for rev 7148
Yes, I always wanted to add a stripped down version of the shader just for mirrors, but you should be able to configure this already so that it will yield a good mirror, and the shader is really not very resource hungry as it is.