A fluid simulation implemented fully on the GPU in TouchDesigner. Based on Jos Stam’s seminal paper using Navier-Stokes equations and a grid-based approach to model fluids, this simulation runs in real time at high resolutions (up to 5,000x5,000 pixels) and is highly versitle. A WebGL implemention is below for exploration (it can also be accessed directly here).
As Stam notes, the Navier-Stokes equations describe the evolution of a velocity field over time. This velocity field represents our fluid and is composed from several intermediate layers:
- Curl - the rotational nature of the fluid at a point
- Divergence - the flow into or out of a grid point in a unit of time
- Advection - the movement of materials in a fluid (in this case, the “dye” we use to color the simulation)
- Pressure - a Poisson solver to solve the pressure equation
These intermediate layers are each a fragment shader, with parameters (i.e. shader uniforms) controlling the interaction of various components:
- Vorticity (or viscosity) controls the degree to which the curl influences the divergence calculation
- Pressure controls the degree to which changes in volume result in directional acceleration
- Diffusion (for both color and velocity) determines how resistive the fluid is to flow, i.e. the momentum of advection
- Pressure passes indicate the number of iterations in our Poisson solver
The below video demonstrates the simulation under various parameter values. There are, of course, many possible extensions and nearly infinite applications (see Portfolio section for some examples).
For a more accessible entry to fluid inspired art, check out