A downloadable tool

Download NowName your own price

Real-Time 2D GPU Fluid Simulation

A real-time 2D fluid simulation built in Unity using compute shaders.

This project explores GPU-based fluid simulation techniques, interactive obstacle drawing, and real-time visualization tools. The simulation runs entirely on the GPU and allows users to experiment with different emitters, obstacle layouts, and debugging views while observing fluid behavior in real time.


Features

  • Real-time GPU fluid simulation
  • Interactive obstacle drawing
  • Point, line, vortex, and directional emitters
  • Gravity support
  • Vorticity confinement for swirling fluid motion
  • Multiple debug visualization modes
  • Runtime performance statistics
  • Interactive showcase UI

Controls

Input Action
Left Mouse Add fluid density and velocity
Right Mouse Draw obstacles
Middle Mouse Clear obstacles
Q / W / E / R / A / S / D / F / G / Z / X / C / V Trigger showcase emitters
1 - 7 Switch debug visualization modes

Debug Views

The project includes several visualization modes for inspecting the simulation:

  • Density
  • Velocity Magnitude
  • Velocity Direction
  • Divergence
  • Pressure
  • Obstacle Mask

These views help visualize how different stages of the fluid solver behave internally.


Technical Details

The simulation is implemented using Unity Compute Shaders and is based on a grid-based fluid solver.

Core simulation steps include:

  • Velocity advection
  • Density advection
  • Gravity
  • Curl computation
  • Vorticity confinement
  • Divergence calculation
  • Iterative pressure solving
  • Velocity projection

On my test machine, the simulation measures approximately 0.28 ms GPU time.

Test Machine

  • NVIDIA GeForce RTX 4070
  • Intel i5-13400
  • 32 GB RAM

Why I Built This

The goal of this project was to deepen my understanding of GPU programming, compute shaders, and real-time simulation techniques.


Future Improvements

Potential future work includes:

  • Fluid rendering improvements
  • Colored fluids and fluid mixing
  • Additional emitter types
  • Performance optimizations
  • 3D fluid simulation experiments

Credits & References

This project was inspired by:

  • Mike Ash — Fluid Simulation for Dummies
  • Sebastian Lague — Coding Adventure: Simulating Smoke

Download

Download NowName your own price

Click download now to get access to the following files:

FluidSim V1.0.0.zip 41 MB

Leave a comment

Log in with itch.io to leave a comment.