Vortex shedding in a wind tunnel.
Vortex shedding in a wind tunnel (divergence view).
- Reasonably fast 2D fluid simulation on the GPU. See the python-numpy and unity-cpu branches for alternative implementations.
- Interactive objects: fans, heaters, coolers, smoke machines
- Fully configurable fluid interactions (ex. configurable gravity, diffusion, vorticity confinement strength, buoyancy, fan speed, enable/disable simulation effects, etc.)
- View shaders: the simulation can be viewed through the lens of normal smoke, velocity divergence, or a grid of velocity-based arrows
- Simple interface with scene presets (use
`to swap scenes)
This simulation follows the Navier-Stokes incompressible fluids equations:
where:
-
$\vec{u}$ represents the fluid's velocity -
$t$ for time -
$\vec{f}$ is used for external forces acting on the fluid -
$\rho$ is a constant used for density -
$p$ is pressure -
$\nu$ for kinematic viscosity
In other words, at each time step:
- Send user input to compute shader
- Update solid-cell pixel-maps (including brush-added fans, heaters, and smoke-generating vents)
- Apply forces (buoyancy, interactive “solid” cells)
- Vorticity confinement (promote tiny swirls)
- Resolve pressure so the liquid is incompressible
- Self-advect
- Advect other properties (smoke, temperature, etc.)
- Diffuse and decay
- Update display shaders
We use a MAC grid to offset velocity components from actual cells of fluid:

Open/import the project into Unity. The default Unity Scene should include a SimulationCanvas object, but in case it does not load, create a new empty object and attach the FluidSimulationGPU script.
| Keypress | Action |
|---|---|
| SPACE | Pause/play |
| CTRL+SPACE or -> | Move one frame forward and pause |
| ESC | Clears everything |
| SHIFT+ESC | Clears everything except solids |
| TAB | Switch view mode |
| ` | Switch scene |
These buttons work alongside mouse movement.
| Keypress | Action |
|---|---|
| R | Clears everything (brush) |
| SHIFT+R | Clears everything except solids (brush) |
| Z | Adds smoke (density) |
| X | Adds velocity |
| C | Adds solid |
| V | Adds heat source |
| SHIFT+V | Adds heat sink |
| B | Adds density source (constant) |
| SHIFT+B | Adds density sink (constant) |
| CTRL+letter | Removes what the above letters added |
| W | Add upwards velocity source (hollow fan) |
| A | Add left velocity source (hollow fan) |
| S | Add down velocity source (hollow fan) |
| D | Add right velocity source (hollow fan) |
| SHIFT+letter | Adds one layer of pixels directly opposite the fan |
| CTRL+letter | Removes hollow fans in a given direction |
- FluidSimulationGPU.cs acts as the orchestrator for all other scripts and shaders
- Simulation.compute is the main engine as a compute shader. All physics-related objects are placed in 2D grids (RWTexture2D objects) - kernels are GPU functions that act on these grids on a per-cell basis.
- View.shader paints the canvas with one layer of pixels. Non-fluid objects and fluid objects are interpolated together so that smoke appears on top of the other objects, but there is really only one pixel plane. Future work could include separating these layers for a more straightforward shader architecture.
- SimulationConfig.cs contains all important configuration options (which can be modified within the Unity editor)
- A 2D platformer game where the character needs to blow dust to see (invisible) platforms. The dust will use the air simulation, and we can add wind/fans to make things more difficult
- 3D simulations
- Add in moving objects
- Find a better pressure projection algorithm (right now we use Jacobi, but Gauss-Seidel or Conjugate Gradient would converge faster)
- https://www.youtube.com/watch?v=Q78wvrQ9xsU
- https://www.cs.ubc.ca/~rbridson/fluidsimulation/fluids_notes.pdf
- https://cgweb.informatik.uni-freiburg.de/intern/seminar/gridFluids_fluid_flow_for_the_rest_of_us.pdf
- https://andrewkchan.dev/posts/fire.html
- https://www.dgp.toronto.edu/public_user/stam/reality/Research/pdf/GDC03.pdf
- https://pages.cs.wisc.edu/~chaol/data/cs777/stam-stable_fluids.pdf
Convection of hot and cool air.
Circular vortices in opposite directions.
Velocity vectors for each cell (debug view)





