Shallow-water Wave Equation in 2D
Lecture, Dr. Lawlor
I claim simple wave dynamics requires three variables:
X variation in height drives X velocity: steep cliff facing right
will resolve itself by fluid flowing to the right.
- X velocity
- Y velocity
Y variation in height drives Y velocity the same way.
Velocity "divergence" drives height: if all velocities are
converging on one point, that point gets higher.
These three things should make waves. Let's try this
This is exactly the discrete form of the partial differential
equations at Wikipedia for the shallow
water wave equations.
Sadly, this is unstable--it explodes into weird zebra patterns.
There's a simple fix: blur things out, by averaging the neighbor
vec4 blur=0.25*(L+R+T+B); /* neighborhood average */
Instead, Wikipedia recommends pushing back against velocities: big
velocities will tend to damp out this way, but you need to add so
viscosity, nothing interesting happens. Piles of tar are not
known for their cool ripples.
Curiously, the unstable zebra patterns are almost prettier than the
waves we're trying to simulate!
Here's the full 2D version, with X and Y change:
Initial conditions make a big difference: if you have nonzero X and
initial velocity, then your waves will move at that velocity.
float HtChange=L.x-R.x+B.y-T.y; /* = divergence of velocity */
The "ht" and "vel" constants are related: the ratio is the scale
factor between initial height and velocity.
Try the WebGL