cursor-fluid-simulation
Cursor Fluid Simulation
When to use this
- You want a fluid dynamics cursor trail where color swirls, dissipates, and interacts with itself like ink in water.
- The brief calls for a smoke-like or paint-like mouse interaction on a background.
- You need the full Navier-Stokes look: viscosity, vorticity, pressure waves.
- You want to understand the GPU ping-pong FBO technique for 2D fluid simulation.
- Do NOT use this for simple particle trails or fading cursor tails -- those are dramatically cheaper. See the cheaper alternatives section below.
Mental model
A 2D fluid simulation solves (a simplified form of) the Navier-Stokes equations on a grid. Each cell of the grid stores a velocity vector (where fluid is flowing) and optionally a density/color (what is visible).
The simulation runs these passes each frame, in order:
-
Advection: Move the velocity field by itself. For each cell, trace backward along the velocity to find where the fluid came from, and copy that value forward. This is semi-Lagrangian advection -- stable at any time step.
-
Diffusion (optional): Smooth the velocity field to simulate viscosity. For real-time fluid, this is often skipped or folded into a decay multiplier.
-
External forces: Add velocity at the cursor position (splat). This is how the mouse interacts with the fluid -- it injects velocity and optionally color.