Lecture, Dr. Lawlor
I claim simple wave dynamics requires
only three variables:
X variation in height drives X velocity:
steep cliff facing right will resolve itself by fluid flowing to
- 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
These three things should make
waves. Let's try this shader:
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 values.
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 much 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
float vel=0.2, ht=0.2; // constants
Initial conditions make a big
difference: if you have nonzero X and Y initial velocity, then
your waves will move at that velocity.
N.x+=vel*(L.z-R.z); // height gradient
N.z+=ht*(L.x-R.x+B.y-T.y); // velocity divergence
The "ht" and "vel" constants are
related: the ratio is the scale factor between initial height and