Position Based Fluids in WebGPU: water and rigid bodies solved in the same constraint loop, with the surface rendered in screen space.
The features of this repo are like below:
- Treat both fluid and rigid bodies as sets of particles and solves them in one unified solver presented in Unified Particle Physics for Real-Time Applications.
- Buoyancy is naturally realized within this unified solver.
- Reconstruct a smooth fluid surface using anisotropic kernels presented in Reconstructing Surfaces of Particle-Based Fluids Using Anisotropic Kernels.
- Reconstructed fluid surface is further smoothed in screen space using a narrow-range filter presented in A Narrow-Range Filter for Screen-Space Fluid Rendering.
- Realistic surface tension is realized based on the method presented in Versatile surface tension and adhesion for SPH fluids.
fluid_compressed.mp4
(TODO: write)
(TODO: write)
(TODO: write)
(TODO: write)
WebGPU needs a secure context, so open it over http rather than from file://:
python -m http.server 8080
then http://localhost:8080. Chrome or Edge 113+, Safari 18+, or Firefox with WebGPU enabled. No build step, no dependencies — it is ES modules and WGSL.
Scene picks the size, quality is the fraction of the window the per-pixel
passes run at, box size moves a wall while the water is in it, and
Pour water runs a hose from the near wall. Left-drag rotates, right or middle
drag pans, the wheel zooms, moving the pointer over the water pushes it, space
pauses, H hides the controls and D opens the debug window.
Panorama: Quarry Cloudy by Poly Haven, CC0.