Real-Time-Gases
Gas simulation plugin for Unity based on the position-based dynamic algorithm
Engine:  
Unity
Languages:  
C#, GLSL
Tools:
Rider, Git
Project Link:
GitHub
Project Description
With steadily increasing computing power real-time
simulations of particle-based fluids gain more attention. For interactive
applications the position-based dynamics are widely used
because of their controllability. We present a GPU independent
position-based approach for Unity, focusing on gases, with the
capability to calculate the densities in closed environments. We
show that a realistic gas simulation with reasonable performance,
which calculates and visualizes the amount of gases in a game,
can easily be integrated into Unity using this plugin. On a CPU
with 3.30GHz, we have constant 40 to 50 frames per second
using around 1k particles. A minimal simulation model can be
acquired with four clicks, when the plugin is integrated.
Real-time Gases is developed as a particle-based simulation,
that calculates the methods of the position-based dynamics
on the GPU, while still providing a CPU version. To prevent
permanent instantiation and destroying of particles, the
maximum number of required gases is initialized in an object
pool at the beginning of the simulation. Then all simulation
values are sent to the GPU, where the needed calculations are
run. After this, the resulting values are read from the GPU
and applied to the simulation objects. In case of the CPU
version, the position-based dynamic calculations are executed
directly. At the end the particles positions are updated with
their corresponding Game Objects.
Gallery

1: for each particle i do
2: damp velocity vi ← vi · damping · Δt
3: apply external forces vi ← vi + Δt · fext()
4: estimate position xi* ← xi + Δt · vi
5: end for
6: for each particle i do
7: find neighboring particles Ni(xi*)
8: find other contacts Ci(xi; xi*)
9: end for
10: while iter < solverIterations do
11: for each particle i do
12: solve density constraint Δpi
13: update position xi* ← xi* + Δpi
14: end for
15: end while
16: for each particle i do
17: update velocity vi ← (xi* − xi) · (1 / Δt)
18: apply internal forces fdrag, fvort
19: update position xi ← xi*
20: end for
PBD algorithm solver loop
