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 3: Tianyi Xiao #30

Open
wants to merge 27 commits into
base: main
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
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cmake_minimum_required(VERSION 3.1)

project(cis565_path_tracer)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
Expand Down
90 changes: 85 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,91 @@ CUDA Path Tracer

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

* (TODO) YOUR NAME HERE
* Tested on: (TODO) Windows 22, i7-2222 @ 2.22GHz 22GB, GTX 222 222MB (Moore 2222 Lab)
* Tianyi Xiao
* [LinkedIn](https://www.linkedin.com/in/tianyi-xiao-20268524a/), [personal website](https://jackxty.github.io/), [Github](https://github.com/JackXTY).
* Tested on: Windows 11, i9-12900H @ 2.50GHz 16GB, Nvidia Geforce RTX 3070 Ti 8032MB (Personal Laptop)

### (TODO: Your README)
### Render Images
![](/img/wahoo_1.png)
![](/img/refraction_1.png)

*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.
### Stream Compaction

With stream compaction, we could terminate the rays that reach end, like reach outside of the scene, or hit the light.

![](/img/graphs/Stream%20Compation%20ray%20decrease.png)
Above graph record how rays are terminated with stream compaction, using the basic cornell box scene below, within one render iteration.
![](/img/jitterRay_cmp.png)
When it comes to the 7th bounce, there are just about 1/6 rays left compared with the beginning stage.

obj box scene:
![](/img/cornellDode.png)
closed box scene:
![](/img/closed_box.png)
Statistics of render time of each frame in different scenes (SC == Stream Compaction):
![](/img/graphs/Stream%20Compaction%20scenes.png)

Then, I test the average render time of one frame in different scenes. The first scene is just the basic conrell box scene. The second and the third scene are both the obj box scene above, which combine the cornell box scene with several objects, so it's more complicated. But for the third scene, rays bounce 20 times instead of 8 times. (Other three scenes all bounce only 8 times, which is enough for render.)

From these three scenes, we can see that the stream compaction could speed up the render process. When the scene is simple, the speed up isn't obvious. But when tested in complicated scene, the positive effect of stream compaction is clearer. Also, as the maximum bounce times increase, the stream compact works better, since with more and more ray terminated, the render speed in succeeding bounce is higher and higher.

The forth scenes is closed box scene, which means no ray would reach outside of this scene. Therefore there will be a lot fewer rays terminated after each bounce. And from the result we can see that, in this situation, the stream compaction actually slow down the render speed. Because there are not many ray terminated in each bounce, the cost of stream compaction itself is higher than the time decrease of shading process.

### Material Sort
refraction scene:
![](/img/Refraction.png)

Statistics of render time of each frame in different scenes (MS == Material Sort):
![](/img/graphs/Material%20Sort.png)

The new refraction box scene is shown above. Actually the material sort slow down the render process. I think the reason is that, the cost of material sort is higher than the efficiency it brings. And there are only at most several branches relative to material kinds in shading stage. Maybe in scenes with fewer pixels and a with a lot more various kinds of materials supported (like different shading methods, Phong, PBR, etc.), the material sort could work out.

### First Bounce Cache
wahoo scene:
![](/img/wahoo_0.png)
Statistics of render time of each frame in different scenes:
![](/img/graphs/First%20Bounce%20Cache.png)

Caching the first bounce result could increase the render speed a little, without doubt. Though the speed up is not quite obvious, anyway it's still helpful.

### BVH Tree

The BVH part cost most of my time(I think nearly 60%), in which I face lots of bugs and problems (and luckily fix them all, finally). In conclusion, there are two toughest problems which I'd like to share about.

The first one is about the box intersection judgement. Initially I first check if the ray go through any pair of bounding box faces, then I check if the ray origin point is inside the box.

The second one is about the the tree division. I build bvh tree from the top to the bottom, and to divide objects in one parent bounding box to two children bounding box, initially I divide them accoding to its position compared with bounding box central position. However it makes the tree highly unbalanced. Now I sort the object of their position in specific axis, and deviced them into two equal parts according to the sort result.

many object scene
![](/img/manyObj.png)
Statistics of render time of each frame in different scenes:
![](/img/graphs/BVH.png)

These two main update (and also many trivial modificatoin together) make my BVH tree really effcient now. From the bar graph result above, we can see that the BVH tree increase the render speed dramatically, as we expect. With BVH tree, we could sucessfully limit the render time of complicated scene within a resonable limit.

### Render Features

This project also support some render features.

**Obj Load**

![](/img/manyObj.png)

**Microfacet**

![](/img/microfacet.png)

**Refraction**

![](/img/refraction_0.png)

**Jitter Ray**

jitter ratio is 1e-3
![](/img/jitterRay_1e_3_8d.png)
jitter ratio is 1e-2, the result is more blur
![](/img/jitterRay_1e_2_8d.png)

**Depth Of Field**

![](/img/Depth_Of_Field.png)
Binary file added img/Depth_Of_Field.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/Refraction.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/bug.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/closed_box.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/cornellDode.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/graphs/BVH.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/graphs/First Bounce Cache.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/graphs/Material Sort.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/graphs/Stream Compaction scenes.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/graphs/Stream Compation ray decrease.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/jitterRay_1e_2_8d.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/jitterRay_1e_3_30d.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/jitterRay_1e_3_8d.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/jitterRay_cmp.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/manyObj.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/microfacet.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/refraction_0.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/refraction_1.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/wahoo_0.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/wahoo_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
222 changes: 222 additions & 0 deletions scenes/closedDode.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
// Emissive material (light)
MATERIAL 0
RGB 1 1 1
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 8

// Diffuse white
MATERIAL 1
RGB .98 .98 .98
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0

// Diffuse red
MATERIAL 2
RGB .85 .35 .35
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0

// Diffuse green
MATERIAL 3
RGB .35 .85 .35
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0

// Specular white
MATERIAL 4
RGB .98 .98 .98
SPECEX 0
SPECRGB .98 .98 .98
REFL 1
REFR 0
REFRIOR 0
EMITTANCE 0

// Diffuse blue
MATERIAL 5
RGB .35 .35 .85
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0

// Camera
CAMERA
RES 800 800
FOVY 45
ITERATIONS 5000
DEPTH 8
FILE cornell
EYE 0.0 5 10.5
LOOKAT 0 5 0
UP 0 1 0


// Ceiling light
OBJECT 0
cube
material 0
TRANS 0 10 0
ROTAT 0 0 0
SCALE 3 .3 3

// Sphere
OBJECT 1
sphere
material 4
TRANS -1 4 -1
ROTAT 0 0 0
SCALE 3 3 3

// Left wall
OBJECT 2
cube
material 2
TRANS -10 10 0
ROTAT 0 0 0
SCALE .01 20 20

// Right wall
OBJECT 3
cube
material 3
TRANS 10 10 0
ROTAT 0 0 0
SCALE .01 20 20

// Floor-0
OBJECT 4
triangle
material 1
VERTEX 10 0 -10
VERTEX -10 0 10
VERTEX 10 0 10

// Floor-1
OBJECT 5
triangle
material 1
VERTEX -10 0 -10
VERTEX -10 0 10
VERTEX 10 0 -10

// Ceiling-0
OBJECT 6
triangle
material 1
VERTEX 10 20 -10
VERTEX 10 20 10
VERTEX -10 20 10

// Ceiling-1
OBJECT 7
triangle
material 1
VERTEX -10 20 -10
VERTEX 10 20 -10
VERTEX -10 20 10

// Back wall-0
OBJECT 8
triangle
material 1
VERTEX -10 0 -10
VERTEX 10 20 -10
VERTEX -10 20 -10

// Back wall-1
OBJECT 9
triangle
material 1
VERTEX 10 20 -10
VERTEX -10 0 -10
VERTEX 10 0 -10

// Mesh
OBJECT 10
mesh
material 5
MESH_PATH D:\CIS565\Project3-CUDA-Path-Tracer\scenes\obj\dodecahedron.obj
TRANS 0 2 1.5
ROTAT 0 90 0
SCALE 1.5 1.5 1.5

// Mesh
OBJECT 11
mesh
material 5
MESH_PATH D:\CIS565\Project3-CUDA-Path-Tracer\scenes\obj\dodecahedron.obj
TRANS -2 2 3
ROTAT 0 90 0
SCALE 1.2 1.2 1.2

// Mesh
OBJECT 12
mesh
material 5
MESH_PATH D:\CIS565\Project3-CUDA-Path-Tracer\scenes\obj\dodecahedron.obj
TRANS 0 7 1.5
ROTAT 0 90 0
SCALE 1.2 0.9 1.2

// Mesh
OBJECT 13
mesh
material 5
MESH_PATH D:\CIS565\Project3-CUDA-Path-Tracer\scenes\obj\dodecahedron.obj
TRANS -2 5 3
ROTAT 0 90 0
SCALE 1 1 1


// Mesh
OBJECT 14
mesh
material 5
MESH_PATH D:\CIS565\Project3-CUDA-Path-Tracer\scenes\obj\dodecahedron.obj
TRANS 3 2 1.5
ROTAT 0 90 0
SCALE 1.5 1.5 1.5

// Mesh
OBJECT 15
mesh
material 5
MESH_PATH D:\CIS565\Project3-CUDA-Path-Tracer\scenes\obj\dodecahedron.obj
TRANS 3 7 -3
ROTAT 0 90 0
SCALE 1 1 1

// Front wall-0
OBJECT 16
triangle
material 1
VERTEX -10 0 10
VERTEX -10 20 10
VERTEX 10 20 10

// Front wall-1
OBJECT 17
triangle
material 1
VERTEX 10 20 10
VERTEX 10 0 10
VERTEX -10 0 10
Loading