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: Kaixiang Miao #22

Open
wants to merge 13 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
100 changes: 93 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,104 @@
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)
* Kaixiang Miao
* Tested on: Windows 7, i7-3630QM @ 2.40GHz 8GB, GTX 660M 2GB (Lenovo Y580 laptop, personal computer)

### Screenshot

----------------

#### Perspective-correct Color Interpolation
<table class="image">
<tr>
<td>duck.gltf (Blinn-Phong)</td>
<td>cow.gltf (Blinn-Phong)</td>
<td>flower.gltf (Lambert)</td>
</tr>
<tr>
<td><img src="img/20.gif"/></td>
<td><img src="img/10.gif"/></td>
<td><img src="img/3.gif"/></td>
</tr>
</table>

#### Bilinear Texture Mapping
<table class="image">
<tr>
<td>duck.gltf</td>
<td>CesiumMilkTruck.gltf</td>
</tr>
<tr>
<td><img src="img/51.gif"/></td>
<td><img src="img/61.gif"/></td>
</tr>
</table>

#### Perspective-correct Texture Mapping
<table class="image">
<tr>
<td>Bad Mapping</td>
<td>Nice Mapping</td>
</tr>
<tr>
<td><img src="img/8.jpg"/></td>
<td><img src="img/81.jpg"/></td>
</tr>
</table>

#### Bilinear Texture Mapping
<table class="image">
<tr>
<td>Bilinear Off</td>
<td>Bilinear On</td>
</tr>
<tr>
<td><img src="img/tex.jpg"/></td>
<td><img src="img/bitex.jpg"/></td>
</tr>
</table>

#### Backface Culling
<table class="image">
<tr>
<td>Backface Culling Off</td>
<td>Backface Culling On</td>
</tr>
<tr>
<td><img src="img/71.gif"/></td>
<td><img src="img/7.gif"/></td>
</tr>
</table>

###Performance Analysis

#### Kernel Time of Different Stages

The kernel time of different stages of different .gltf files is shown as below. However, in spite of the fixed distance from the object, the objects have different scale factors, which make the stacked chart below less meanningful.

![](./img/Kernel.jpg)

Instead of comparing different objects, different distance from the object `duck.gltf` to the opsition of the camera is applied.

![](./img/Duck.jpg)

As the camera getting closer and closer, the rasterizer stage takes up more time. It illustrates that as the object taking up more and more area of the screen, the workload of the rasterizer becomes heavier because of the large area of primitives and more pixels needed to be filled by scanline.

The following graph shows the duration of the **fragment shader** of `duck.gltf`. Although the value is increasing, the ratio of this stage is decreasing, because of the steeper increase of the duration of the **rasterzier stage**. Besides, the duration of the **vertex shader**, the **primitive assembly** and the **backface culling** does not vary much because the number of vertices, primitives and backfaces is not relevant to the distance.

![](./img/DuckFrag.jpg)

#### Backface Culling

Backface Culling reduce lots of execution time of both fragment shader and the rasterizer stage.

### (TODO: Your README)
![](./img/backface.jpg)

*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.
With no backface culling, the stacked chart appears different from the one shown at the beginning. The rasterizer stage takes up most duration because the rasterizer is shading numerous redundant primitives.

![](./img/nobackface.jpg)

### Credits

Expand Down
Binary file added img/1.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/10.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/2.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/20.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/3.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/4.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/5.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/51.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/6.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/61.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/7.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/71.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/8.jpg
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/81.jpg
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.jpg
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/DuckFrag.jpg
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/Kernel.jpg
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/QQ截图20161027104041.jpg
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/QQ截图20161027125805.jpg
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/QQ截图20161027125842.jpg
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/QQ截图20161027130210.jpg
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/QQ截图20161027141341.jpg
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/QQ截图20161027194239.jpg
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/QQ截图20161027195451.jpg
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/QQ截图20161027195722.jpg
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/QQ截图20161027205430.jpg
Binary file added img/QQ截图20161027205528.jpg
Binary file added img/QQ截图20161027205938.jpg
Binary file added img/QQ截图20161027210034.jpg
Binary file added img/QQ截图20161027231940.jpg
Binary file added img/QQ截图20161028180142.jpg
Binary file added img/QQ截图20161028183459.jpg
Binary file added img/QQ截图20161028184002.jpg
Binary file added img/QQ截图20161028213137.jpg
Binary file added img/QQ截图20161028223323.jpg
Binary file added img/backface.jpg
Binary file added img/bitex.jpg
Binary file added img/fun0.jpg
Binary file added img/fun1.jpg
Binary file added img/nobackface.jpg
Binary file added img/tex.jpg
27 changes: 18 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,19 @@ void mainLoop() {
//---------RUNTIME STUFF---------
//-------------------------------
float scale = 1.0f;
float x_trans = 0.0f, y_trans = 0.0f, z_trans = -10.0f;
float x_angle = 0.0f, y_angle = 0.0f;
float x_trans = 0.0f, y_trans = 0.0f, z_trans = -5.0f;
float x_angle = 0.0f, y_angle = 0.0f;bool flag = false;int c = 0;
//float x_trans = 0.0f, y_trans = 0.0f, z_trans = -3.0f;
//float x_angle = 0.63f, y_angle = 3.19f;bool flag = false;int c = 0;
void runCuda() {
// Map OpenGL buffer object for writing from CUDA on a single GPU
// No data is moved (Win & Linux). When mapped to CUDA, OpenGL should not use this buffer
dptr = NULL;

glm::mat4 P = glm::frustum<float>(-scale * ((float)width) / ((float)height),
scale * ((float)width / (float)height),
-scale, scale, 1.0, 1000.0);

//y_angle += 0.01f;
//glm::mat4 P = glm::frustum<float>(-scale * ((float)width) / ((float)height),
// scale * ((float)width / (float)height),
// -scale, scale, 1.0, 1000.0);
glm::mat4 P = glm::perspective(3.14159f / 3, 1.0f, .1f, 1000.0f);
glm::mat4 V = glm::mat4(1.0f);

glm::mat4 M =
Expand All @@ -117,9 +119,16 @@ void runCuda() {
glm::mat3 MV_normal = glm::transpose(glm::inverse(glm::mat3(V) * glm::mat3(M)));
glm::mat4 MV = V * M;
glm::mat4 MVP = P * MV;

//printf("camera:%f %f %f\n", x_angle, y_angle, z_trans);
cudaGLMapBufferObject((void **)&dptr, pbo);
rasterize(dptr, MVP, MV, MV_normal);

//if (!flag)
{
rasterize(dptr, MVP, MV, MV_normal, c);
c++;
flag = true;
}

cudaGLUnmapBufferObject(pbo);

frame++;
Expand Down
Loading