top of page

Fluid Sim

Computer Graphics, Interactive Simulation

Following along with GPU gems and Jos Stam's work, I used Unity's Compute Shader pipeline to program an interactive 2D fluid simulator.

Square source with upward velocity

Playing Around

Player Interaction


The player uses the left mouse button to inject dye while using the right mouse button to stir the fluid around.

Pressing the space bar will cycle between different rendering modes:

  • Directly taking density values at each cell and treating them as opacities for some dye color

  • Taking density values at each cell and color-banding according to threshold values

  • Taking velocity values and coloring by mapping velocity angle to hue.

Vorticity Confinement


Only applying diffusion, advection, and velocity projection has a tendency to overdamp the total energy of the system. Softology's Blog mentions that vorticity confinement is a big part of making fluids seem more lifelike. It does so by calculating the curl of the velocity field and "reinjecting" velocity at places with larger amounts of curl. The degree to which velocity is "reinjected" is simulator-controlled with a singular vorticity value, with values close to 0 doing nothing and higher values introducing many small vortices in the fluid.

This is particularly visible when mapping velocity angle to hue.

Vorticity Confinement with Velocity Angle as Hue

Internal boundaries

bottom of page