Skip to content
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
86 changes: 79 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,92 @@
CUDA Rasterizer
===============

[CLICK ME FOR INSTRUCTION OF THIS PROJECT](./INSTRUCTION.md)

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

* (TODO) YOUR NAME HERE
* Tested on: (TODO) Windows 22, i7-2222 @ 2.22GHz 22GB, GTX 222 222MB (Moore 2222 Lab)
* Jonathan Lee
* Tested on: Tested on: Windows 7, i7-7700 @ 4.2GHz 16GB, GTX 1070 (Personal Machine)

# Overview

In this project, I was able to implement a basic graphics pipeline in CUDA including the *Vertex Shading*, *Primitive Assembly*, *Rasterization*, and *Fragment Shading* stages.

![](renders/milktruck.PNG)

## Features
* UV Texture Mapping with Bilinear Filtering and Perspective Correct Coordinates
* Line and Point Rasterization
* Naive Backface Culling

## Flags
* `DRAWLINES`
* `DRAWPOINTS`
* `TEXTURE`
* `BILINEAR`
* `PERPSECTIVE_CORRECT`
* `MUTEX`

# Results

## Rasterization Types
### Duck
Textured | Triangles | Lines | Points
:-------------------------:|:-------------------------:|:-------------------------:|:-------------------------:
![](renders/duck_tri.PNG) | ![](renders/duck_diff.PNG) | ![](renders/duck_line.PNG) | ![](renders/duck_point.PNG) |

### Cesium Milk Truck
Textured | Triangles | Lines | Points
:-------------------------:|:-------------------------:|:-------------------------:|:-------------------------:
![](renders/milktruck_diff_texture.png) | ![](renders/milktruck_diff.png) | ![](renders/milktruck_line.png) | ![](renders/milktruck_point.png) |

## Texturing
### Perspective Correctness

Perspective correctness accounts for the vertex positions in 3D space rather than interpolating in screen space. This is where most of the overhead comes from in the rasterization step.

Without Perspective Correct Coordinates | With Perspective Correct Coordinates
:-------------------------:|:-------------------------:
![](renders/noperspective2.png) | ![](renders/perspective2.png)


### (TODO: Your README)

*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.
### Flickering

Having a lock for dealing with each specific pixel is fairly important. This prevents the flickering seen in the left gif. This is caused when two threads are working on the same pixel.

Without Locking | With Locking
:-------------------------:|:-------------------------:
![](renders/(no)mutex.gif) | ![](renders/mutex.gif)

# Analysis

Below is the data from rendering the Cesium Milk Truck model. Overall, the rasterization step takes the most time to process. This makes sense since all of the main computation occurs at this step.

#### Cesium Milk Truck

Having the mutex lock causes a slight overhead across the texture methods which is well worth the overhead.

![](images/milktruck_pipeline.png)

![](images/pipeline.PNG)

![](images/rasterization_types.png)

![](images/rastertype.PNG)

![](images/line_point.png)

Clearly, there is a huge dropoff between rasterizing triangles and lines and points. There are no calculations needed to rasterize points. To rasterize lines, `_rasterizeLine()` gets called three times to account for the three lines that make up the triangle: P1-P2, P2-P3, P3-P1. Using the slope, we can find the position along the line as we move from point to point.

### 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)

### References
* https://www.scratchapixel.com/lessons/3d-basic-rendering/rasterization-practical-implementation/perspective-correct-interpolation-vertex-attributes
* https://www.opengl.org/discussion_boards/showthread.php/170651-Is-it-possible-to-get-the-pixel-color
* https://stackoverflow.com/questions/35005603/get-color-of-the-texture-at-uv-coordinate
* https://en.wikipedia.org/wiki/Bilinear_filtering
* http://groups.csail.mit.edu/graphics/classes/6.837/F02/lectures/6.837-7_Line.pdf
* https://en.wikipedia.org/wiki/Back-face_culling

Binary file added images/chart.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 images/line_point.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 images/milktruck_pipeline.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 images/pipeline.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 images/rasterization_types.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 images/rastertype.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/(no)mutex.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/cow.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/duck.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/duck_diff.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/duck_line.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/duck_point.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/duck_tri.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/fail1.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/frontfaceculling.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/lines.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/milk.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/milk2.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/milktruck.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/milktruck_diff.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/milktruck_diff_texture.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/milktruck_diffuse.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/milktruck_line.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/milktruck_lines.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/milktruck_point.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/milktruck_points.PNG
Binary file added renders/milktruck_texture.PNG
Binary file added renders/mutex.gif
Binary file added renders/nobilinear.gif
Binary file added renders/noperspective.PNG
Binary file added renders/noperspective2.png
Binary file added renders/perspective.PNG
Binary file added renders/perspective2.png
Binary file added renders/uvindex.PNG
Loading