August 23rd, 2024

Fluid Simulation and Web Assembly

Eric Hayes developed an interactive fluid simulation in C++ using Smoothed Particle Hydrodynamics, optimizing performance with a grid system and addressing challenges related to stability and Web Assembly compatibility.

Read original articleLink Icon
Fluid Simulation and Web Assembly

Eric Hayes discusses his experience creating an interactive fluid simulation using C++ and Web Assembly, inspired by a Unity project. He explains two primary fluid simulation methods: Eulerian, which is grid-based and suitable for scientific applications, and Lagrangian, which tracks individual fluid particles and is often used in rendering. Hayes implemented the Smoothed Particle Hydrodynamics (SPH) technique, which estimates fluid properties using a smoothing kernel. He faced challenges in achieving stable simulations and optimizing performance, particularly with frame rates dropping significantly when using more than 400 particles. To enhance efficiency, he created a grid to limit calculations to nearby particles, resulting in a substantial increase in particle count from hundreds to nearly ten thousand. However, further speed improvements were necessary for larger 3D simulations, prompting him to consider parallel computing options. He explored using CUDA for GPU computations but faced limitations due to hardware and compatibility issues with Web Assembly. Instead, he opted for OpenGL's vertex and fragment shaders for particle calculations. For rendering, he initially used SFML but switched to SDL for compatibility with Emscripten, which compiles C++ to Web Assembly. Hayes notes that while Emscripten is user-friendly, it has a complex array of compiler flags. He invites readers to check out the source code and demo of his project.

- Eric Hayes created a fluid simulation in C++ using the Smoothed Particle Hydrodynamics technique.

- He optimized performance by implementing a grid system to limit calculations to nearby particles.

- Challenges included achieving stable simulations and adapting to Web Assembly limitations.

- Hayes switched from SFML to SDL for rendering compatibility with Emscripten.

- The project highlights the complexities of fluid simulation and optimization in real-time applications.

Link Icon 2 comments
By @leephillips - 5 months
When on this page almost all my keyboard shortcuts stopped working and it was difficult to close the page. I consider this a form of malware.
By @ellellem - 5 months
Fluid simulation is more suited to GPU (because particles/molecules...) than CPU. What am I missing? SIMD maybe? Not sure...