I wrote a basic SPH fluid simulator as part of my Master’s based on the papers by Muller and Kelager, written in C++, OpenGL, and NGL. The hardest part was finding parameters to balance pressure and viscosity to keep it from exploding. The only optimization is done with premultiplying the kernel coefficients and a uniform grid.

After cleaning up and optimizing my SPH fluid simulator a bit, I implemented marching cubes to generate a mesh over the particles. It’s not terribly efficient but it does alright, usually running 7-9 fps for 400 particles without any tricks like threading or GPU acceleration. Much of it is based on the marching cubes definitions by Paul Bourke, the site is extremely useful and gives a great explanation of the algorithm.

I used two different methods to calculate the scalar field, one being the classic Metaballs by Blinn, and the other is the Averaged Center method by Zhu and Bridson (2005). The averaged center method is supposed to be smoother, but maybe I didn’t have enough particles for it to be really smooth or the radius was too small.

Marching Cubes on SPH fluid simulation from Julia Lou on Vimeo.

SPH Fluid Simulation from Julia Lou on Vimeo.