Eulerian Fluid Simulation
Lionel Pigou / January 2021
Disclaimer: The text in this post is generated by an AI chatbot based on a few bullet points.
Fluid simulations in voxel games can greatly enhance the overall gameplay experience, adding realism and immersion. As a developer of the smooth voxel game Meor, I set out to implement fluid simulations on the GPU, with a primary focus on conserving mass. In this blog post, I will discuss the challenges I faced, the approaches I explored, and the ultimate solution I settled on.
Euler’s Method
To begin with, I decided to adopt the Eulerian method based on the work of Harris, Mark J. in his paper titled “Fast fluid dynamics simulation on the GPU.” This approach seemed promising, but I soon encountered a significant problem - mass conservation. The fluid would dissipate over time, leading to an unrealistic simulation.
In my quest for a solution, I delved into existing research, drawing inspiration from the paper by Chentanez, Nuttapong, and Matthias Müller, titled “Mass-conserving Eulerian liquid simulation.” This research proposed a method that involved determining local masses using a connected components algorithm implemented on the GPU. By calculating the mass for each component before each simulation step, they were able to correct the mass by adding or subtracting as necessary.
While the mass-conserving Eulerian method appeared to address the issue of mass dissipation, I soon encountered another hurdle - performance. The implementation was not performant enough for my needs. On a GTX 980, the computation time ranged from 3 to 6 milliseconds, which exceeded the performance budget I had set for fluid simulations alone. As a result, I had to seek an alternative solution.
Grid Sweeping Method
After careful consideration, I opted for a grid sweeping method to achieve the desired fluid simulation. This approach involved sweeping the fluid mass over the grid in a specific direction during each pass. Notably, different fluid materials had varying viscosities and moved at different rates, which added complexity to the simulation.
Compared to other potential alternatives such as cellular automata, the grid sweeping method proved to be more efficient in terms of fluid movement speed. While cellular automata could have been a viable solution, it significantly slowed down the fluid simulation process.
Conclusion
Implementing fluid simulations in a voxel game posed several challenges, particularly in terms of mass conservation and performance. While initially adopting the Eulerian method showed promise, it fell short in terms of conserving mass effectively. Seeking inspiration from related research helped me understand the intricacies of the problem better, but ultimately, the performance limitations led me to explore alternative solutions.
The grid sweeping method emerged as the most viable choice, allowing for efficient fluid movement while maintaining acceptable performance levels. As a game developer, striking a balance between realism and performance is crucial, and I believe that the solution I settled on for fluid simulations in Meor achieves that balance.
By continually experimenting, learning, and refining our approaches, we can push the boundaries of what’s possible in game development, creating more immersive and captivating experiences for players. The journey of implementing fluid simulations in Meor has been an enlightening one, and I’m excited to continue exploring new techniques and advancements in the field.