You can view the spec for this project at Assignment 4: Cloth Simulation.
In this project, a real-time simple cloth simulation is implemented with mass-spring system model. Starting from building the data structures to discretely represent the cloth, I then define and apply physical constraints (including STRUCTURAL, SHEARING, or BENDING ) on them, and apply numerical integration to simulate the way cloth moves over time. Meanwhile, collisions with other objects (plane and sphere) and self-collisions are also implemented.
In this part, the basic structure of cloth is built up with three types of constraints (including STRUCTURAL, SHEARING, or BENDING).
Here are the outputs of a horizontally flat cloth wireframe with different settings of enabled constraints.
![]() |
![]() |
![]() |
|---|---|---|
| with all constraints | without any shearing constraints | with only shearing constraints |
An output of scene\pinned2.json
![]() |
|---|
scene\pinned2.json |
In this part, Verlet integration is implemented for integrating the physical equations of motion in order to apply the forces on our cloth's point masses. And then, figure out how they move from one time step to the next.
Here is a simulation process of the cloth with 4 ends pinned:
![]() |
|---|
scene\pinned4.json |
The appearance and behavior of the cloth can vary by modifying parameters, including the stiffness/resistance to deformationks and density. While higher ks results in tight cloth that is less tend to stretch under gravity, higher density increases the downward gravitational force on the cloth and create more folds as shown below.
Varying ks with fixed density = 15
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|
ks = 100 |
ks = 1000 |
ks = 5000 (default) |
ks = 100000 |
Varying density with fixed ks = 5000
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|
density = 5 |
density = 15 (default) |
density = 30 |
density = 100 |
In this part, collisions with other objects (including plane and sphere) are implemented. At a high level, the collide method will determine whether or not a given point mass is inside the primitive. If it is, we adjust the point mass's position so that it stays just outside the primitive's surface, accounting for friction as we do so.
Colliding with sphere and plane (without self-collisions)
![]() |
![]() |
|---|---|
scene\sphere.json |
scene\plane.json |
Here is a simulation process of the cloth colliding with sphere (without self-collisions)
![]() |
|---|
scene\sphere.json |
In this part, self-collision of cloth is implemented with spatial hashing.
Here is a simulation process of the cloth placing vertically and colliding with the plane and itself. However, the jittering artifact is still noticeable. It could be improved with smaller step_of_time or better self-collision handling methods.
![]() |
|---|
scene\selfCollision.json |
With self-collision implemented, let's compare the sphere-cloth collision with and without self-collision. It's obvious that with collision, the part of cloth that is falling downward (below the sphere) is more natural and it's not colliding with itself any more.
![]() |
![]() |
|---|---|
| without self-collision | with self-collision |
In this part, five different types of shaders are implemented using GLSL, including diffuse shading, Blinn-Phong shading, texture mapping, displacement and bump mapping, and environment-mapped reflections
![]() |
|---|
| Diffuse Shading |
![]() |
|---|
| Blinn-Phong Shading |
![]() |
|---|
| Texture Mapping |
![]() |
![]() |
|---|---|
| Bump Mapping | Bump Mapping: does NOT change the vertex |
![]() |
![]() |
| Displacement Mapping | Displacement Mapping: changes the vertex and the geometry |
![]() |
|---|
| Environment-mapped Reflections (with cubemap textures) |

























