2 Water Ripple Simulation

1 Water Ripple Generation

Without external forces, the water surface would stay calm. In order to have water ripples, vibration sources must be added to the water. The style of the water ripple is different with different ways of initialization. The most common way is to initialize a circle area to a specific value.

Simulation Algorithms of Water Wave Caused by Moving Body:

According to wave theory, when the oscillation of water ripples happens, 
the vibration would move along the negative z-direction and this vibration would spread to other directions in xy surface 
which means a negative impulse should be added to the mesh to cause the vibration.

A(x,y) is a round area with the center (x,y) and radius r. And use A(x,y) to initialize the mesh(Adding a negative impulse to the mesh, a positive one has no differences).If r=1 , then we just change one value of the node in the mesh. It is not bad to simulate the raindrop effect.

void init(int x, int y, float energy)
{
     nwater2[i][j] = energy;
}
2 Water Ripple Propagation

The article has the derivation process of the water ripple and it is not difficult.
In wave mechanics, small amplitude wave is a common and basic model to describe water wave. According to the small amplitude wave theory, the water height can be described as follow:

\eta = -\frac{\omega}{g}D\cdot coth(kh)\cdot sin(\omega t+k_{1}x+k_{2}z+\phi)

Generally, it is a complex sine function where parameters are not important here.

Let

\hat t = \frac{t_i+t_{i+1}}{2}
\Delta t = t_{i+1} -t_i (i\ge0)

This function can be deduced:

\eta(x,z,t_i) + \eta(x,z,t_{i+1}) = 2\eta(x,z,\hat t) cos\frac{\omega\Delta t}{2}

Ideally, water wave propagation is isotropic. And the height of a cell is affected by the heights of its adjacent cells in the previous moment.

\eta(x,z,\hat t)

Can be estimated by the heights of its neighbor points.
Suppose the mesh is like this:

mesh03.png
\eta(x,z,\hat t)= \frac{1}{r}\sum\limits_{j=1}^{r}\eta(x_j,z_j,t_i)

Here r is 4, let

2cos\frac{\omega\Delta t}{2} = 1

and the law of energy conservation should be taken into consideration.

If r is 8, then

cos\frac{\omega\Delta t}{2} = 1

The article only mentions when r=8.

Then the evolving formula is

\eta(x_k,z_k,t_{i+1}) = \frac{1}{4}\sum\limits_{j=1}^{4}\eta(x_j,z_j,t_i)- \eta(x_k,z_k,t_i)
3 Fading Process

Ideally, it has to follow the law of energy conservation. But in reality, the energy can have the loss. It the energy increased, then the effect of the water surface would be a mess. We just to multiple a variable which has a value between 0 and 1 to make the ripple fade away.

void spread()
{
    for(int i = 1;i < SIZE_WATER-1; i++)
    {
        for(int j = 1; j < SIZE_WATER-1; j++)
        {
            float y = nwater1[i-1][j] + nwater1[i+1][j] + nwater1[i][j-1] + nwater1[i][j+1];
            nwater2[i][j] = y * 0.5f - nwater2[i][j];
            nwater2[i][j] -= nwater2[i][j] / 32.0f;
        }
    }
    for(int i = 1;i < SIZE_WATER-1; i++)
    {
        for(int j = 1; j < SIZE_WATER-1; j++)
        {
            ntmp[i][j] = nwater1[i][j];
            nwater1[i][j] = nwater2[i][j];
            nwater2[i][j] = ntmp[i][j];
        }
    }
}

The water ripple effect:

mesh04.png
mesh05.png
mesh06.png
mesh07.png
mesh08.png
mesh09.png
mesh10.png

This algorithm is very awesome that its simple rules can easily handle the interaction of many waves and the obstacles. Adding a loss can simulate the fading process well.

留下评论

通过 WordPress.com 设计一个这样的站点
从这里开始