Cloth Simulation: Physical simulation of a cloth in 3D using a mass spring system model
2021
Modeling a Mass Spring System for Real-Time Cloth Simulation in 3D
Our goal with this project was to model a system that would generate a real-time cloth simulation in 3D. To achieve this, together with a friend of mine, we defined a mass spring system model. In terms of software, we used Unity with C# and wrote a compute shader to handle the computations on the GPU for better performance.
Development
Even though the Unity engine already provides 3D cloth physics behaviour by default, it is limited in terms of performance and vertices count resolution due to the fact that it uses the CPU for execution. For this reason, we wanted to create an algorithm based on parallelism of multiple threads by utilizing the graphical processing unit (GPU). In order to achieve this, we delved into learning how to use compute shaders in Unity.
We made use of the mass spring system model to simulate the cloth. The cloth is represented by a grid of vertices. Each vertex is connected to its neighbors by springs. The spring types we used are structural, shear, and bend springs, as shown in the image below.
Results
By offloading the calculations of many vertex velocities and positions to the GPU where they can be calculated in parallel, we can vastly improve performance. As seen in the following results Unity’s cloth out performs our cloth with less vertices, however, increasing the vertex count shows that this method of cloth simulation is superior in terms of performance.