2D FLIP · particles + MAC grid

Heavy liquid, real splashes.

Tens of thousands of GPU particles slosh under gravity in the bottom of the page. Hover and the pool swells up after you; dip your cursor in and it is a solid paddle that parts the pool, drags a wake and throws droplets that fall back in.

How it works

How it works

The pool is 65,536 particles, and the particles are the liquid: they carry its shape and momentum, so splashes, sheets and droplets come for free and never smear. Every substep they are scattered onto a 327×184 staggered grid (plus 8 hidden columns at each side), the grid makes the flow incompressible, and the change is handed back to the particles. This is the FLIP/PIC method, running entirely in WebGL2 fragment shaders. What you see is not the particles but a surface rebuilt from them: a density field, cut at an iso level and mirrored like liquid chrome.

Pipeline (per frame)

pointer segment ─▶ paddle capsule (push-out radius R, solid cells to R − 3, swept per substep)
                   + a swell under a hovering cursor, a soft lid under the hero copy
                   1 substep per 60 Hz frame (+1 for a fast sweep with the paddle in the pool)
┌─ simulation, per substep ── 8 passes (7 when calm) ──────────────────────────────────────┐
│ [1] P2G       gl.POINTS 3 px × 65,536, blend ONE+ONE, 2 render targets                   │
│               acc   RGBA16F 344×185   Σw·u, Σw·v, Σw_u, Σw_v   tent weights computed     │
│               cell  RG16F   344×185   Σw_c, particles in cell   from gl_FragCoord        │
│ [2] FORCES    3 render targets in one pass                                               │
│               old   RGBA16F  normalised grid (the FLIP reference)                        │
│               vel   RGBA16F  + gravity, paddle grip, hover swell, copy lid, walls        │
│               p     RGBA32F  (warm-start p, A = 1/diagonal, B = rhs·A, ρ/ρ₀)             │
│                      fluid = holds a particle or ρ ≥ ¼ρ₀; diagonal = fluid               │
│                      neighbours + ghost-fluid 1/θ for air ones; air, solid = 0           │
│                      rhs = (∇·v − k·(ρ/ρ₀ − 1)) / Δt   (pull-in on interior cells only)  │
│ [2b] VISC ×2  only when Viscosity > 0: 4 Jacobi steps on (I − νΔt∇²) v = v₀, 2 per       │
│               pass (each fragment replays its cone in registers); the second pass        │
│               also writes p, from the diffused velocity                                  │
│ [3] PRESSURE ×4  RGBA32F 344×185  red-black SOR, ω = 1.82, 3 iterations per pass:        │
│               each fragment loads the 85 cells within 6 of it and replays the            │
│               sweeps in registers, p += ω(A·Σp_nb − B − p); 12 iterations, 9 when        │
│               calm, 6 in each half of a split frame, 24 after a pour                     │
│ [4] PROJECT   2 render targets RGBA32F 344×185: every u / v face once,                   │
│               v −= Δt∇p (ghost fluid at the surface), solid faces take the wall /        │
│               paddle velocity, stored pre-weighted (w·v, w·v_saved, w, w_saved);         │
│               air–air faces get weight 0                                                 │
│ [5] G2P       RGBA32F 512×128 (x, y, vx, vy): 2 branch-free 8-fetch bilinear gathers,    │
│               v = mix(PIC, FLIP, 0.94) (slow surface → PIC), RK2, speed and step         │
│               ≤ 2.4 screen heights/s, paddle push-out, walls                             │
└──────────────────────────────────────────────────────────────────────────────────────────┘
┌─ surface, per frame ── 8 passes ─────────────────────────────────────────────────────────┐
│ [6] SPLAT     gl.POINTS r = 2 cells, poly6, + copies mirrored at the walls (one draw)    │
│               → field  RG16F 683×372  density, speed·density (0.25× canvas + margin)     │
│ [7] BLUR      13-tap Gaussian H+V, σ = 1.4 cells → medium RG16F 683×372                  │
│               H+V σ = 7 cells → wide RG32F 171×372 (¼ width, full height)                │
│ [8] DEEP      RG32F 171×372: wide blurred again vertically (σ 14 cells, ≤ 0.3 × depth)   │
│ [9] NORMALS   RGBA16F 683×372: ∇ lip(medium) + ∇ dome(wide) + ∇ deep                     │
│ [10] DISPLAY  2560×1440 → premultiplied canvas                                           │
│               coverage  smoothstep(iso ± fwidth): medium blur when calm, raw when fast   │
│               dark page: mirror of a studio seen through a 40° lens (floor, wall,        │
│                          horizon strip, key softbox) + tight crest bloom                 │
│               light page: Fresnel + Blinn-Phong + thickness tint + contact + soft shadow │
└──────────────────────────────────────────────────────────────────────────────────────────┘
┌─ every 4th frame ── 1 pass ──────────────────────────────────────────────────────────────┐
│ [11] REDUCE   RGBA16F 128×16: per block, the top occupied cell and fastest cell velocity │
│               → PBO + fence, read a frame later: is the paddle in the liquid? how calm?  │
└──────────────────────────────────────────────────────────────────────────────────────────┘

The ideas that matter

Parameters

Presets

Performance & compatibility

References & credits