1 波源產(chǎn)生 Water Ripple Generation
水面不會憑空振動,需要給水面施加一個振動波源。
論文里面沒有提如何產(chǎn)生波源,不同初始化波源的方式得到的波形也不一樣。常見的一種方法是圓形初始化。
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.
引用引用運(yùn)行體的水波生成與擴(kuò)散模擬算法的話:
Simulation Algorithms of Water Wave Caused by Moving Body:
水波初始振蕩發(fā)生時 ,其原動力是負(fù)向的 ,振動向負(fù)方向偏移。
振蕩發(fā)生后 ,振動立即會向水面的各個方向傳遞 ,
其傳播到的水域內(nèi)各點(diǎn)的水紋高度應(yīng)為該點(diǎn)在上一時刻的振動狀態(tài)與其相鄰點(diǎn)在更前一時刻的原振動狀態(tài)的綜合效應(yīng)。
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.
對以為中心
為半徑的區(qū)域范圍
進(jìn)行初始化(施加一個負(fù)的尖脈沖)實際上正的也沒什么區(qū)別。。
時就是一個點(diǎn),模擬雨點(diǎn)效果不錯。簡化版:
is a round area with the center
and the radius
. And use
to initialize the mesh(Adding a negative impulse to the mesh, a positive one has no differences).
If , 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 水波演變公式推導(dǎo) Water Ripple Propagation
文章給出了水波演變公式的推導(dǎo)過程,推導(dǎo)過程不是很復(fù)雜。
這里簡單介紹一下。
波浪力學(xué)里面用小波變換來描述施加擾動后自由面的高度:
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:
本質(zhì)上是一個帶一堆系數(shù)的sin函數(shù),參數(shù)意義在這里不是很重要。
Generally, it is a complex sine function where parameters are not important here.
令
Let
,
利用三角函數(shù)和差化積公式可以推出
This function can be deduced:
由于水波自身特點(diǎn),就是每個點(diǎn)的高度都受周圍的點(diǎn)的高度影響。理想的波是各向同性傳播的,假設(shè)這里的水波也是理想情況。
那么這個可以用周圍的點(diǎn)的高度來估計。
假設(shè)網(wǎng)格長這樣:
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.
Then can be estimated by the heights of its neighbor points.
Suppose the mesh is like this:
這里是4,那么令
,這里需要注意能量守恒。如果
是8,需令
。論文中只提了
的情況。
Here, is 4,let
, and the law of energy conservation should be taken into consideration. If
is 8,then
. The article only mentions when
.
所以演變公式可以變?yōu)?br>
Then the evolving formula is
3 水波消散 Fading Process
公式理想情況下能量符合能量守恒定律的,但現(xiàn)實情況能量會減小但不能增加。如果能量增加,水面效果會爆炸。為了使水波消散,我們對得到的乘上一個絕對值小于1的系數(shù)即可。
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:
這個算法厲害之處在于他這個簡單規(guī)則可以有效的處理多個波互相干擾和障礙物反射。增加了能量耗散系數(shù)對水波的消退也能很好的模擬。
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.