Position-Based Dynamics — Real-Time Cloth, Ropes and Soft Bodies
Traditional physics engines integrate Newton's second law — forces produce accelerations, accelerations update velocities, velocities update positions. This pipeline has a critical flaw: stiff constraints (inextensible cloth, rigid joints, collision contacts) require tiny timesteps or specialized solvers to remain stable. Position-Based Dynamics (PBD), introduced by Müller et al. in 2007, sidesteps the problem by operating directly on positions through iterative constraint projection — producing unconditionally stable cloth, rope, and soft-body simulation fast enough for real-time games and interactive VFX.
1. Force-Based vs. Position-Based
In a force-based simulation, a spring between two particles contributes a force F = k(|Δx| − L₀) × n̂ at each timestep. Solving the resulting stiff ODE requires either:
- Small timesteps (explicit Euler, Runge-Kutta) — stable but slow for stiff springs.
- Implicit integration (Newmark-Beta, implicit Euler) — stable but requires solving a large linear system at each frame.
Both approaches scale poorly to millions of constraints. PBD replaces this with a direct constraint projection step: instead of computing forces, we directly compute how much to move each vertex to satisfy a geometric constraint. The result:
- Unconditional stability regardless of timestep size.
- O(n) and easily parallelizable (no global linear system).
- Intuitive stiffness as number of solver iterations (artistic control).
2. The PBD Algorithm
The velocity update in step 4 is crucial: velocities are derived from position displacements, not integrated from forces. This means constraint corrections automatically produce physically consistent velocity changes — collisions produce accurate impulses for free.
3. Constraint Types
Distance Constraint
Maintains the rest length L₀ between particles p₁ and p₂:
Bending Constraint
Resists out-of-plane folding in cloth. Applied to four particles forming two adjacent triangles, it penalizes deviation of the dihedral angle from the rest angle.
Volume Conservation
For soft bodies, a global volume constraint maintains total enclosed volume close to rest volume V₀, producing the incompressibility characteristic of biological tissue and rubber.
Collision Constraint
When particle p penetrates a surface with normal n̂ and moves by depth d, the constraint C = d ≥ 0 is enforced by projecting p to the contact plane and applying friction impulses tangentially.
4. Gauss-Seidel Iteration and Convergence
PBD applies constraints sequentially (Gauss-Seidel order) rather than simultaneously. Each constraint is projected assuming all others are already satisfied — a greedy approach that is fast but not exact:
- With 1 iteration: low-resolution, springy behaviour (useful for ropes).
- With 10–30 iterations: near-inextensible cloth, rigid joints.
- With 50+ iterations: near-rigid rods, suspension bridges.
The effective stiffness scales as (1 − (1 − k)^n) where k is the constraint stiffness coefficient [0,1] and n is the iteration count. Convergence is guaranteed for convex constraint sets, and the simulation never explodes — worst case is a slightly "looser" constraint than intended.
For dependent constraints (e.g., long rope chains), convergence is still limited by information propagation speed — a constraint at one end only "knows about" a constraint at the other end after N passes through the chain. This motivates substeps: splitting each frame into multiple smaller PBD timesteps.
5. XPBD — Extended PBD with Compliance
Müller et al. (2020) introduced XPBD to give PBD a proper physical basis. Each constraint gets a compliance parameter α = 1/k (with k the spring stiffness in N/m) that is timestep-independent.
XPBD is used in NVIDIA's Flex, Unreal Engine's Chaos Physics, and Houdini's Vellum solver. It enables artists to specify material stiffness in N/m (a physically meaningful unit) while the engine automatically produces stable simulations regardless of substep count.
6. Self-Collision and Continuous Detection
Cloth self-collision — vertices penetrating the same mesh — is the hardest problem in cloth simulation. Naïve O(n²) collision detection between all vertex pairs is too slow. Common approaches:
- Spatial hashing: hash grid of cells sized to cloth thickness; only test vertex-pairs in the same or adjacent cells. O(n) for uniform cloth.
- BVH traversal: bounding volume hierarchies (AABBs or oriented bounding boxes) refitted each frame. O(n log n), good for non-uniform meshes.
- Continuous collision detection (CCD): instead of testing end-of-timestep positions, test the entire trajectory from x to p for vertex-triangle and edge-edge collisions. Prevents tunnelling through thin layers.
For visual effects at cinema quality, Pixar's cloth system adds repulsion forces between surfaces approaching closer than a proximity threshold, preventing the need to resolve many simultaneous deep penetrations.
7. GPU Parallelism
PBD scales well to GPU because the constraint projection step is embarrassingly parallel at the per-constraint level. The main challenge is write conflicts: two constraints sharing a vertex both try to update that vertex simultaneously.
Solutions include:
- Graph colouring: colour constraints so same-coloured constraints share no vertices. Each colour group is processed in parallel on GPU. Cloth typically requires 4–8 colours.
- Atomic float adds: accumulate position deltas atomically; divide by count after all constraints are processed (Jacobi-style).
- WebGPU compute shaders: the modern web alternative to CUDA/OpenCL; supports the graph-coloured PBD pipeline with workgroup shared memory for local aggregation.