Overview
This project is a real-time soft-body and cloth simulator with tearing and wind forces. It is implemented in C++ and OpenGL using GLFW, GLEW, Eigen, and GLM.
Video
Details
This demo uses a position-based dynamics (PBD) mass-spring model.
- Mass-Spring Model Both soft-bodies and cloth are made up of particles connected by springs. Each spring has a rest length that is enforced through iterative position corrections.
- Volumetric Constraints Soft-bodies have volumetric constraints in addition to spring constraints. Particles throughout the soft-body are grouped into tetrahedra, and each tetrahedron has a signed volume that is preserved to prevent the soft-body from losing volume, and to prevent the soft-body from inverting.
- Tearing Springs, when stretched beyond 2.5 times their rest lenth, are marked as broken, and their constraints are no longer applied. This allows parts of the cloth to separate and form tears. Additionally, tetrahedra that contain broken springs are also marked as broken, allowing soft-bodies to tear.
- Wind Forces Every few seconds, the wind in the scene is given a random direction and pressure. For every triangle in the soft-bodies and cloths, the force of the wind on the triangle is calculated as the dot product of the triangle's normal and the wind's pressure, multiplied by the triangle's area. This force is then distributed to every particle in the triangle in the direction of the triangle's normal. This approximation creates a natural appearing wind force, although it is far stronger on soft-bodies due to being applied to their internal triangles.
- Solver To keep the soft-bodies stable, the spring constraints undergo 10 PBD iterations per timestep.
- Static Objects Cloth and soft-body particles collide with non-soft-body objects in the scene, including spheres, planes, cylinders, and tetrahedra using simple geometric projections to the object's surface. The user can also control a spherical or tetrahedral held object that can collide with the cloth and soft-bodies.
- Rendering The scene uses a basic two-pass pipeline with shadow mapping. The first pass renders the depth from the light source into an FBO. The second pass calculates typical Blinn-Phong shading with a shadow map lookup.
Source
The source code for this project can be found on Github.