View Full Version : Implement Water Ripple effect

caravanio

11-30-2014, 02:49 PM

I am doing my master's thesis and have chosen to implement water ripple effect. The best example of what I am trying to achieve is: madebyevan.com/webgl-water/

This demo encompasses several effects as denoted by the author:

Raytraced reflections and refractions

Analytic ambient occlusion

Heightfield water simulation

Soft shadows

Caustics

Currently, I want to implement the "Heightfield water simulation". I've found lots of articles and discussions (cannot post them due to a restriction on the number of links that a forum topic could contain) but cannot see the most right way to implement it. Saw several physics formulas - model the water surface as an elastic membrane with low stiffness or use Navier-Stokes еquations. Most of the tutorials speak how to simulate arbitrarily moving water but not water ripples.

Could you point me to the most correct maths/physics and OpenGL practices for simulating water ripples?

Agent D

12-01-2014, 02:14 AM

Did you already take a look at this (http://www.roxlu.com/downloads/scholar/001.fluid.height_field_simulation.pdf)? It discusses a simple pseudo code implementation of height map based water surfaces.

caravanio

12-02-2014, 10:17 AM

Yes, it was the first thing to read. But as you start reading it you find the following:

Initialize u[i,j] with interesting function

First question: what is this? Is it to fill a map with arbitrary height values, so that I have initial non-calm water which I later on modify by:

v[i,j] +=(u[i-1,j] + u[i+1,j] + u[i,j-1] + u[i,j+1])/4 – u[i,j]

Which means - add the average sum of all surrounding pixels, or vertices, and then subtract that of the center one. So, they probably initialize the mesh vertices' heights using the "interesting function" and they later on modify the already initialized vertices' heights. This leads to simulating water, not simulating water ripple. That is why I wrote:

Most of the tutorials speak how to simulate arbitrarily moving water but not water ripples.

So, this and another several tutorials were the first I saw. Then read someone speaking about sinc and sombrero functions, which are actually fading sin in 1D or 2D respectively. These are more close to what a math representation of a water ripple should look like. Here's a sample code of the heightfield simulation you gave link about: www.roxlu.com/2013/024/height-field-simulation-on-gpu

It cites the same tutorial you gave link about but older I think: www.cs.ubc.ca/~rbridson/fluidsimulation/GameFluids2007.pdf

Probably, I should better read the tutorial becase this video illustrates the given heightfield effect: www.youtube.com/watch?v=mh4ouyoMlL8

Agent D

12-02-2014, 02:38 PM

Initialize u[i,j] with interesting function

First question: what is this? Is it to fill a map with arbitrary height values, so that I have initial non-calm water which I later on modify by:

v[i,j] +=(u[i-1,j] + u[i+1,j] + u[i,j-1] + u[i,j+1])/4 – u[i,j]

Yes. You initialize the height field with initial wave crests to propagate. The formula you quoted is for updating the height map each frame what generates the wave effects.

Which means - add the average sum of all surrounding pixels, or vertices, and then subtract that of the center one. So, they probably initialize the mesh vertices' heights using the "interesting function" and they later on modify the already initialized vertices' heights. This leads to simulating water, not simulating water ripple. That is why I wrote:

Most of the tutorials speak how to simulate arbitrarily moving water but not water ripples.

This does simulate water rippling. You apply the above formula each frame for propagating the waves. The waves are implicit in the height map values.

So, this and another several tutorials were the first I saw. Then read someone speaking about sinc and sombrero functions, which are actually fading sin in 1D or 2D respectively. These are more close to what a math representation of a water ripple should look like. Here's a sample code of the heightfield simulation you gave link about: www.roxlu.com/2013/024/height-field-simulation-on-gpu (http://www.roxlu.com/2013/024/height-field-simulation-on-gpu)

It cites the same tutorial you gave link about but older I think: www.cs.ubc.ca/~rbridson/fluidsimulation/GameFluids2007.pdf (http://www.cs.ubc.ca/~rbridson/fluidsimulation/GameFluids2007.pdf)

Probably, I should better read the tutorial becase this video illustrates the given heightfield effect: www.youtube.com/watch?v=mh4ouyoMlL8 (http://www.youtube.com/watch?v=mh4ouyoMlL8)

The height map based approach does not explicitly deal with waves. Waves and ripples are an emergant propperty of the simulation. Those other things you mentioned

actually work with explicit matematically representations of waves.

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.