CS 184: Computer Graphics and Imaging, Spring 2023

Project 4: Cloth Simulator

Austin Patel, Jennessa Ma, CS184

https://cal-cs184-student.github.io/sp23-project-webpages-horseshoe/proj4/index.html

Overview

We simulate a cloth by modeling it as a grid of masses and springs connected by different spring constraints. We do the physical modeling of the spring forces and gravity on the point masses. We extend this for self-collisions within the cloth and for collisions with spheres and planes. We use numerical integration to determine the movement of the cloth points. Finally, we experimented wit a series of shaders to see different visual appearances such as environment maps and blinn-phong shading.

Part I: Masses and springs

All constraints
No shearing
Only shearing

Part II: Simulation via numerical integration

Default settings: pinned2
Small Ks (100 N/m)
Large Ks (10000 N/m)

Modifying the spring constant affects how strong the springs are. For example, a very small spring constant creates many valleys/ripples across the 2 pinned corners, whereas a really high spring constant (strong springs) only creates 1 shallow valley.

Small density (2g/cm^2)
Large density (100g/cm^2)

Changing the density of the cloth impacts the mass of each of the point masses in the cloth. If there is a small density, then each point will have a small mass meaning that the points will have a larger acceleration due to the spring force (F=ma). If the density is high, then the points will have higher mass and will move more slowly. With heavier points the cloth sags downward more and with smaller mass there is less sag in the cloth.

Small damping (2%)
Large damping (95%)

Modifying the damping term affects the stability of the cloth while it simulates. With a very small damping term, the cloth was constantly wavering and unstable, while a large damping term caused the cloth to be very stagnant and stabilized once it fell.

Default settings: pinned4

Part III: Handling collisions with other objects

Default ks=5000 sphere
Small ks=500
Large ks=50000
Cloth lying peacefully on the plane

With a weaker spring constant (500), the springs in the cloth are overall weaker, so it easily folds over itself more as it drapes over the sphere. On the other hand, a very high spring constant (50000) means the springs are very strong so the cloth is expected to be quite stiff. This can be seen by the very few folds on the cloth and the edges sticking outwards more as it physically has a harder time bending.

Part IV: Handling self-collisions

Default parameters:

Time 1
Time 2
Time 3
Time 4

Varying the density of the cloth impacts how smooth the folds are in the cloth. For the very low density experiment, the cloth folded very flatly across the surface, while the high density cloth had had a lot of smaller wrinkles and didn't fold flat as nicely.

Density 1 g/cm^2
Density 100 g/cm^2

Varying the spring constant changes how stiff the cloth is and how resistant it is to folds. For the low Ks experiment the cloth had less rigid structure and didn't lay as flat. For the high Ks experiment, the cloth had a more rigid structure and had a smaller number of folds.

Ks 100 N/m
Ks 50000 N/m

Part V: Shaders

A shader program is composed of a vertex shader and a fragment shader that works together to create light, texture, color, material, etc. outputs. A vertex shader works on individual vertices by applying transformations such as converting it to the model space, sampling texture maps, and scaling it to determine the final position on the screen. This creates the input to the fragment shaders, which expects varyings such as the normals, transformed positions, tangents, uvs, etc. With these varyings, the fragment shader can use them to compute the final color and appearance of a pixel. This could mean sampling another texture map, using the normals to calculate new rays, calculating diffuse/specular/ambient shading, etc. Together, the final output could be very complex materials such as blinn-phong shadings, mirrored images, and bumpy/displaced surfaces.

Blinn-Phong Shading: This shading involves combining ambient, diffuse, and specular light to create a final surface. In our implementation, the ambient component consists of constants ka and Ia multiplied together, resulting in a simple color that affects all surfaces equally. The diffuse component consists of using the constant kd, light intensity I, distance from the camera to the position, the normal, and direction to the light to simulate diffuse objects under light. The specular component focuses on light reflecting off a specific direction, creating the shiny parts of the cloth.

Ambient component
Diffuse component
Specular component
Entire Blinn-Phong model

Texture mapping shader with our own custom texture (kresge library):

Custom texture

Bump mapping and displacement mapping: Bump mapping involves modifying the surface normals according to a bump map which is a texture. For the desired u,v coordinates, we compute a discrete derivative of the texture at u,v and use that derivative to compute a modified surface normal. This lets us generate the appearance of bumps by modifying surface normals. Displacement mapping takes this one step further by actually modifying the locations of the vertices by the height in the texture map (moved in direction of the surface normal).

Bump mapping on the cloth and on the sphere
Displacement mapping on the sphere
Bump: Modified sphere's coarseness: -o 16 -a 16
Bump: Modified sphere's coarseness: -o 128 -a 128
Displacement: Modified sphere's coarseness: -o 16 -a 16
Displacement: Modified sphere's coarseness: -o 128 -a 128

For both bump and displacement mapping, the lower coarse image resulted in sharper edges on the sphere compared to the higher resolution image. The cloth remained the same because the parameters should only affect the sphere resolution.

Mirror shader:

Mirror shader
Mirror shader with simulation