Water reflection edges artefacts (GLSL)

Started by
21 comments, last by jfdegbo 17 years, 9 months ago
Guess what?
In DX9 mode, Source uses a shader which reduces water refraction in areas with shallow water.
This way you could both smooth out the shorelines AND get rid of the artefacts!
The simplest way to implement something like that is using a texture.
Calculate the points where your water plane intersects the shores.
Save these points.
These points make up your water surface.
Now make a refraction amount texture, like this one: http://img291.imageshack.us/img291/3829/refractionmapvq6.png
Stretch it over your water surface using texture coordinates.
The (grayscale) texture contains values between 0 and 256 exclusive. (Black to white.)
For every fragment of your water surface, multiply the default refraction amount for the current fragment by the value in the texture (put it in range of 0 to 1 first).
This should do the trick nicely!

This is, of course, all in theory.
It shouldn't require DX9 and should be very cheap.
Advertisement
Great !
I've just finished implemnting a new algorithm... works quite good !
Many many thanks mrbig ! I owe you one :-)

For those who are interested, I did not implement the method but got mine while reading mrbig's post.

I just kept the idea of fading the waves away on the shores. In fact computing intersections in real time and for each frame (I want the system to be fully flexible and dynamic) would have been too expensive (not speaking of the texture generation).

I just do one extra pass before the refraction, giving the fragment a shade of grey, the deeper, the lighter. I then redraw the real refracted scene, using the shaded Y-depth to attenuate the waves... Here is a vid showing it working, on the end you can see it is dyunamic with the object dynamically spawned on the water. This system has limitations to a certain type of shores pointing upwards, but as the advantage to be very, very fast.

Here is the vid : XViD codec.
_____My little engine : I.E.
No, no, no, you got it all wrong!
You only need to calculate the intersection points and texture coordinates once.

[EDIT]

Oh, flexible and dynamic...
But why would you need to change your water surface in real time?

[EDIT]

You don't need to generate the texture at all.
You can just use the one in my previous post.
to reflect some people, animated skinned meshes for instance
_____My little engine : I.E.
But the intersection points and texture coordinates don't change. Nor does the refraction amount texture.
yes is does, at the actor's intersection with the water plane
_____My little engine : I.E.
I found a partial solution to this problem. I took the heightmap of the terrain and scaled it so that it was 0 at the shore, and 1 just a little further out. Then I used this to scale down the distortion of both the reflection and refraction near the shores, which gets rid of the glitch in most cases. You can also use this factor to introduce more refraction near the shores, like mrbig said. That way you can get rid of the hard shorelines. Here are the results:

hard edges
soft edges

If you want to see it in action try downloading my aQuaterra demo (click on the downloads tab)

I say partial solution because the way I did it only works on the terrain. But it could easily be extended to the rest of the scene, and the fadeout factor could be computed as a pre-process, making the performance optimal (a texture lookup and a multiply)

Also you might find this thread helpful.
Quote:Original post by jfdegbo
yes is does, at the actor's intersection with the water plane


Ooooh, you're right!

P.S:
Wow, James, that looks good! :D
The only problem is, your method is brilliant for terrains, but it won't work for dynamic models.

P.P.S:
Jfdegbo, how do you calculate the Y-depth?
thanks for all this information james...

mrbig : i just interpolated it from vertex to fragments... but in viewspace. Maybe i'll figure out another solution, but as the shader is extremely simple and fast, it is not on the top of the todo list.
_____My little engine : I.E.
I think I'm gonna spend some time today trying to figure a robust solution.

This topic is closed to new replies.

Advertisement