Fabric in the Machine
Cloth simulation is one of the most visually rewarding challenges in computer graphics. From Batman's cape to the flags in Assassin's Creed, every piece of simulated fabric starts as a flat grid of particles connected by invisible springs. The art lies in making these simple connections produce the rich, flowing behavior we associate with real textiles — silk, denim, chainmail each requiring different parameters.
Position-Based Dynamics
Modern cloth engines use Position Based Dynamics (PBD), pioneered by Matthias Muller and collaborators. Instead of computing forces and integrating accelerations, PBD directly moves particles to satisfy constraints — distance constraints prevent stretching, collision constraints prevent penetration, and bend constraints control fold stiffness. The result is a robust, stable simulation that rarely explodes even under extreme conditions.
The Constraint Solver
Each frame, gravity and wind displace the particles. The constraint solver then iterates through every constraint, nudging connected particles toward their rest distance. More iterations mean stiffer cloth but higher CPU cost. Real-time engines typically use 3-8 iterations — enough for convincing fabric without breaking the frame budget. This simulation lets you see how iteration count directly affects cloth behavior.
Wind, Collision, and Self-Intersection
Gravity alone produces static draping. Wind transforms cloth into a dynamic, living surface — flags snap, capes billow, curtains flutter. Wind forces are applied per-triangle based on face normal and wind direction, creating aerodynamic lift and drag. Collision detection keeps the cloth from passing through characters and scenery. Self-collision — preventing the cloth from passing through itself — remains one of the hardest problems in real-time graphics.