In order to continue with my project The SciTech Playroom it has been necessary that I include reasonably believable interactive fluids. Therefore, the last couple of months have seen me researching and experimenting with various means by which this can be accomplished.
I have chosen Position Based Dynamics (PBD) particles, combined with the SPH algorithm to provide the liquid properties.I was able to find two Unity implementations of PBD posted on Github. One was CPU based :Position-Based-Dynamics and the other was GPU based, using Compute Shaders:PBD-Fluid-in-Unity
The challenge for me was, firstly, to port the Unity C# code to Monogame C#. Then, secondly, to implement Compute Shaders into the Monogame code of my demo app. If successful with these two tasks then optimise so as to get the speed boost required for interactive liquids.
I’m pleased to say that all the above has now been accomplished. They say that “the proof of the pudding is in the eating” so here are a couple of vids to show the results.
CPU based implementation (2000 particles @ 2fps)
GPU based implemention using Compute Shaders (4500 particles @ 59fps)
The CPU based implementation is certainly NOT the way to go.
I will thus be following through on the GPU implementation.
Further work will be to add some kind of surface rendering to the particles (Marching Cubes? Volume Rendering?) to give a more cohesive liquid look.
My thanks to ‘Scrawk’ for making the Unity code freely available.