CS 184: Computer Graphics and Imaging, Spring 2023

Project 4: Cloth Simulator

Ziqi Shi, Buyi Geng

Website URL: Linum usitatissimum



Overview

There are two main parts to this project. In the first part, we simulated the physics behind cloth kinematics and created a system that can simulate how a piece of fabricated cloth can interact with itself and other objects in a scene, while in the second part we wrote GLSL shaders to render the cloth in different interesting manners.

The first part was divided into 4 main steps:

The second part of the project was more straightforward. For each different shader, we simply use the simulation algorithm for each of the light effects in each shader's corresponding .frag file, and copied the rendered value to the output variables. For displacement shader, we also modified the .vert file so that it can edit the vertex locations in accordance to the displacement map to reflect a varying height for each vertex to represent the displacement on the materials.

Part I: Masses and springs

Take some screenshots of scene/pinned2.json from a viewing angle where you can clearly see the cloth wireframe to show the structure of your point masses and springs.


Show us what the wireframe looks like (1) without any shearing constraints, (2) with only shearing constraints, and (3) with all constraints.

No Shearing
Only Shearing
Full Mesh

By taking screenshots of the cloth wireframe under these different constraints, we can demonstrate how the point masses and springs work together to simulate the behavior of a cloth. The comparison of the wireframes also helps in understanding the role each type of constraint plays in the overall simulation.

Part II: Simulation via numerical integration

Experiment with some the parameters in the simulation. To do so, pause the simulation at the start with P, modify the values of interest, and then resume by pressing P again. You can also restart the simulation at any time from the cloth's starting position by pressing R

Show us a screenshot of your shaded cloth from scene/pinned4.json in its final resting state!

Pinned4.json in its final resting state

Part III:Handling collisions with other objects

Show us screenshots of your shaded cloth from scene/sphere.json in its final resting state on the sphere using the default ks = 5000 as well as with ks = 500 and ks = 50000. Describe the differences in the results.

500ks
ks = 500
5000ks
ks = 5000
50000ks
ks = 50000

Show us a screenshot of your shaded cloth lying peacefully at rest on the plane. If you haven't by now, feel free to express your colorful creativity with the cloth! (You will need to complete the shaders portion first to show custom colors.)

Part IV:Handling collisions with other objects

Show us at least 3 screenshots that document how your cloth falls and folds on itself, starting with an early, initial self-collision and ending with the cloth at a more restful state (even if it is still slightly bouncy on the ground).

The cloth begins to fall down and folds on itself
The cloth collides on itself
The cloth flattens out

Vary the density as well as ks and describe with words and screenshots how they affect the behavior of the cloth as it falls on itself.

With lower density and lower ks, the cloth appears more elastic and loosely folded, as the lower stiffness allows for larger deformations and less resistance to self-collision. With higher density and higher ks, the cloth appears stiffer and maintain its structure more effectively, leading to smaller folds and a more rigid appearance. A combination of low/high density and high/low ks can produce varying behaviors that demonstrate the cloth's responsiveness to changes in these parameters.

Lower density cloth folds with larger folds, i.e. more loosely.
Low Ks makes the cloth softer and creates folds with smaller gaps.
High density cloth can't retain its shape as well and folds more randomly.
High Ks makes the cloth stiffer and creates folds with larger gaps.

Part V:Cloth Sim

Explain in your own words what is a shader program and how vertex and fragment shaders work together to create lighting and material effects.

A shader program is a set of specialized programs that run on a GPU, designed to manipulate vertex and pixel data to create various visual effects, such as lighting, texturing, and shading. Vertex shaders and fragment shaders work together in a shader program to generate these effects. The vertex shader processes individual vertices and can manipulate their position, color, and other attributes. The fragment shader, also known as the pixel shader, calculates the final color of each pixel based on the output from the vertex shader and other inputs, such as textures, lights, and material properties.

Explain the Blinn-Phong shading model in your own words. Show a screenshot of your Blinn-Phong shader outputting only the ambient component, a screen shot only outputting the diffuse component, a screen shot only outputting the specular component, and one using the entire Blinn-Phong model.

The Blinn-Phong shading model is a lighting model that approximates the appearance of surfaces by combining ambient, diffuse, and specular components. Ambient lighting represents the base level of light in the scene, independent of any light sources. Diffuse lighting depends on the angle between the surface normal and the light direction, simulating the scattering of light on a matte surface. Specular lighting creates shiny highlights on surfaces, depending on the angle between the viewer and the reflection of the light source. Provide screenshots of your Blinn-Phong shader outputting only the ambient component, only the diffuse component, only the specular component, and using the entire Blinn-Phong model.

Only Ambient lighting (very dark)
Only Diffuse lighting
Only Specular Lighting
Final combined Phong shader effect

Show a screenshot of your texture mapping shader using your own custom texture by modifying the textures in /textures/.

Show a screenshot of bump mapping on the cloth and on the sphere. Show a screenshot of displacement mapping on the sphere. Use the same texture for both renders. You can either provide your own texture or use one of the ones in the textures directory, BUT choose one that's not the default texture_2.PNG. Compare the two approaches and resulting renders in your own words. Compare how your the two shaders react to the sphere by changing the sphere mesh's coarseness by using -o 16 -a 16 and then -o 128 -a 128.

For this part, we exchanged the names of given textures 2 and 3 to generate a different rendering result from the bump/displacement shaders. Below is a side by side comparison of both shaders:

Bump Cloth
Bump Sphere
Displacement Cloth
Displacement Sphere

Then, we compared the render results with different coarseness of the sphere mesh. While this does not have a signficant impact on the bump shader, it does change the way the displacement are calculated in the displacement shader. When the sphere mesh is less coarse, the render result is "smoother" with less details of the displacement texture map, while more details are rendered when the sphere mesh is more coarse.

Bump shader with low coarseness
Displacement shader with low coarseness
Bump shader with high coarseness
Displacement shader with high coarseness

Show a screenshot of your mirror shader on the cloth and on the sphere.

Sphere.json with mirror shader