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

Project 4: David Liao #13

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ef6c952
kernels
Oct 22, 2016
57c88ef
why is this not loading
Oct 22, 2016
3047ce2
got things showing
Oct 23, 2016
66837b6
z-buffer
Oct 25, 2016
2fb53c5
progress on shader
Oct 25, 2016
55b3999
yay rasterizer base pipeline done
Oct 26, 2016
9348cf6
baseline close enough
Oct 26, 2016
585d5b9
texture mapping complete
Oct 28, 2016
a31e44a
backface culling
Oct 28, 2016
4e38d81
NPR oil painting yay
Oct 28, 2016
97dea72
npr shadingbuild/Release/cis565_rasterizer.exe gltfs/CesiumMilkTruck/…
Oct 28, 2016
cb812bd
renders and gifs
Oct 28, 2016
48d245a
Update README.md
davlia Oct 28, 2016
c06146f
Update README.md
davlia Oct 28, 2016
08700cc
Add files via upload
davlia Oct 28, 2016
0b9aca5
Update README.md
davlia Oct 28, 2016
d72095b
Update README.md
davlia Oct 28, 2016
18da31a
Update README.md
davlia Oct 28, 2016
ca3d28b
Update README.md
davlia Oct 28, 2016
007e40c
Update README.md
davlia Oct 28, 2016
e35d565
Update README.md
davlia Oct 28, 2016
4b263d0
Update README.md
davlia Oct 28, 2016
5e2f41e
Update README.md
davlia Oct 28, 2016
5c966af
Update README.md
davlia Oct 28, 2016
76fd763
Update README.md
davlia Oct 28, 2016
32066c6
Update README.md
davlia Oct 28, 2016
d72ae2d
Update README.md
davlia Oct 28, 2016
0421ddb
Update README.md
davlia Oct 28, 2016
296b46a
Add files via upload
davlia Oct 28, 2016
50884a5
Update README.md
davlia Oct 28, 2016
188db1a
Update README.md
davlia Oct 28, 2016
7325d8d
Update README.md
davlia Oct 28, 2016
5751e9e
Update README.md
davlia Oct 28, 2016
657540f
Add files via upload
davlia Oct 29, 2016
db65688
Update README.md
davlia Oct 29, 2016
fe95093
Update README.md
davlia Oct 29, 2016
805450f
Update README.md
davlia Oct 29, 2016
fa58b05
final commit
Oct 29, 2016
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
62 changes: 55 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,68 @@
CUDA Rasterizer
===============
**University of Pennsylvania, CIS 565: GPU Programming and Architecture, Project 4**

[CLICK ME FOR INSTRUCTION OF THIS PROJECT](./INSTRUCTION.md)
* David Liao
* Tested on: Tested on: Windows 7 Professional, Intel(R) Xeon(R) CPU E5-1630 v4 @ 3.70 GHz 3.70 GHz, GTX 1070 8192MB (SIG Lab)

**University of Pennsylvania, CIS 565: GPU Programming and Architecture, Project 4**
![](renders/demo.gif)

### Rasterizer
A rasterizer takes a scene described in 3d space and maps it to a 2d space for output to a screen. It differs from a ray tracing in that no rays are fired from the camera to intersect with geometry. Rather the geometry (usually composed of triangles) has its vertices projected onto a screen with perspective correct transformations and then shaded in appropriately. A depth buffer (or z-buffer) is used to keep track of which triangles are on top of others. The above gif demonstrates the basic properties of a rasterizer.

### Main Features
* Basic rasterizer implementation
* Lambert Shading
* Texture mapping with perspective correct tranformation and bilinear interpolation
* Backface culling with stream compaction
* NPR shading (Oil painting)

### Pipeline
* Buffer initialization
* Vertex Shading
* Primitive assembly
* Rasterization
* Texture loading
* NPR Shading
* Fragment Light Shading
* Framebuffer writing

### Texture Mapping
#### UV Mapping
The rasterizer transforms the 2d space into uv texture space and reads from the loaded textures to determine fragment color.
<img src="renders/texture_ducky.PNG" width="400" height="400"/>

#### Perspective Correct Transformation
If we naively interpolate the texture coordinates by using the barycentric weights, we'll end up with a distortion unless we take into account our perspective. The below effect demonstrates the affine (left) vs perspective correct transformations (right).
<img src="renders/affine.PNG" width="400" height="400"/>
<img src="renders/perspective_correct.PNG" width="400" height="400"/>
#### Bilinear Interpolation
Sometimes sampling the textures leaves us with rough-edged textures (left). As a result, we sample adjacent textures and interpolate the texture color (right). As a result, we introduce a bit of blurriness and take a hit in performance but remove jarring edges.

<img src="renders/texture_checker.PNG" width="400" height="400"/>
<img src="renders/bilinear_checker.PNG" width="400" height="400"/>


### Backface Culling
Backface culling involves a preprocessing step that determines whether a triangle is visible in the perspective of the viewer. This is determined by the chirality of the triangle primitives. If they are counter-clockwise when a front-facing triangle should be clockwise, then we can ignore that triangle. We also perform a stream compaction to ensure that all primitives that are culled are not accounted for in our kernel launches. Furthermore, depending on the perspective of the camera, more or less polygons will be culled. Below demonstrates the percentage of culled primitives from a side-view perspective (default perspective when launched). It was hard to determine the exact performance impact in terms of frames per second due to the strong processing capabilities of a 1070 card (everything was maxing out at 60 frames!). My hypothesis would be that the impact would be a linear improvement with respect to the culled primitives. See Performance Analysis section for more detailed analysis on the impact of backface culling on the rasterize step in the pipeline!

* (TODO) YOUR NAME HERE
* Tested on: (TODO) Windows 22, i7-2222 @ 2.22GHz 22GB, GTX 222 222MB (Moore 2222 Lab)
<img src="renders/Capture.PNG" />
### Non-Photorealistic Rendering (NPR)
Before the final step in calculating the lighting of each fragment, we manipulate our fragment buffer by applying a NPR filter over it. In our case, we apply an oil painting effect onto our rasterized image. For each pixel, we search in a radius around it and cache all color intensities (determined by avg RGB value from 0-255). By caching all color intensities, we map them to the sum of all nearby RGB values of each intensity band. We then select the mode intensity and average all RGB values and set that pixel to the averaged RGB value. The parameters INTENSITY controls the blockyness of the filter and the RADIUS tunes the size of the "brush". The current settings for the pictures below are set to a radius of 4 and intensity of 25. We also vandalized the Cesium car a bit to demo the effect a bit better :).

### (TODO: Your README)
<img src="renders/oilpainting2.png" width="400" height="300"/>
<img src="http://cdn.pcwallart.com/images/maple-leaf-wallpaper-3.jpg" width="400" height="200"/>

*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.
### Performance Analysis
The vast majority of the time is taken up by the NPR shader since it performs a lookup to nearby fragments in the fragment buffer. As a result, it hits global memory pretty frequently, thus taking up a large chunk of compute time. I believe using shared memory here would benefit the algorithm greatly as the algorithm is solely based on the locality of the fragments. Time permitting, I will probably implement shared memory version of the shader at a later date. Backface culling, despite removing a large number of primitives, still only improves rasterization speed by ~9% in the ducky scene and ~4% in the cesium truck scene. Texture loading is relatively fast, and all other assembly/transfer kernels are relatively fast. The bottleneck which I had hoped culling would relieve was rasterization but the improvement seems to be minimal.

<img src="renders/analysis4.png" width="400" height="300"/>
<img src="renders/analysis1.png" width="400" height="300"/>
<img src="renders/analysis3.png" width="400" height="300"/>
<img src="renders/analysis2.png" width="400" height="300"/>

### Credits

* [tinygltfloader](https://github.com/syoyo/tinygltfloader) by [@soyoyo](https://github.com/syoyo)
* [glTF Sample Models](https://github.com/KhronosGroup/glTF/blob/master/sampleModels/README.md)
* [NPR Oil Painting Effect](http://www.codeproject.com/Articles/471994/OilPaintEffect)
Binary file modified gltfs/CesiumMilkTruck/CesiumMilkTruck.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 renders/Capture.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 renders/affine.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 renders/analysis1.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 renders/analysis2.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 renders/analysis3.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 renders/analysis4.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 renders/bilinear_checker.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 renders/blooper1.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 renders/demo.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 renders/oilpainting.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 renders/oilpainting2.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 renders/p1.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 renders/p2.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 renders/p3.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 renders/p4.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 renders/perspective_correct.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 renders/texture_checker.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 renders/texture_ducky.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading