MaT
MaT

Reputation: 1606

2D Water top surface profile

I am trying to create the effect of the water surface thickness with a vertex-fragment shader.

I am in a 3D game environment but It's a scroll view so a "2D" view. Here is a good tutorial of creating such effect in real 2D using fragment shader.
But this can't be used in my case I think. For the moment I have only a plane were I apply refraction.

refraction

And I want to apply the water thickness effect. But I don't know how to do it.
I am not trying to create some water deformation/displacement using vertex for the moment, this is not the point.

I don't know if it's possible with a simple quad maybe should I use an object like this.

system

Here are some examples.

1 2 4 rayman

Thanks a lot !

[EDIT] Added Rayman water effect to have a better reference of the effect.

Upvotes: 1

Views: 2832

Answers (1)

datenwolf
datenwolf

Reputation: 162194

I am trying to create 2D Water effect with a vertex-fragment shader on a simple quad.

Your first misconception is thinking in 2D. What you see in your right picture is the interaction of light with a 2 surface in a 3D space. A simple quad will not suffice.

For water you need some surface displacement. You can either simulate this by solving some wave equation. Or you're using a fourier transform based approach. I suggest the second. Next you render your scene "regular" for everything above the water, then "murky and refracted" for everything below the water line. Render both to textures.

Then You render the water surface. When looking at the Air→Water Interface (i.e. from above) use a Fresnel reflection term, i.e. mix between top reflection and see through depending on the angle of incidence, and for a too small angle emulate Brewster reflection. For the Water→Air Interface (i.e. from below) you do similar, only you don't need the Fresnel term, but only the Brewster term, to account for total internal reflection.

Since you do all mixing in the fragment shader, you don't need blending, hence no need to sort drawing operations for the water depth.

Yes, rendering water is not trivial.

Upvotes: 2

Related Questions