CS 184: Computer Graphics and Imaging, Spring 2023

Project 4: Cloth Simulator

JIAN YU, XIAOYU ZHU

Overview

In Project 4 of CS 184, we created a realistic cloth simulator. Our implementation involved constructing a mesh of interconnected point masses, handling collisions with spheres and planes, and preventing self-collisions for a natural draping effect. Using shaders, we achieved realistic rendering under various lighting conditions.

Part 1: Masses and springs

Comparison image with low and high ks:

low ks(1e-05)high ks(1e05)

Comparison image with low and high density:

low density(1)high density(10000)

Comparison image with low and high damping:

low damping(0)high damping(1)

Images of default state

Part 3: Handling collisions with other objects

cloth on sphere with different ks(500,5000,50000)

Screenshot of falling cloth

Screenshot of falling and rest state with different ks and density

ks = 5000, d = 1
ks = 5000, d = 100
ks = 75000, d = 15
ks = 10, d = 15
ks = 5e+6, d = 100

Density

Spring Constant (ks)

Combined Effects

LowLowVery soft flowing fabric, collapses readily, loose folds.
DensityksBehavior
LowHighLightweight, but less elastic. Forms more open folds.
HighLowHeavy fabric that stretches and compresses easily. Thick, bunched up folds.
HighHighStiff and heavy, drapes in large open folds, minimal collapse on itself.

An additional observation is that when ks and density change proportionally at the same time, the behavior of the cloth is very similar. We believe the reason is that the main force determining the shape of the cloth is the internal elastic force, rather than gravity or other external forces. Force affects the motion behavior of an object by affecting its acceleration. When ks and density change proportionally, their effects on acceleration cancel each other out, resulting in similar behavior of the cloth. We have confirmed that the images are not misplaced, they are indeed very similar :)

Part 5: shaders

Shader description

A shader program is a piece of code written in a specialized shading language, like GLSL that runs on the GPU . Its purpose is to determine how each pixel (fragment) or vertex of a 3D object should be rendered on the screen.

Vertex shaders are responsible for processing each vertex of a 3D object. They manipulate the position, color, texture coordinates, and other properties of vertices. For instance, they can transform the 3D coordinates of vertices into 2D screen coordinates for rendering on the screen. They can also calculate lighting effects at each vertex.

Fragment shaders, also known as pixel shaders, operate on individual pixels of the rendered image. They determine the final color of each pixel based on various factors such as lighting, textures, and material properties. Fragment shaders calculate the final color by interpolating values from the vertices, applying lighting calculations, texture sampling, and other effects.

Together, vertex and fragment shaders form the core of the rendering process. Vertex shaders prepare the geometry for rendering by transforming vertices, while fragment shaders determine the final appearance of each pixel on the screen by calculating lighting and material effects. By working together, they enable the GPU to efficiently render complex 3D scenes with realistic lighting and materials.

Explaination of Blinn-Phong model

In Blinn-Phong shading, each pixel's color is determined by considering three main components: ambient, diffuse, and specular lighting.

Texture mapping shader

It's a photo of us during spring break haha:)

Bump mapping screenshots(using texture_3 provided)

Displacement mapping on sphere:

Comparison of Bump/Displacement coarseness

-o 16 -a 16-o 128 -a 128

Mirror shader on cloth and sphere