Problem with reflection in WaterRenderPass

I have an issue with the reflection effect in WaterRenderPass.

My application is based on jmetest.effects.water.TestProjectedWater. I have added a "shoebox" floating in the water. The problem is that the reflection looks weird. The reflection plane is not in the water surface, but in a straight line where the water would be if there was no waves. Now using this effect it looks like my shoebox isn't floating, but skipping…



Watch the attached image. The arrow shows the largest difference, and the circle marks where the reflection is correct

I guess it would be very hard to create correct reflections with waves.

Maybe MrCoder or someone else who is familiar with reflections/shaders and such things could give some hints.

I wonder if the reflection texture needs to be updated…



Or if that's not it I wonder if you could 'fudge' something playing around with some (more) multi-texturing on the water…



(To get a 'true' reflection I think you would have to take into account the actual angle(s) of the water with respect to the viewing angle for each water 'area'. (and that could be some pretty costly calculating…))

how do get stuff to float on the water , always been curious about that

I don't think this issue can really be fixed… The water pass simply reflects the image across a plane, and so you get things like this. Obviously when using the simple-water (without 3D waves) this issue wouldn't exist. If the waves are made lower or on a smaller scale this would be less noticeable.

mcbeth said:


how do get stuff to float on the water , always been curious about that


Thats buoyancy physics, you can find some info online.. A simple way to do it is by sampling the heights on the area of your object and then apply a small force depending on how close the water height is at each point.

I wonder how hard it would be to 'fudge' what you need, maybe a separate rendering pass that just applies the 'boat' reflection texture (maybe pre-process to add some 'fuzzyness').  This texture could come from the boat itself I think, and could be 'applied' to a different trimesh with the same coordinates of the wave verts; then render that trimesh right on top of the water (alpha blended of course)…

Maybe a ProjectedTexture!

lol, that could work too (and probably easier ;))

But expensive for a simple sea!

It may be possible to use a separate object just for the reflection. I simply inverse the pitch, roll and height of the second object.  The main (first) object is added directly to the rootNode and the second object is added to the reflection node.

The problem is that I have to hide the second (inverted) object from above the surface

Can't you cull the object when rendering on the second pass and then uncull it again?

mcbeth said:

how do get stuff to float on the water , always been curious about that


A bit off topic but...

There is a number of methods some are more correct than other. I use a technique where i place four points in the water by x and z coordinate, and get the y coordinate from the same object which generate the waves.
pull out the height, pitch and roll of this plane and add them to my object

I have subclassed the WaterHeightGenerator and added a getLastTime() function to get the exact same time which the the wave is generated.

The call to the update function looks like this.

updateNodeInWater(ship, waves, shipPosition, shipX, shipZ, waves.getLastTime(), false);


ship is the Node, waves is the same object which is passed on to WaterRenderPass, shipX & shipZ is the width and length of the floating object and waves.getLastTime() is the function mentioned above.

If someone is interested in the code for my updateNodeInWater(...) I can post it in a different thread...
clovis said:

Can't you cull the object when rendering on the second pass and then uncull it again?

Probably. I'm not familiar whit culling so I'll read about that. I'm a newbie :D
buestad said:

mcbeth said:

how do get stuff to float on the water , always been curious about that


A bit off topic but...

There is a number of methods some are more correct than other. I use a technique where i place four points in the water by x and z coordinate, and get the y coordinate from the same object which generate the waves.
pull out the height, pitch and roll of this plane and add them to my object

I have subclassed the WaterHeightGenerator and added a getLastTime() function to get the exact same time which the the wave is generated.

The call to the update function looks like this.

updateNodeInWater(ship, waves, shipPosition, shipX, shipZ, waves.getLastTime(), false);


ship is the Node, waves is the same object which is passed on to WaterRenderPass, shipX & shipZ is the width and length of the floating object and waves.getLastTime() is the function mentioned above.

If someone is interested in the code for my updateNodeInWater(...) I can post it in a different thread...


yeah sorry about the OT :// just thought it looked good  :mrgreen:

would interested in seein the code........ if u do post it, usercode would be the area

If duplicated objects were the solution, it's recommended to be a lowpoly texturized model for the reflection.

Imagine a lot of ships on a war scene  :-o