In this project we implement the basics of cloth simulation, using a wireframe of springs as our physical model of a cloth. On top of modeling these spring interactions, we additionally have the force of gravity. We additionally implement collision detections (with other primitives and self-collisions). Finally, we implement some basic shaders for the cloth.
First we must implement the basic spring mesh. The basic idea here is to have a grid of point masses, with springs connecting diagonal point masses, adjacent point masses, and skip-adjacent point masses (to model bending).
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
For our spring corrective forces, we use Hooke's Law. To determine the change in position for each point mass, we use
Verlet Integration (integrating over accelerating gives us our first order movements). Using different spring constants ks
changes the stiffness of the cloth:
Additionally, modifying density impacts the mass of each point mass, and thus the cloth behavior:
The damping behaviour changes how quickly the cloth comes to rest, essentially determining loss of energy of the simulation.
![]() |
![]() ks |
![]() density |
![]() damping . |
After pinning the cloth, here it is in its final resting state with relatively high damping
and ks
parameters,
with normal shading.
Next we implement collision with other objects. Here is the cloth landing on the sphere:
![]() |
![]() |
![]() |
Essentially, this result informs how much the cloth "droops down", or stretches out. That is, ks
exactly determines the stiffness of the cloth.
Here is a (mirror) shaded display of the cloth colliding with the plane.
To demonstrate the basics of self-collision, we simulate a vertical cloth falling on top of a sphere. Below is a series of screenshots fo this at various parameters
![]() |
![]() |
![]() |
![]() |
As before, the parameters of ks
and density
effect the stiffness of the cloth.
ks
allows the cloth to fold over itself multiple times.density
achieves a similar effect.Vertex shaders are responsible for manipulating the position and orientation of each vertex of a 3D object. They take in vertex data such as position, normal, and texture coordinates and output a modified version of the vertex data. The modified vertex data is then used to determine how the object will appear on the screen. Fragment shaders, on the other hand, are responsible for determining the color of each pixel of an object. They take in the output of the vertex shader and calculate the final color of each pixel based on lighting, material properties, and other factors. Together, vertex and fragment shaders work to create the illusion of depth and realistic lighting effects in 3D scenes. By manipulating the position and color of each vertex and pixel, they can create intricate material effects such as reflections, refractions, and shadows.
The Blinn-Phong shading model is a fragment shader that breaks down lighting into ambient, diffuse, and specular components. The first is a base brightness applied to each fragment. The second is responsible for matte shading. The latter is responsible for many of the glossy and reflective properties of the texture.
![]() |
![]() |
![]() |
![]() |
Instead of light-based shading, we can use UV mapping, we can apply any image as our texture:
We can use either bump or displacement mapping to create depth texture on our default Blinn-Phong shading model. In the former approach, we change the texture by manipulating the vertex normals of the objects. In the latter approach, we manipulate the position of the vertices themselves.
![]() |
![]() |
|
![]() |
![]() |
Displacement mapping clearly has a somewhat more realistic effect. We can see that the actual positions of the cloth are different under this simulation.
Varying the coarseness of the sphere also has different effects based on our type of mapping:
![]() |
![]() |
|
![]() |
![]() |
The Displacement Mapping appears to look significantly better as we increase our resolution of the sphere. In contrast, the Bump Mapping essentially looks the same in both, but the geometry of the sphere obviously changes. This makes sense, as the Displacement Map manipulates the position of the vertices, so if there are more vertices, the effects will be more obvious.
It is easy to implement mirror shading, reflecting from some environment map texture, simply by reflecting the incoming vectors:
![]() |
![]() |
![]() |