Cloth Simulator

Rina Lu



Overview

In this project, I learned to animate a cloth material based on its physical properties. I learned how to create the cloths structure, how to manipulate the structure based on forces acting upon it in its environment, how to model the cloths interactions with other objects, and how to shade the cloth.

Part I: Masses and springs

In order to animate the cloth material, I first had to implement its structure. I did so by creating a grid of point masses to represent the intersections of the strings in the cloth, and implemented springs between each point mass in three orientations, structural, shearing, and bending. The springs assist in the animation of the cloth, and help to create a realistic rendering of how the cloth is affected by various forces by maintaining the material's basic form.

Wireframe of cloth without and with the effects of gravity.
With all constraints.
Without shearing constraints.
With only shearing constraints.

Part II: Simulation via numerical integration

Once the basic frame of the cloth was constructed, I could begin simulating the effects of forces on it. First, I calculated the total external force acting on the cloth, and applied the force to each of its point masses. Next, I applied the spring correction forces to each spring, and adjusted the bending constraing forces to be weaker. After applying the external forces to the structure of the cloth, I calculated the new positions each point mass would take on in the next time step, using Verlet integration. If a point mass was pinned, its position did not change. Finally, to account for the effect of the springs on the cloth's movement, I constrained the change in length between positions such that it did not exceed more than 10% per timestep. I did this by iterating through the springs, and accessing the position of both of its point masses to see if their difference was greater than the rest length of the spring multiplied by 1.1. If it was, I calculated a correction vector to be added to each point mass. After completing this section, I could simulate a cloth falling due to gravity.

Small ks.
Large ks..
Small density.
Large density.
Small damping.
Large damping.
The cloth pinned at 4 points.

A small ks, or spring constant, created more wrinkles in the cloth, as well as more movement. A large ks had less movement, and less wrinkles and flexibility in the cloth. A small density also allowed for more movement, while a large density made the cloth slow and heavy, causing a larger bend between the two pins. A small damping value created a lot more movement and oscillation, while a higher damping yielded less movement.

Part III: Handling collisions with other objects

I implemented the effects of the cloth colliding with other objects by manipulating the positions of each point mass such that they never end up inside the object. If the point masses' positions were inside the object, I bumped them back up to the surface of the object. I implemented this for both a sphere and a plane.

Cloth with ks 500..
Cloth with ks 5000.
Cloth with ks 50000..

A higher spring constant, ks, yielded a stiffer cloth that bended less.

Cloth lying on plane.

Part IV: Handling self-collisions

In addition to handling collisions between the cloth and external objects, I also needed to handle collisions between the cloth and itself. Before implementing this section, the cloth fell straight through itself, but after, the cloth reacted upon collision with itself. I implemented self collision by using a hash function to create a spatial map of all the point masses, and used this to check to see if each point mass coincided with another. If the point masses collided, I applied a correction vector.

Cloth falling on itself.

I varied the density and spring constant to see how they would affect the cloth falling on itself. I found that with a higher density, the cloth crumpled more directly on top of itself, and had tighter folds, while a smaller density caused large folds in the cloth and less wrinkles. On the other hand, a larger spring constant created larger folds and a stiffer cloth, while a smaller spring constant yielded more wrinkles.

Large density.

Small density.

Large spring constant.

Small Spring constant.

Part V: Shaders

A shader program is a program that runs computations in parallel on the GPU. They are used to manipulate the lighting and shading effects, taking in various inputs such as a texture file, and outputs a single 4 dimensional vector. Vertex shaders affect the positions of the vertices by applying transforms to them, and fragment shaders affect the color and texture by taking calculations from the vertex shader.

The Blinn-Phong shading model blends ambient, diffuse, and specular components of lighting to create a realistic, cohesive lighting rendering.

Blinn-Phong with only ambient component.
Blinn-Phong with only diffuse component.
Blinn-Phong with only specular component.
Blinn-Phong with all parts implemented.

Texture-mapped cloth.

Bump-mapping on sphere.
Bump-mapping on cloth.
Displacement-mapping on sphere.
Displacement-mapping on cloth.
Bump with -o 16 -a 16.
Sphere less visible under cloth.
Displacement with -o 16 -a 16.
Displacement is more inaccurate.
Bump with -o 128 -a 128.
Sphere more visible under cloth.
Displacement with -o 128 -a 128.
Displacement is more accurate.
Mirror shading on sphere.
Mirror shading on cloth.