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: Ziyu Li #9

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
init commit
 - Update All Features
 - Update Images
 - Update README
ziyuli committed Oct 15, 2017
commit 4ae23a6839a2d493299fad9393b1c4e399530c2d
102 changes: 93 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,102 @@
CUDA Rasterizer
===============
University of Pennsylvania, CIS 565: GPU Programming and Architecture, Project 4 CUDA Rasterizer
======================
* Ziyu Li
* Tested on: Windows 7, Intel Core i7-3840QM @2.80GHz 16GB, Nvidia Quadro K4000M 4GB

[CLICK ME FOR INSTRUCTION OF THIS PROJECT](./INSTRUCTION.md)
## Features
#### All Features
- All Basic Graphics Pipeline
- Vertex Shading
- Primitive assembly with support for triangles read from buffers of index and vertex data.
- Rasterization
- Fragment shading
- Depth Buffer and Depth Test
- Lambert and Blinn shading Model
- Other Features
- High Precision Float z buffer
- Screen Space Ambient Occlusion (SSAO)
- Super-Sampling Anti Aliasing (SSAA)
- Tile-Based Pipeline
- Back-face Culling
- Display Wire-frame / Points with line width and point size adjustment
- UV Texture Mapping with Perspective Correction
- Bilinear Texture Filter
- Toon Shading
- Bloom (Still has some bugs...)

**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)
For better result, all the images demonstrate below are using SSAA 2x

### (TODO: Your README)
#### Shading Models
| Lambert | Blinn |
| ----- | ----- |
| ![lambert](img/duck_lambert.gif) | ![blinn](img/duck_blinn.gif) |

*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.
#### Tile-Based Pipeline
| Primitive-Based | Tile-Based |
| ----- | ----- |
| ![prim](img/truck_prim_base.gif) | ![tile](img/truck_tile_base_backface.gif) |

For details performance comparison, please check *Performance* Section.

#### Back-face Culling
| No Culling | Back-face Culling |
| ----- | ----- |
| ![noculling](img/truck_prim_base.gif) | ![culling](img/truck_prim_base_backface.gif) |

For details performance comparison, please check *Performance* Section.

#### Display Wire-frame / Points
| Solid | Wire-frame | Points|
| ----- | ----- | ----- |
| ![solid](img/duck_no_wire_point.PNG) | ![wire](img/duck_wireframe.PNG) | ![point](img/duck_point.PNG) |

#### UV Texture Mapping with Perspective Correction

| Wrong | Correct|
| ----- | ----- |
| ![texw](img/tex_wrong.PNG) | ![texr](img/tex_right.PNG) |

#### Bilinear Texture Filter

| No Filter | Bilinear Filter |
| ----- | ----- |
| ![nof](img/truck_no_bilinear.PNG) | ![f](img/truck_bilinear.PNG) |

#### Screen Space Ambient Occlusion (SSAO)


| No AO | SSAO | SSAO Pass |
| ----- | ----- | ----- |
| ![no ao](img/truck_lambert_noao.PNG) | ![ssao](img/truck_lambert_ao.PNG) | ![ssaopass](img/truck_ao_pass.PNG) |


**Noise Texture Generation**
![noise](img/noise.PNG)

**SSAO Pass Render**
![aoaa](img/truck_ao_pass_ani.gif)

#### Super-Sampling Anti Aliasing (SSAA)

| No AA | SSAA x2 | SSAA x4|
| ----- | ----- | ----- |
| ![no aa](img/duck_no_aa.PNG) | ![ssaa2](img/duck_aa.PNG) | ![ssaa4](img/duck_aa4.PNG) |


#### Toon Shading
| Orignal | Toon Shading |
| ----- | ----- |
| ![lambert](img/duck_lambert.gif) | ![toon](img/duck_lambert_toon.gif) |


#### Bloom (BUGGE......)
| Orignal | Bloom |
| ----- | ----- |
| ![lambert](img/img/duck_lambert.gif) | ![bloom](img/duck_blinn_bloom.gif) |


##Performance

### Credits

Binary file added img/duck_aa.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/duck_aa4.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/duck_blinn.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/duck_blinn_bloom.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/duck_lambert.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/duck_lambert_toon.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/duck_no_aa.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/duck_no_wire_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 img/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 img/duck_wireframe.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/noise.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/tex_right.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/tex_wrong.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/truck_ao_pass.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/truck_ao_pass_ani.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/truck_bilinear.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/truck_lambert_ao.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/truck_lambert_noao.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/truck_no_bilinear.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/truck_prim_base.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/truck_prim_base_backface.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/truck_tile_base_backface.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -120,7 +120,7 @@ void runCuda() {
glm::mat4 MVP = P * MV;

cudaGLMapBufferObject((void **)&dptr, pbo);
rasterize(dptr, MVP, MV, MV_normal);
rasterize(dptr, MVP, MV, MV_normal, frame);
cudaGLUnmapBufferObject(pbo);

frame++;
@@ -138,8 +138,8 @@ bool init(const tinygltf::Scene & scene) {
return false;
}

width = 800;
height = 800;
width = 512;
height = 512;
window = glfwCreateWindow(width, height, "CIS 565 Pathtracer", NULL, NULL);
if (!window) {
glfwTerminate();
714 changes: 674 additions & 40 deletions src/rasterize.cu

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/rasterize.h
Original file line number Diff line number Diff line change
@@ -16,9 +16,10 @@ namespace tinygltf{
class Scene;
}

static float _time;

void rasterizeInit(int width, int height);
void rasterizeSetBuffers(const tinygltf::Scene & scene);

void rasterize(uchar4 *pbo, const glm::mat4 & MVP, const glm::mat4 & MV, const glm::mat3 MV_normal);
void rasterize(uchar4 *pbo, const glm::mat4 & MVP, const glm::mat4 & MV, const glm::mat3 MV_normal, float time);
void rasterizeFree();
17 changes: 17 additions & 0 deletions src/rasterizeTools.h
Original file line number Diff line number Diff line change
@@ -88,6 +88,23 @@ bool isBarycentricCoordInBounds(const glm::vec3 barycentricCoord) {
barycentricCoord.z >= 0.0 && barycentricCoord.z <= 1.0;
}

__host__ __device__ static
bool isBarycentricCoordOnBounds(const glm::vec3 barycentricCoord) {
if (glm::abs(1 - glm::abs(barycentricCoord.x + barycentricCoord.y)) <= 0.07f && glm::abs(barycentricCoord.z) <= 0.07f) return true;
if (glm::abs(1 - glm::abs(barycentricCoord.y + barycentricCoord.z)) <= 0.07f && glm::abs(barycentricCoord.x) <= 0.07f) return true;
if (glm::abs(1 - glm::abs(barycentricCoord.z + barycentricCoord.x)) <= 0.07f && glm::abs(barycentricCoord.y) <= 0.07f) return true;
return false;
}

__host__ __device__ static
bool isBarycentricCoordOnCorner(const glm::vec3 barycentricCoord) {
if (glm::abs(1 - glm::abs(barycentricCoord.x)) < 0.11f && glm::abs(barycentricCoord.y) < 0.11 && glm::abs(barycentricCoord.z) < 0.11) return true;
if (glm::abs(1 - glm::abs(barycentricCoord.y)) < 0.11f && glm::abs(barycentricCoord.x) < 0.11 && glm::abs(barycentricCoord.z) < 0.11) return true;
if (glm::abs(1 - glm::abs(barycentricCoord.z)) < 0.11f && glm::abs(barycentricCoord.y) < 0.11 && glm::abs(barycentricCoord.x) < 0.11) return true;
return false;
}


// CHECKITOUT
/**
* For a given barycentric coordinate, compute the corresponding z position