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
156 changes: 148 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,159 @@
CUDA Rasterizer

===============

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

[CLICK ME FOR INSTRUCTION OF THIS PROJECT](./INSTRUCTION.md)
* Henry Zhu
* [Github](https://github.com/Maknee), [LinkedIn](https://www.linkedin.com/in/henry-zhu-347233121/), [personal website](https://maknee.github.io/), [twitter](https://twitter.com/maknees1), etc.
* Tested on: Windows 10 Home, Intel i7-4710HQ @ 2.50GHz 22GB, GTX 870M (Own computer)

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

![](cuda_strike.gif)

- * Reference to the First Person shooter [Counter Strike](https://en.wikipedia.org/wiki/Counter-Strike)
- * Not very accurate of a first person shooter, but the enemies are ducks and pressing the left button deletes them :)

![](truck1.png)
![](truck2.png)
![](truck3.png)
![](truck4.png)
![](truck5.png)

## What is a rasterizer?

A rasterizer is a method of rendering images by forming triangles and converting these triangles to pixels on the screen

In more detail, a rasterizer has a so called graphics pipeline where points from an object's data file are converted to points in the screen space and triangles are formed from three points. From these triangles, an AABB check if performed around the triangles to see what approximate rectangular area the triangle takes up. Then, a scanline method is performed where the rasterizer iterates through all pixels in the AABB A barycentric calculation is performed to check if the pixel is actually in the triangle. If the pixel is, a depth test is checked and if that passes, the pixel(fragment)'s color can be modified from all cool effects such as colors, lights, etc.

## Building / Usage

### Building
- Build using cmake or cmake-gui
- Open sln project in visual studio

### Running

- ./cis565_rasterizer.exe ..\gltfs\duck\duck.gltf

## Basic features
- Entire graphics pipeline
- Lambert shading and blinn-phong shading
- Depth testing

## What advanced features of my rasterizer implement?

- The rasterizer can be actually used to play a game and loads Multiple objects :)
- UV texture mapping with bilinear texture filtering and perspective correct texture coordinates
- Correct color interpolation between points on a primitive
- Backface culling, optimized using stream compaction (with thrust)

## UV texture mapping

### UV texture mapping

![](duck_map.png)

### UV texture mapping evaluation

This feature consists of mapping textures onto an object with bilinear filtering and perspective correct texture coordinates.

Bilinear filtering is sampiling four (u,v)s on a texture and mixing the two based on where the u,v is mapped to on the pixel.

Perspective correct texture coordinates can be done by using a combination of barycentric coordinates and eye coordinates to change the texture color to map to the correct values based on eye position.

#### Performance

The performance did not take too much of a hit. The fps decreased by about a fifth compared to just using colors, but fps is measured as the inverse of the time per frame. The bilinear filtering usage vs not using bilinear filtering causes a slight performance hit.

#### Future optimizations

An optimization is to precompute the texture values color mapping to the object's triangle points, so that when the camera is moved, all that is needed to be done to color perspective correwct the texture color values. This takes up space, however.

Another way to optimize is not move the camera and save all the texture colors in a buffer that changes when the camera is moved. When the camera is not moving, there is no work to be done.

## Correct color interpolation between points on a primitive

![](triangle_color.png)
![](checkerboard_color.png)

### Color interpolation evaluation

Color interpolation is done by correct the color based on baycentric coordinates and the eye's position. This is like mixing the colors between different points as shown in the triangle image.

#### Performance

The performance is not noticable at all. All that was done was add a couple more multiplications and divisions to correctly interpolate color between points

#### Future optimizations

There are not many optimizations as this is multiplying baycentric coordinates to the pixel value and camera values, but one way to speed things up would be to add a cache that maps the baycentric value to different points on a triangle and to compute the pixel value quickly by fetching the baycentric value quickly.

- Backface culling, optimized using stream compaction (with thrust)

![](backface-culling-graph.png)

### Backface culling evaluation

Backface culling is the technique of removing faces that are not facing towards the camera. This can be done by getting the triangles' normals and dotting that with the camera forward vector. With stream compaction, the primitives can be removed from being calcuated for the screen since the triangles are facing away from the user.

#### Performance

This was a performance hit since triangles facing away from the user are not used in computation and in the end, thrown away. This resulted in a 2x speedup for the duck since half of its triangles were facing away from the camera.

#### Future optimizations

This is an optimization already since this technique removed triangles not facing the same direction as the user.

But, a way to speed things up is to keep a track of triangles not facing the user and cache that, so stream compaction is used on a smaller part of the total number of primitives

- Performance Analysis

Chart of each pipeline stage

![](performance.png)

* (TODO) YOUR NAME HERE
* (TODO) [LinkedIn](), [personal website](), [twitter](), etc.
* Tested on: (TODO) Windows 22, i7-2222 @ 2.22GHz 22GB, GTX 222 222MB (Moore 2222 Lab)
Data in nano seconds

### (TODO: Your README)
```
Triangle
Vertex Assembly and Shader 236885
Primitive Assembly 80467
Rasterizer 1826779
Rasterizer with texture mapping 0
Rasterizer with backface culling 1638904
Fragment shader 1132289

Duck
Vertex Assembly and Shader 289846
Primitive Assembly 160934
Rasterizer 0
Rasterizer with texture mapping 3824242
Rasterizer with backface culling 3632737
Fragment shader 1105604

Cow
Vertex Assembly and Shader 534122
Primitive Assembly 163808
Rasterizer 6801853
Rasterizer with texture mapping 0
Rasterizer with backface culling 6472184
Fragment shader 1110119

Flower
Vertex Assembly and Shader 468434
Primitive Assembly 149029
Rasterizer 4718007
Rasterizer with texture mapping 0
Rasterizer with backface culling 4325114
Fragment shader 1165544
```

*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.
## Third party usage

### Book
- [PBRT](https://www.pbrt.org/)

### Credits

Expand Down
Binary file added backface-culling-graph.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 checkerboard_color.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 cuda_strike.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 duck_map.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 performance.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading