SPH fluid simulation

I researched using SPH — smoothed particle hydrodynamics — to simulate fluids for a chemistry lab simulation. I started from sample C++ code I found online, first in Unreal Engine and later in a custom C++ application, and worked on getting it to run on low-end hardware: the target was a cheap Walmart laptop, not a workstation. That constraint shaped the rest of the work, because SPH is simple to describe and expensive to run — every particle has to find its neighbours again on every step.

I moved off Unreal Engine because I was not confident I could reach the low-level performance that hardware demanded without writing the fluid renderer myself — and because I wanted to know how to build one from scratch.

Simulating the particles

The particle step was the first cost to attack. I looked into various performance techniques like SIMD and using parallel processing for the fluid particle simulation.

Rendering the surface

A particle simulation has no surface of its own — one has to be reconstructed every frame from the particle field, and the point of the exercise was to work out which approach would hold up on that hardware. I used marching cubes to build a polygonal surface from the density field, and researched and partially implemented screen space fluid rendering as the alternative, which skips the mesh entirely and reconstructs the surface from the depth buffer instead.

Previous Next