Water purification in opengl

I have absolutely no idea how to create water sources (ocean, lake, etc.). This, like every tutorial I come across, assumes that I have a basic knowledge of the topic, and therefore talks about the issue in an abstract way, but I don't.

My goal is to have elevation based water levels in my area.

I cannot find a good article to help me get started.

+3


source to share


1 answer


The question is pretty broad. I would decompose it into separate components and each of them worked in turn. Hopefully this helps narrow down what maybe, unfortunately I can only offer a discussion at a higher level that you are not immediately following.

Modeling waves (geometry and animation):

The procedural method will give a fixed height for position and time based on some noise function. The main idea is y = sin(x) + cos(z)

. Some more complex examples are given in GPUGems .

enter image description here

As in the picture, you can visualize the geometry meshing , the sample height ( y

) in the grid cells x,y

, and connect these points with triangles.

If you explicitly store all heights in a 2D array, you can create some pretty decent waves and ripples. The idea here is to update the elevation based on adjacent elevations using a few simple rules. For example, each height moves towards an average adjacent height, but also tends to an equilibrium height of zero. For this to work well, altitude must have a speed value in order to give water momentum.

I found some examples of such dynamic water here :

height_v[i][j] += ((height_west+ height_east + height_south + height_north)/4 - height[i][j]);
height_v[i][j] *= damping;
height[i][j] += height_v[i][j];

      

Rendering:

Using alpha transparency is a great first step for water. I would start here until your simulation works fine. The main effect you are looking for is reflection, so I'll just cover that. Next, you will want to scale the reflection value using the Fresnel factor. You may need an absorption effect (like fog) underwater based on distance (see Beer's Law in general exp(-distance * density)

). Understanding what you really want, you might want to render the lower parts of the water with refraction. But back to thinking ...



Probably the easiest way to render planar reflections is with stencil reflections, where you have to paint the scene from under the water and use the stencil buffer to only affect the pixels you previously painted the water in.

An example is here .

enter image description here

However, this method does not work when you have a bumpy surface and the reflections are disturbed.

Instead of displaying the underwater reflection directly on the screen, you can display it with a texture . Then you have color information to reflect when you make water. The tricky part is where in the texture is sampled after calculating the reflection vector.

An example is here .

enter image description here

This uses textures, but only for perfectly planar reflections.

See also: How do I draw a mirror mirroring something in OpenGL?

+12


source







All Articles