Advanced Particle-Based Fluid Simulation in Unity:
A Journey Through Development, Challenges, and Optimizations
Xinchan JIN / Girish Mallikarjuna / Nikolay Kolev
YouTube: https://youtu.be/jS7aGeo1HLM


Introduction
This project involves the iterative development of a sophisticated particle-based fluid simulation within the Unity game engine, with a focus on adopting and refining Smoothed Particle Hydrodynamics (SPH) techniques. Beginning with initial particle movement influenced by gravity, the project progresses to simulate intricate fluid dynamics behaviors. Throughout the development process, various methodological advancements, mathematical formulations, and computational strategies are employed to enhance the simulation. The project's evolution includes three-dimensional modeling and GPU acceleration, highlighting both the potential and challenges of implementing scientific concepts within a gaming framework. This work contributes valuable insights into computer graphics, game development, and computational fluid dynamics.
01
Background and Related Work
1. Fluid Dynamics and Simulation
Fluid dynamics is a branch of physics concerned with the study of fluids (liquids and gases) and the forces acting upon them. The Navier-Stokes equations are the foundational mathematical equations that describe the motion of fluid substances. However, solving these equations analytically is often impractical due to their complexity, leading to the development of numerical methods and simulations to study fluid behaviour.
2. Particle-Based Simulation Techniques
Among the numerical methods for fluid simulation, particle-based techniques stand out for their ability to model complex fluid interactions intuitively. Smoothed Particle Hydrodynamics (SPH), a method originally developed for astrophysical simulations (Cabezón et al, 2017), has been adapted for fluid simulation in computer graphics due to its versatility and the realistic results it can produce. This method is widely used in a huge range of fields. (Lucy, 1977; Gingold & Monaghan, 1977; Monaghan, 1992).
3. Unity as a Platform for Simulation
Unity, a widely used game development engine, offers robust tools for 3D rendering, physics calculations, and interactive application development. Its adaptability makes it an attractive platform for developing scientific simulations, providing a bridge between complex theoretical models and accessible visual representations.
02
Methodology
The development of the fluid simulation entailed several key phases: initial setup and basic dynamics, integration of SPH for fluid behaviour modelling, optimisation for performance, and expansion to three dimensions. Each phase built upon the previous, incorporating more sophisticated techniques and addressing emerging challenges.
1. Initial Setup and Basic Dynamics
The simulation began with the creation of a basic environment in Unity where particles could be represented and influenced by gravity. This foundational step involved:
Defining particle properties, including position and velocity. Implementing a gravitational force affecting each particle.
Creating a bounding box to contain the particles and simulate collisions.
2. Integration of SPH Techniques
The core of the simulation's realism stemmed from the adoption of SPH methods to approximate fluid density and interactions among particles. This phase included:
Establishing a method to estimate the fluid density at any given point using a kernel smoothing function.
Calculating pressure forces based on density estimates to simulate fluid incompressibility. Implementing viscosity calculations to model internal friction within the fluid.
3. Performance Optimization
Given the computationally intensive nature of particle-based simulations, several optimization strategies were employed:
Spatial partitioning to reduce the computational load by limiting particle interaction calculations to nearby particles.
Transitioning the simulation to utilize GPU compute shaders for parallel processing, significantly improving performance.
Implementing a dynamic adjustment of simulation parameters based on real-time performance metrics.
03
Discussion
The development process highlighted the complexity of fluid simulation, particularly in a computationally limited environment like a game engine. The application of SPH techniques significantly improved the simulation's realism but also introduced computational challenges. Optimizations, particularly spatial partitioning and GPU acceleration, were crucial in achieving a balance between accuracy and performance.
In the future, we will explore the potential of using Unity colliders instead of pre-calculated box constraints. This would enable user to create custom vase using existing Vase Gen project which uses curves to generate 3d vases for endless animation possibilities