Work / xpbd

XPBD vs PBD: real-time cloth simulator

Cloth simulator built on PBD and evolved into XPBD, decoupling material stiffness from solver iterations.

  • Processing
  • Java
  • PeasyCam
  • P3D

Context

Position-based simulation (PBD) is a family of techniques used in cloth, rope, soft body, and fluid physics engines. Instead of computing forces and accelerating particles, it directly corrects positions to satisfy constraints. It’s fast and stable, which is why it powers engines like Havok Cloth, Nvidia PhysX, and Unity Cloth.

This project is a cloth simulator built from scratch on PBD, which I evolved into XPBD (2016) after hitting the classic formulation’s best-known limitation: material stiffness depends on the solver, not just on its parameters.

Overview

I started by implementing a custom particle engine in Processing with the classic PBD constraints: distance, shear, bending, and sphere collision. It worked, but the cloth’s stiffness shifted depending on how many solver iterations ran per frame — raising iterations to stabilize the simulation stiffened the cloth without touching any material parameter. That coupling is PBD’s structural problem.

I rewrote the constraint projection using the XPBD formulation, which introduces a compliance parameter with real physical units, decoupling material stiffness from iteration count. The rest of the system — constraints, solver, integration — stayed the same, but now responds predictably.

From PBD to XPBD: what I changed

In classic PBD, stiffness is controlled by a parameter k ∈ [0,1] with no physical units, and the simulated material also depends on solver iterations and timestep. Müller’s correction (k' = 1 - (1-k)^(1/n)) partially compensates for this, but saturates fast: with moderately stiff materials it stops working and the problem returns.

XPBD solves this by reformulating the constraint as a real physical problem. It introduces the compliance parameter (α), the inverse of stiffness with physical units (m/N). The projection incorporates α̃ = α/dt² and a per-constraint accumulator λ that tracks the force applied during the step. The result: α describes the material, iterations describe convergence quality — independent axes.

I implemented both formulations inside the same Constraint class, which let me directly compare their behavior and confirm that XPBD removes the coupling. The final simulator uses XPBD across all constraints.

Implemented constraints

Four constraint types: distance (structural), shear (angle between edges, analytical gradient (I - vvᵀ)), triangle bend (vertex-to-midpoint distance, more numerically stable than a dihedral angle), and sphere collision with Coulomb tangential friction and surface velocity from rotation (ω × r).

Solver and integration

Sequential Gauss-Seidel solver, 2 iterations per step, dt = 20 ms (60 fps). Semi-implicit Euler integration: position prediction, constraint projection, velocity reconstruction as v = (x - x_prev) / dt. Collisions solved by brute force O(n·m) against the scene’s spheres.

Stability under tension: opening the corners

To validate that the constraints don’t collapse under strong tension, I subjected a cloth to the simultaneous opening of its four corners. The mesh holds numerical stability with no oscillation throughout the motion.

Collision interaction: sphere over hanging cloth

With two top corners fixed, a sphere moves in a straight line through the cloth, exercising the sphere-cloth collision constraint with tangential friction described above.

  • Repository: github.com/fernandoabadlopez/xpbd
  • Position Based Dynamics, Müller et al., 2007
  • XPBD: Position-Based Simulation of Compliant Constrained Dynamics, Macklin, Müller, Chentanez, 2016