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
4 changes: 4 additions & 0 deletions PROJ4_WIN/565Rasterizer/565Rasterizer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@
<CompileOut>$(ProjectDir)$(Platform)/$(Configuration)/%(Filename)%(Extension).obj</CompileOut>
<Include>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include;C:\ProgramData\NVIDIA Corporation\CUDA Samples\v5.5\common\inc;../shared/glew/include;../shared/freeglut/include;%(AdditionalIncludeDirectories)</Include>
</CudaCompile>
<CustomBuildStep>
<Command>
</Command>
</CustomBuildStep>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
Expand Down
1,212 changes: 901 additions & 311 deletions PROJ4_WIN/src/rasterizeKernels.cu.deps

Large diffs are not rendered by default.

238 changes: 92 additions & 146 deletions README.md

Large diffs are not rendered by default.

132 changes: 132 additions & 0 deletions README.md.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
-------------------------------------------------------------------------------
CIS565: Project 4: CUDA Rasterizer
-------------------------------------------------------------------------------
Fall 2013
-------------------------------------------------------------------------------
Due Thursday 10/31/2012
-------------------------------------------------------------------------------

I got really busy these weeks: 2 onsite interviews in Bay area. Thus I did not have enough time to deal with this project, and just implement something that is not as impressive as the last 3 projects.
Hopefully I'll try more after I got some free moment.

-------------------------------------------------------------------------------
IMPLEMENTED FEATURES
-------------------------------------------------------------------------------

In this project, I implemented 4 features as listed: anti-aliasing, color interpolation, back-culling and mouse interaction. Besides, I added normal interpolation feature so that it can show some smooth models.

---
Anti-Aliasing
---

Anti-aliasing is simple: it rasterize on another depthbuffer with doubled width and height, and doing everything as normal. And the fragment shader is also processed on this larger depthbuffer.
After the fragment shader, it will merge the color of each tile, with size of 2*2, into 1 pixel and write it to the depth buffer, and then render it and output it to the screen.

![screenshot](https://github.com/heguanyu/Project4-Rasterizer/blob/master/bmps/anti-aliasing.png?raw=true)

---
Color interpolation
---

I'm not quite sure if it is the "Correct color interpretation between points on a primitive", just do it as same as interpolating the depth. I'll illustrate the interpolation method later.
So color interpolation is similar, using the color of each vertex, and then interpolate them.

![screenshot](https://github.com/heguanyu/Project4-Rasterizer/blob/master/bmps/color_interpolation.png?raw=true)
---
Normal Interpolation
---

THANKS TO Nathan Marshak 's post on the google group, the smooth cow looks brilliant!
![screenshot](https://github.com/heguanyu/Project4-Rasterizer/blob/master/bmps/normal_interpolation.png?raw=true)

---
MOUSE INTERACTION
---

Instead of a pure camera-interaction, this mouse interaction include both camera and mesh interaction.

*When pressing LEFT mouse button
*Move up: mesh zoom in(scale larger)
*Move down: mesh zoom out(scale smaller)
*When pressing MIDDLE mouse button
*It will move the camera according to where your mouse move to.
*When pressing RIGHT mouse button
*It will rotate the camera.

---
DEPTH RENDERING
---
Simply render the mesh based on the vertical distance of the point at the pixel to the camera. It is a nature of the depthbuffer, so it shouldn't count as a feature.
![screenshot](https://github.com/heguanyu/Project4-Rasterizer/blob/master/bmps/depthtest.bmp?raw=true)

-------------------------------------------------------------------
INTERPOLATION
-------------------------------------------------------------------

After the vertex shader and primitives assemble, every primitives is represented by 3 vertices, which has the position in the screen space, as well as the depth, color and normal information. So it is important
to interpolate the information of an arbitrary point inside this triangle(in this project it is just the integer points but it can be applied to real number coordinations)

Lets say that the 3 points are p1(x1,y1), p2(x2,y2), p3(x3,y3) in the screen space. Please note that all these coords are the precise float number, instead of integers on the pixel.
And the point we want is on p(x,y)

The we got vectors: v21=p2-p1 and v31=p3-p1 and v=p-p1
So the interpolation here means that we need 2 float numbers t1 and t2, so that t1v21+t2v31=v, or else, find out (1-t1-t2)*p1+t1*p2+t2*p3=p

It is easy to solve this 2-unknown-2-equations-1-polygon function, and I use det of 2*2 matrix to simplify the calculation.
After getting t1 and t2, what is still need to do is to check whether all of the t1,t2 and 1-t1-t2 are between 0 and 1. If not, this point is out of the triangle, and will not be drawn at all.

With t1 and t2, it is easy to get
depth=(1-t1-t2)*z1+t1*z2+t2*z3;
color=(1-t1-t2)*c1+t1*c2+t2*c3;
normal=(1-t1-t2)*n1+t1*n2+t2*n3;

And this is how interpolation works.


-------------------------------------------------------------------------------
PERFORMANCE EVALUATION
-------------------------------------------------------------------------------

The performance largely depends on the scale of the mesh: the larger it occupied the screen, the slower the rasterizer would be.
In the same scale, anyway, I tested the Back-face Culling performance.

All the test have anti-aliasing on so that it is slow enough to embody the real fps


Scale level: fps with BFC/ fps without BFC
*Small(default): 36/33
*Medium: 24/22
*Large: 13/11
*Very Large: 8/7
*Extreme Large: 2/2

About anti-aliasing

scale level: fps with anti-aliasing/ fps without anti-aliasing
*small: 60/36
*medium:58/24
*large:46/13
*Very Large: 37/8
*Extreme Larg: 24/2

I'd also tried pixel-parallel rasterization for fun only, however it explode in the cow model. As far as I tested the cube model, it shows a poor performance comparing to the triangle-parallel rasterization
I don't record the data by that time, and the code do not work now after several versions of revisions. It is for FUN only.


-------------------------------------------------------------------------------
VIDEO LINK
-------------------------------------------------------------------------------
http://youtu.be/WsTtFDiekJk

-------------------------------------------------------------------------------
3RD PARTY CODE
-------------------------------------------------------------------------------
Nothing except for the base code


-------------------------------------------------------------------------------
SAD STORY
-------------------------------------------------------------------------------
Did you find out the bug of this piece of code? Yes, I wasted 3 hours to find it out. So embarassing.


Binary file added bmps/anti-aliasing.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 bmps/color_interpolation.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 bmps/depthtest.bmp
Binary file not shown.
Binary file added bmps/normal_interpolation.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 bmps/stupidbug.bmp
Binary file not shown.
8 changes: 4 additions & 4 deletions objs/cube.obj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
v -0.1 -0.1 -0.1
v -0.1 -0.1 0.1
v -0.1 0.1 0.1
v -0.1 -0.1 0.3
v -0.1 0.1 0.3
v -0.1 0.1 -0.1
v 0.1 0.1 -0.1
v 0.1 0.1 0.1
v 0.1 -0.1 0.1
v 0.1 0.1 0.3
v 0.1 -0.1 0.3
v 0.1 -0.1 -0.1

vn 1 0 0
Expand Down
20 changes: 20 additions & 0 deletions objs/cube.obj.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
v -0.1 -0.1 -0.1
v -0.1 -0.1 0.3
v -0.1 0.1 0.3
v -0.1 0.1 -0.1
v 0.1 0.1 -0.1
v 0.1 0.1 0.3
v 0.1 -0.1 0.3
v 0.1 -0.1 -0.1

vn 1 0 0
vn 0 1 0
vn 0 0 1
vn -1 0 0
vn 0 -1 0
vn 0 0 -1

f 1//4 2//4 4//4
f 4//4 2//4 3//4
f 8//6 1//6 5//6
f 5//6 1//6 4//6
Loading