Introduction

This project is the final project of CS6660, aiming to simulate cloth in real-time framerate. Simulation part is doing in CPU with single thread. Graphic API is OpenGL4.4. Render Engine is my own graphic engine.

Hardware:
Processor: Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
Installed Ram: 16.0 GB
Display adapters: NVIDIA GeForce RTX 2080
Monitor: 144Hz

Parameters:
Particles: 100 * 100

Mass: 1.0 kg (per node)
Cloth length: 2.0 m
Gravity: (0, -0.392, 0) m·s−2

FRICTION_COEFFICENT 0.25                       // Friction coefficient

FRICTION_DAMPING      – 0.50                     // Friction damping

FRICTION_BIAS               0.50                        // A form of thickness of the cloth when checking friction
STRUCT_STIFF                   80.0                      // stiffness of structural spring force
STRUCT_DAMP                 -2.00                      // damping of structural spring force
SHEAR_STIFF                     56.0

SHEAR_DAMP                   -1.00

BEND_STIFF                      40.0

BEND_DAMP                    -0.50

STIFF_DIFFERENCE          0.40                       // stiff difference ratio from the top node to the bottom node

Algorithm

Pipeline:

1. Initialize all particles position, particle neighbors and collision spheres.
2. Set up texture coordinate, indices.
3. Enter main loop and render loop.
4. Calculate internal spring forces from neighbors.
5. Calculate friction from floor and sphere.
6. Use integrator to get the next position.
7. Do floor and sphere collision detection and response.
8. Update next position and calculate normal.

Integrator:
Verlet integration (without velocities)
x(t + dt) = 2·x(t) – x(t-dt) + a(t)·dt^2 + O(dt^4);
v(t)         = (x(t)-x(t-dt)) / dt;

Combine and ignore O(dt^4):
x(t + dt) = x(t) + v(t)·dt + a(t)·dt^2;

Handle friction:

Get the vertical force on the surface normal direction. Check if it is going toward to the center of the sphere. Check if the horizonal force on the surface normal direction is bigger than the friction force. The final horizontal force will not be smaller than zero on surface tangent direction.

Collision response to sphere:

Simply move the particle out of the sphere.

Render

Material of the cloth is PBR metallic roughness workflow.

Vertex layout:

Challenge:

My implementation is so easy to explode:

1. Increase time step
2. Increase stiffness
3. Reduce mass per particles

Therefore, it is very hard for me to increase the resolution of the cloth but keeping the stiffness in a high value. I must adjust a lot of things to ensure a decent result and prevent simulation explosion. You might notice that the gravity is not -9.8f. The reason is that if the gravity is too big, my cloth will be stretched to the ground due to low stiffness and it looks very bad. I have tried increase the damping and stiffness together, but it always explodes at the end.

References

1. Verlet integration
https://en.wikipedia.org/wiki/Verlet_integration
2. Cloth simulation project
https://github.com/dayeol/clothsimulation/blob/master/CLOTH%20SIMULATION(FINAL).pdf
3. Simulate Tearable Cloth and Ragdolls With Simple Verlet Integration
https://gamedevelopment.tutsplus.com/tutorials/simulate-tearable-cloth-and-ragdolls-with-simple-verlet-integration–gamedev-519
4. Cloth Simulation
https://steven.codes/blog/cloth-simulation/