Silk
Four thousand particles drifting through a noise field, and the one operation that makes it look like fluid instead of sand.
What it is
Particles released at random, following a velocity field, leaving trails. Press the button to switch how that field is built and watch the difference. One looks like fluid, the other looks like sand blowing into corners.
How it works
The field comes from fractal noise, four octaves of smoothed value noise, each half the amplitude and twice the frequency of the last.
The obvious way to turn that into a velocity is to sample it twice, one channel for x and another for y. It works, and it looks wrong. Particles pile up in some places and evacuate others, so within a few seconds the picture is a set of clumps with bald patches between them.
The fix is to treat the noise as a potential rather than as a velocity and take its curl. In
two dimensions that’s the vector perpendicular to its gradient, (∂ψ/∂y, −∂ψ/∂x).
The flow then runs along the potential’s contours instead of up and down them, and the field is divergence-free by construction. No sources, no sinks, nothing accumulates. That’s what fluid looks like.
What surprised me
How big the difference is when you actually measure it, rather than just observing that one looks nicer.
Root-mean-square divergence over the same patch, same noise, same octaves, measured across six different seeds:
- curl of a scalar field: 0.032 – 0.037
- two independent noise channels: 0.98 – 1.08
A factor of 28 to 32, and remarkably stable across seeds. Both numbers are on screen while it runs.
The residual 0.034 in the curl field isn’t real, it’s the error in my finite-difference derivatives. Analytically it’s exactly zero, because the divergence of a curl always is.
That’s a satisfying kind of test to be able to write. The look I was after has a precise mathematical name, so rather than tuning parameters until the clumping stopped I could assert the property that rules clumping out and get the look for free. The test demands the curl field’s divergence be at least ten times smaller. It’s thirty.
What I would do next
Advect the particles through a real fluid solve rather than a synthetic potential, and see whether the difference is still visible.