Multiphase Fluid Simulation

A real-time 3D multiphase FLIP fluid simulator on the GPU, with hierarchical mesh refinement up to 256³ — over 2 million particles at more than 120 fps on an M5 Max.

2026 C# · HLSL

A 3D incompressible multiphase fluid simulator, written from scratch as GPU compute. Particles carry the fluid (FLIP), and an adaptive octree rebuilt under them every frame refines to 256³ detail where the flow needs it, at the free surface and solid boundaries, while staying coarse in the bulk. It runs over 2 million particles at more than 120 fps on an M5 Max.

Pipeline

Every stage is custom GPU compute, more than 150 kernels in all.

  • Sort. Particles are put in Morton order every frame by a hand-written GPU radix sort, so spatial neighbors sit together in memory.
  • Build. The octree is constructed from the sorted particles with parallel prefix sums and stream compaction, with no CPU readbacks, and kept 2:1 balanced between refinement levels.
  • Level set. A signed distance field is propagated inward from the surface for collisions.
  • Pressure. Incompressibility is a Poisson solve on the adaptive grid, done with matrix-free preconditioned conjugate gradients: the stencil is applied on the fly and fused with CG’s dot-product reductions, so the matrix is never assembled.
  • Render. Screen-space fluid rendering from the particles.

Where my research started

The pressure solve is the bottleneck. The octree’s mixed cell sizes and the density jump between the two fluids make the Poisson system badly conditioned, and it changes every frame, so there is no time to build a multigrid hierarchy for it. That problem started my research on learned preconditioners, and the simulator runs a learned preconditioner inside its PCG solve. The published work is A Neural Hierarchical-Matrix Preconditioner for Real-Time GPU Solves (SIGGRAPH Asia 2026 Posters).