Depth fade and refractive material problems

If I lay on the beach (In the engine) :smiley: , and look out over my ocean. Something interesting happens, the depth fade wich controls color and opacity completely messes up.
It seems like it takes one point on the surface, begins a depth check following the vector at wich im looking at it.
So for example a small wave 5cm high, just off shore where the water is really shallow, the depth check keeps tracing untill it hits something else… Wich most of the time is the ocean floor 100s of meters away.
This causes a wave at really shallow water, to be colored as if it was out on the sea at 100 meter depth. Same with its opacity, it will be 100% solid.
If I do the same but have 1 meter high waves just off the shore, I will look at a dark blue wall, even if the wave is really thin.

Also I feel like the depth fade should take into consideration the refractive value, for instance if the light bends and things appear shallower than what the depth check return. Not the acctual depth.

Is there any way to fix my first issue? And is there anyway to modify a depth fade function so that it offsets and traces to a point wich is closer to me than the one it hit?

For example I look at a point on the surface, the ior bends the angle of my view vector and color the pixel based on the view vector I put in?


Turned out I had used the wrong vector earlier.
I used the gerstner algorithm and picked the current world position subtracted the objects position and masked the blue value.
Then I translated the blue value to the 0-1 range and decided that when the offset is 0 the depth is calculated by a depth fade only.
But as the height value keeps getting higher (Higher up on the wave) I used the equation of an ellipse to calculate the width of the wave at that location.
Translated the width to an opacity value depending on the amount of particles in the water. So a thinner wave is more transparent than the large ones at the sea. And each wave is the most transparent near its top.
Also the depth fade is taken into account so that a thin wave at the beach is more transparent than an equally thin wave at the sea.
The water still looks a bit off, and this picture is using only one wave.

As of now im completely clueless, its the refraction that is ruining the water.
If I set the refractive value to 1.33 across the entire surface, all detail on the surface disappear and it becomes basically a mirror image of the sky.
Also there is a horizontal line a small distance from the top of the view that follows the camera when looking towards the horizon.

If I distance blend the refraction so that its 1.33 on shallow water and 1 on the deep water, I get a better result far away. But a bad result close up.
Setting a refractive value close to shore with not quite 1.33 seems to be better, since as far as I understand that value is based on clean water.
However I am still running into the issue as to what refraction to use far out on the ocean:

waterlike = an image of the sky from underneath the water is rendering on the surface.
Ior of 1 = a very reflective surface wich looks like color on a reflective plane rather than water.

Would be grateful of some input and ideas on how to improve the water :slight_smile: