Basic filter effect for underwater objects

I would like to apply a basic blueish filter color to (part of) objects located under water, like in the image below (the base of the mushroom is blueish, compared to the top) :

I wonder how I could achieve this result with JME.

The solutions I could think about so far are :

  • use a closed transparent geometry for the water : does not work when the cam is inside the water since objects inside the water geometry do not get the filter effect. Moreover, that increases the number of triangles.
  • a post processing filter ? never tried that but how could I apply the filter to only the pixels located under the water surface ?
  • a shader ? same problem, how to know whether the pixel is above or under the water ?
  • a geometry “curtain” just in front of the cam ? Don’t know how to shape the curtain geometry so that only underwater objects get the effect (use the frustrum near plane ?).

Any clue would be appreciated :smiley:

How much do you care about that half in the water half out the water. It doesn’t really happen in real life (your eye is to a first approximation either fully underwater or fully above water).

I typically detect the camera going below the water line and flip from above water mode to below water mode. Like this:

Thanks for the share. Indeed, it was actually my first solution.

The problem is that it implies that the water surface must not be rendered when the cam is underwater. Otherwise, using the picture example above, the top of the mushroom will appear blueish above a visible water surface when the camera is half in half out.
And if I do not render the water surface, then the rendering is a bit strange when the player is e.g. in a waterfall (the player does not see the waterfall boundaries).

Additionnally, knowing that someone achieved this result is bitting me :smiley:

Yeah, with waterfalls I went with a different approach

Here the flowing surface always renders, both from inside and outside (as you say, it looks weird not to be able to see the edge of the waterfall from inside) and the blue overlay turns on and off as you go within the water. That does mean looking out from within a waterfall looks “double blue” but I think that looks correct, you expect it to be a bit darker being underwater and looking out than being outside the waterfall looking in.

One issue you may find is that being inside the waterfall looking out into another waterfall can cause issues (transparency being viewed through transparency is always a bit difficult). But because I have a world that the player can arrange however they like I’m particularly vulnerable to that, you may simply be able to arrange your waterfalls so that never happens.

“when the camera is half in half out.”

I must admit, I turn on the “underwater” effect very slightly early (if you look carefully you may notice it) to make sure there is never a half in half out situation, you are either fully in the water, or fully out of it


Well in theory you need this effect when crossing the surface boundary, right?
So that would mean the “view ray” collides with the surface plane.
That means your view direction (aka rotation/transform multiplied with UNIT_Z) intersects with a plane.
Actually you probably need the depth as well to know the length of the vector or something to stop the ray at the object.