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.
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.
|
|
|
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.
|
|
|
|
|
|
|
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.
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.
|
|
|
A higher spring constant, ks, yielded a stiffer cloth that bended less.
|
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.
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.
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.
|
|
|
|
Texture-mapped cloth.
|
|
|
|
|
|
|
|
|
|
|
|
|
|