Computer Graphics | Game Dev | Technical 2D/3D Art
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
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.
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
A more recent addition: adding on a boolean representing if a cell is a boundary or not, we can draw internal boundaries in the fluid and watch it flow around obstacles. The initial build on the right damps a lot of the fluid motion though.