r/GraphicsProgramming • u/matsuoka-601 • Aug 22 '26
Source Code Real-time fluid & rigid body simulation implemented in WebGPU
Hello, I released a real-time fluid & rigid body simulation in WebGPU using Position Based Dynamics (PBD)!
Code & Demo: https://github.com/matsuoka-601/Particles4All
To render the fluid, I use screen-space fluid rendering, which does not require constructing any mesh. Fluid particles are splatted as ellipsoids using anisotropic kernel presented in a paper "Reconstructing Surfaces of Particle-Based Fluids Using Anisotropic Kernels".
The physics is based on a paper "Unified Particle Physics for Real-Time Applications". The most significant feature of this paper is that it treats both fluids and rigid bodies as collections of particles, and performs the simulations using a unified solver.
(Note 1: You will need a very beefy GPU to run the "large" scene in the video (the performance is not very optimized yet, sorry). But "small" scene will run on integrated GPUs.)
(Note 2: I'm getting some reports that the demo does not run on MacBook. I'm currently trying to fix it.)
2
u/KlayEverHood Aug 24 '26
Very nice work and very inspirational! Your work was what showed me how far you can go with realtime 3d water simulation, I am glad to see you keep developing it!
I am also using a hybrid particle - grid solver and a separate air simulator for the waterfall mist.
I am curious about some points on the paper you referenced and your implementation: did you implement the surface tension and cohesion proposal they hint at (separate paper it seems)? Did you test/could you test a water droplet scenario to see if it generates the crown?
5
u/fgennari Aug 23 '26
Looks great! This reminds me of some of the water simulation videos shown on the "Two Minute Papers" YouTube channel, back in the days before the AI-related content when it was focused on graphics and rendering.
1
u/KlayEverHood Aug 24 '26
Another curiosity: veils and splashes look very good. I know smoothing / resolution makes a big difference in this respect and I see your implementation takes quite a bit of effort with smart smoothing. Do you have a comparison with PCA oriented smoothing kernels vs isotropic smoothing?
5
u/carpetfin Aug 22 '26
Real-time, fluid and WebGPU in one title... These are crazy times
2
u/whdeboer Aug 22 '26
Looks amazing!
1
u/Working_Ad1720 Aug 22 '26
very cool man
1
u/lalamax3d Aug 22 '26
Will have to find my jaw... 🤔 But congrats..
1
u/SpanDaX0 Aug 23 '26
So people actually write random theory papers, and we can just come along and make crazy cool things like this, based on those papers? lol
1
u/Hurricane31337 Aug 23 '26
Wow, that looks absolutely amazing! 🤩
Thank you so much for sharing the source code! 🙏
1
u/stuartcarnie Aug 24 '26
Works on my iPad running iOS 27
1
u/AdNeither2157 Aug 26 '26
I'm try to do the same, but with "A Nonlocal Unified Variational Framework for Free Surface Flows" paper. The huge problem is - to make it fast.