Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project5: Keyi Yu #15

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions 92834c4ad142a5899caf4fcbaed2cc2672a7e20a
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
commit 68388017d3203cb9550402e8886607ed93829b46 (HEAD -> master)
Author: lindayukeyi <[email protected]>
Date: Fri Oct 30 21:14:40 2020 -0400

readme

commit 9a43ab04b16382dbd0e7ed0cc7c403fd7b187919
Author: lindayukeyi <[email protected]>
Date: Fri Oct 30 20:59:06 2020 -0400

readme

commit 92834c4ad142a5899caf4fcbaed2cc2672a7e20a
Author: lindayukeyi <[email protected]>
Date: Fri Oct 30 20:53:01 2020 -0400

readme

commit 60ec8a9836cc8e71205bdb37af2f3c37b7f2ab06 (origin/master, origin/HEAD)
Author: lindayukeyi <[email protected]>
Date: Fri Oct 30 14:37:47 2020 -0400

finish

commit 1e22370c3457f2d4f79951bcf7bcd36585b05674
Author: Kangning Li <[email protected]>
Date: Wed Oct 21 11:37:00 2020 -0400

clarify gh-pages instructions

commit b4078bce43ee5d0da0840423b5150817c89aa3b7
Author: Kangning Li <[email protected]>
Date: Wed Oct 21 11:19:12 2020 -0400

add wireframe class for visual debugging

commit 135113b667520e0373c833b8a588f27271a981d8
Author: Kangning Li <[email protected]>
Date: Tue Oct 20 20:22:38 2020 -0400

update some terminology, pin packages

commit 22ed7d5ea573c698bc4345dbd2a8a39aa6e3e44a
Author: Kangning Li <[email protected]>
Date: Tue Oct 20 17:11:28 2020 -0400

add Hannah Bollar's updates for fall 2019 npm webpacks

commit 621051d440edd592d1f03f8403ec08c57eaf521f
Author: Ottavio M. Hartman <[email protected]>
Date: Wed Oct 17 13:29:11 2018 -0400

Update Instructions

commit 32ba1b6ed5b0bc8966dd54b5cf2f2500da0cc642
Merge: e0e02e2 59445f2
Author: Ottavio M. Hartman <[email protected]>
Date: Tue Oct 16 23:30:36 2018 -0400

Merge pull request #1 from CIS565-Fall-2018/update_2018

Update filenames, instructions, and variables with clearer language

commit 59445f2bbcd5061355d824e0fe69c85c1db48a26
Author: Ottavio Hartman <[email protected]>
Date: Tue Oct 16 23:25:25 2018 -0400

Update filenames, instructions, and variables with clearer language

commit e0e02e20d7ea8a421e12274e67cd237de81737c8
Author: Austin Eng <[email protected]>
Date: Thu Oct 19 15:38:08 2017 -0400

Update build system for production

commit c5cdb49e83aed951e631da86d16e090aaf34e24a
Author: Austin Eng <[email protected]>
Date: Thu Oct 19 12:38:09 2017 -0400

Add due date

commit d7caa9574ffcb66d4dcf9839bacb7128522cdb03
Author: Austin Eng <[email protected]>
Date: Thu Oct 19 12:32:48 2017 -0400

Add README.md

commit 5476fb233088810bcbc983c5faa3ecf513df5d6d
Author: Austin Eng <[email protected]>
Date: Thu Oct 19 12:29:08 2017 -0400

Initial base code
90 changes: 80 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,95 @@ WebGL Forward+ and Clustered Deferred Shading

**University of Pennsylvania, CIS 565: GPU Programming and Architecture, Project 5**

* (TODO) YOUR NAME HERE
* Tested on: (TODO) **Google Chrome 222.2** on
Windows 22, i7-2222 @ 2.22GHz 22GB, GTX 222 222MB (Moore 2222 Lab)
* Keyi Yu
* [LinkedIn](https://www.linkedin.com/in/keyi-linda-yu-8b1178137/)
* Tested on: Windows 10, i7-10750H @ 2.60GHz 16GB, GeForce RTX 2070 with Max-Q 8228MB (My Machine)

### Live Online

[![](img/thumb.png)](http://TODO.github.io/Project5-WebGL-Forward-Plus-and-Clustered-Deferred)
[![](img/bf.png)](https://lindayukeyi.github.io/Project5-WebGL-Forward-Plus-and-Clustered-Deferred/)

### Demo Video/GIF

[![](img/video.png)](TODO)
![](img/demo2.gif)

### (TODO: Your README)
### Introduction

*DO NOT* leave the README to the last minute! It is a crucial part of the
project, and we will not be able to grade you without a good README.
In this project, I implemented the foward+ and deferred shading. These two methods are optimized with the clustering method. In terms of the number of ligths in the scene, light radius and tile size, each method has its limitations. In addition, I implemented the Blinn-Phong and toon shading for interesting visulization. I also used 2-component normal to reduce the number of gbuffers.

### Features
**Clustered Rendering**

The basic idea of clustering is deviding the frustum into x * y * z 3D clusters and assigning the lights to those clusters. In this way, we can easily get all the lights instead of iterating every lights in the fragment shader. One tricky thing here is to check the intersection of the clusters and point light. The clusters are the small frustums with different sizes.

**Forward+ shading**

In forward+ fragment shader, I have to invert the fragment coordinate to the indices of clusters. Then I get some information from the texture buffer like the number of lights in a cluster and their indices.

**Deferred Shading**

Deferred shading has two steps. The first step is to write position, color and normal information to a g-buffer. The second step is to find light in clustered texture and then do light shading.

Albedo | Normal | Position
:-------------------------:|:-------------------------:|:-------------------------:
![](img/alb.png) | ![](img/nor.png) | ![](img/pos.png)

**Blinn-phong**

This is a common specular lighting model.
```
S = max(dot(H, N), shininess), 0) * specular color, where H = (V + L) / 2
final color = ambient + S
```

No Blinn-Phong | Blinn-Phong
:-------------------------:|:-------------------------:
![](img/nobf.png) | ![](img/bf.png)

**Toon shading**

I tried toon shading. It has two parts: ramp shading and edge detection. I use sobel filter to convolve depth to find the edge. If the current fragment is an edge, it will be colored line color, otherwise, it should be rendered a ramp color. I followed this [repo](https://github.com/mchamberlain/Cel-Shader) to ramp the color.

![](img/toon.png)

**2-component Normal**

Instead of using an extra vec4 g-buffer to store the normal information. I pack the information like this
```
vec4 gb0 = vec4(position, normal.x);
vec4 gb1 = vec4(col, normal.y)
```
Because the length of a normal is 1, I can extract the z value from x and y value by calulating the square root of (1 - x^2 - y^2). Bacause the value of color is always positive, I use the color information to represent the sign of z value. If the color value is negative, I will multiply the square root by -1.0.

### Performance Analysis
**Forward(F) vs Forward+(F+) vs Deferred Clustering(DC)**
1. Number of lights

In every test, the performance is the same: DC > F+ > F. As the number of lights increases, DC greatly outperforms the other two. In the first graph, DC and F
\+ are not affected by the number of lights because the max number of lights in the cluster is a constant. In contrast, as shown in the second graph, if the max number of lights in a cluster changes along with the number of lights, DC and F+ will also be similarly impacted but they will increase at a slower rate.

![](img/performance100.png)

![](img/performance.png)

2. Tiles

Since large tiles can have more lights, each fragment will check more lights. Small tiles also have more memory usage since each has a light of indices for overlapping lights.

![](img/tile.png)

3. Light raduis

F wins this time. F is not impacted by the radius of light but F+ and DC are greatly impacted. As the raduis increases, F+ and DC slows down. When the raduis is 20, F outperforms F+. The reason why they slow down is that each cluster will have more lights which means the fragment have to check more lights.

![](img/lightradius.png)

**2-Component normal**

The optimized 2-component normal is slightly better than the 3-component one. Although we can save some memory space and data transfer time, it will cost some time to do the float-pointing computation. I just use a straightforward method to compute the z value from x and y using square root. So the result is a little bit blotchy. I could use a more complex encoding and decoding algorithm and I guesss this will cost more time.

![](img/normal.png)

This assignment has a considerable amount of performance analysis compared
to implementation work. Complete the implementation early to leave time!


### Credits
Expand Down
Binary file added img/alb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/bf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/blinphong.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/demo2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/lightradius.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/nobf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/nor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/performance.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/performance100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/pic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/pos.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/tile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/toon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading