Link to GitHub: https://github.com/BosonHBC/GraphicsEngine_OpenGL
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.
Processor: Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
Installed Ram: 16.0 GB
Display adapters: NVIDIA GeForce RTX 2080
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
STIFF_DIFFERENCE 0.40 // stiff difference ratio from the top node to the bottom node
- Initialize all particles position, particle neighbors and collision spheres.
- Set up texture coordinate, indices.
- Enter main loop and render loop.
- Calculate internal spring forces from neighbors.
- Calculate friction from floor and sphere.
- Use integrator to get the next position.
- Do floor and sphere collision detection and response.
- Update next position and calculate normal.
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;
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.
Material of the cloth is PBR metallic roughness workflow.
My implementation is so easy to explode:
- Increase time step
- Increase stiffness
- 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.
- Verlet integration
- Cloth simulation project
- Simulate Tearable Cloth and Ragdolls With Simple Verlet Integration
- Cloth Simulation