This is a brief tutorial for make a simple implementation of a mass-spring system for cloth simulation. The algorithm is based on Newton Second Law, using Verlet integration.


Cloth simulation is a step proposed to develop a solid deformable simulation. Due to mass-spring system simplicity, the algorithm 2d implementation and 3d expansion is very easy.
One of the main features of the problem is to provide enough data independence to extract a high level parallelism, as shown below, and that’s what motivate the use of programmable GPUs.

The mass-spring system

The mass-spring system is based on particles and elastic strengths wich interact under the action of external forces.

How stuff works

The system operation is very simple. Imagine a mass connected by a spring to a fix point, or a infinite mass. If you compress this spring, then a reaction strength with oppose direction will appear to separate the masses. If you stretch the spring, the reaction force will approximate the masses (as shown on the Fig. bellow).
The internal forces will act until the system returns to its rest position or, if there is some external force, until the system reach a balanced state.
The spring reaction force is given by:
Where d is the force direction, k is the spring constant, l is the actual length and r is the rest length.

Cloth simulation

To simulate cloth, we build a system with particles connected by springs as shown in the Fig.
For each particle, its new position is given by the Verlet integration:
Where a represent the particle acceleration, m its mass, x its position, g the external force of gravity and d the damper.

GPU application

We easy adapt the problem to GPU by thinking over matrixes. The positions and acceleration of each particle are a matrix element so, the masses connectivity is given by the neighborhood between those elements. See the Fig.
With Cuda we can easily subdivide the matrix elements to the Execution Units, so each mass point can be processed simultaneously.

Last edited Aug 16, 2009 at 3:33 PM by Lenna, version 7


No comments yet.