Physics Simulation · Computer Graphics · Algorithms
📅 Квітень 2026 ⏱ ≈ 13 хв читання 🎯 Intermediate–Advanced

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:

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:

Limitation: PBD stiffness depends on iteration count and timestep — doubling the number of substeps changes the apparent stiffness. XPBD (Section 5) fixes this with a compliance parameter that remains physically meaningful across different timestep sizes.

2. The PBD Algorithm

foreach timestep h: 1. PREDICT foreach particle i: v_i ← v_i + h · (f_ext / m_i) // apply external forces (gravity, wind) p_i ← x_i + h · v_i // predicted position 2. GENERATE COLLISION CONSTRAINTS detect collisions with scene geometry and between particles add temporary contact constraints 3. PROJECT (repeat for n iterations): foreach constraint C_j(p_1, ..., p_k) = 0: compute corrections Δp_i that satisfy the constraint apply: p_i ← p_i + Δp_i (weighted by inverse mass 1/m_i) 4. UPDATE foreach particle i: v_i ← (p_i − x_i) / h // velocity from position change x_i ← p_i // commit new position 5. UPDATE VELOCITIES (damping, friction, etc.)

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₂:

C(p_1, p_2) = |p_1 - p_2| - L_0 Gradient: ∇_p1 C = (p_1 - p_2) / |p_1 - p_2| = n̂ Correction: Δp_1 = -(w_1 / (w_1 + w_2)) · C · n̂ Δp_2 = +(w_2 / (w_1 + w_2)) · C · n̂ where w_i = 1/m_i (inverse mass; w=0 for pinned/static particles)

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:

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 replaces the constraint projection with a Lagrange multiplier update: Δλ = -(C(p) + ã · λ) / (Σ w_i |∇_pi C|² + ã) where ã = α / h² (compliance scaled to timestep size h) Correction: Δp_i = w_i · Δλ · ∇_pi C After each substep: update λ ← λ + Δλ Key property: α = 0 → rigid constraint (classical PBD) α → ∞ → no constraint at all Stiffness is now independent of iteration count and timestep!

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:

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:

Performance target: A 128×128 cloth mesh (16 384 particles, ~96 000 constraints) running 8 substeps × 10 iterations with GPU graph-coloured solver typically achieves <1 ms per frame on modern hardware — more than fast enough to run alongside a full 3D scene at 60 Hz.
🧵 Try the Cloth Simulation →