Open aMyTimed opened 9 months ago
Note: I've never implemented fluid simulation before and haven't looked too deeply into the details yet, so some things might be inaccurate.
In general, fluid simulation is very challenging to do in a way that is efficient and flexible enough for usage in games. 2D might be doable, but 3D would be very difficult or even impossible to do in real time at large scales. This is why you don't really see much proper fluid simulation in games apart from very small amounts of water or gases or the "fake" water that isn't actually physically simulated (like heightfield-based water or purely visual water like in Subnautica).
SPH and FLIP fluids seem to be the most common approaches, so I'd focus on those. There's nothing that would be specific to bevy_xpbd for the core simulation, so I'd make it a separate crate and explore potential interoperability later on.
I would probably start with a "simple" 2D-only, CPU-based SPH plugin for Bevy, with a goal of having something like Sebastian Lague's video's end result (in 2D). I've seen more learning resources and research on SPH, so it might be easier to get started with in comparison to other methods. Once that's working, it should be pretty easy to extend to 3D, and to support more particles, it could also be worth experimenting with simulation on the GPU.
I'm interested in exploring this field at some point, but unfortunately won't have much time in the foreseeable future due to other physics and collision things being more important for the time being.
I encourage others to try to implement it themselves though! I think fluid simulation is really cool, and it'd be amazing to have a plugin for it in the Bevy ecosystem.
Salva is probably the most prominent fluid simulation library in the Rust ecosystem, but it seems to be basically abandoned and uses Nalgebra instead of Glam (not good for Bevy).
It might be a great inspiration and reference though, as it implements different variants of SPH and has some level of interoperability with Rapier. (if only it was updated...)
fluid simulation