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: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ build
.LSOverride

# Icon must end with two \r
Icon
Icon


# Thumbnails
._*
Expand Down Expand Up @@ -189,7 +190,6 @@ install_manifest.txt
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ set(headers
src/sceneStructs.h
src/preview.h
src/utilities.h
src/ThirdPartyLib/tiny_obj_loader.h
src/bvhTree.h
src/ImGui/imconfig.h

src/ImGui/imgui.h
Expand All @@ -95,6 +97,8 @@ set(sources
src/scene.cpp
src/preview.cpp
src/utilities.cpp
src/ThirdPartyLib/tiny_obj_loader.cc
src/bvhTree.cu

src/ImGui/imgui.cpp
src/ImGui/imgui_demo.cpp
Expand Down
43 changes: 38 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,44 @@ 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)
* Zhuohao Lin
* [LinkedIn](https://www.linkedin.com/in/zhuohao-lin-960b54194/)
* Tested on: Windows 10, i7-10875H @ 2.30GHz 16GB, NVIDIA Grforce RTX 2060 6GB (personal machine)

### (TODO: Your README)
# Overview
This is a GPU based path tracer. The project contains both visual and performance improvements so that mutiple objects with different kinds of materials can be rendered quickly.
![](img/cornell.2022-10-08_06-59-29z.5000samp.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.
# Features
### `Arbitrary mesh loading and rendering with obj file`
![](img/cornell.2022-10-08_20-44-19z.5000samp.png)

### `Antialiasing`
Before Antialiasing | After Antialiasing
:-------------------------:|:-------------------------:
![](img/beforeAntialiasing.png) | ![](img/afterAntialiasing.png)

### `Refraction material`
Index of refraction of cube and sphere: 1.5
![](img/cornell.2022-10-08_22-12-30z.5000samp.png)

### `Bounding volume hierarchy acceleration data structure`
I implemented bounding volume hierarchy data structure in order to accelerate the intersection testing process. This data structure organize primitives into a binary tree based on their bounding box. There are various ways to split primitives. What I did is simply divide primitives into equal subsets. The BVH tree was built in CPU and then passed into GPU in a linear array. When doing intersection tests, first find box intersections within BVH tree apparently improve performance since a lot of primitives are abandoned.

# Performance Analysis

## Cache the First Bounce
For the first intersection of every iteration, it's always the same without any doubts. Therefore, I cache the first intersection data so that the computation can be skipped in every iteration except the first one. To see how much performance this brings, I make a graph as below (all data are got from the same scene)

![](img/cacheFirstBounce.PNG)

By caching the first bounce in the scene, we always get a higher FPS than no cache. However, as the max ray depth increases, the percentage increase in FPS is going down.


## Bounding Volume Hierarchy
I put 3 objects with different number of faces in the same scene for performance comparison. In order to keep the number of intersections as close as possible, I set 3 objects in similar sizes.

![](img/bvhPerformance.PNG)

It's obvious that BVH tree brings a huge performance improvement. The more the number of faces a mesh has, the lower the FPS will be. However, the FPS is dropping much slower using BVH than not using BVH. This is expected since BVH is a binary tree. The time cost to search intersections using BVH is roughly log(N) but N for not using BVH. <br/>
Note: Search intersections in BVH tree is roughly log(N) because it can get into different leaf nodes if some bounding boxes overlap.
Binary file added img/afterAntialiasing.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/beforeAntialiasing.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/bvhPerformance.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/cacheFirstBounce.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/cornell.2022-09-20_19-29-53z.6samp.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/cornell.2022-09-23_04-50-13z.5000samp.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/cornell.2022-09-23_04-50-41z.5000samp.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/cornell.2022-09-23_05-29-46z.5000samp.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/cornell.2022-09-24_01-28-07z.5000samp.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/cornell.2022-09-24_01-44-39z.160samp.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/cornell.2022-09-24_03-18-33z.149samp.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/cornell.2022-09-28_23-33-58z.1120samp.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/cornell.2022-09-28_23-33-58z.1141samp.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/cornell.2022-09-29_06-25-07z.123samp.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/cornell.2022-09-29_06-25-07z.124samp.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/cornell.2022-10-03_00-41-07z.1022samp.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/cornell.2022-10-03_00-41-07z.728samp.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/cornell.2022-10-03_04-42-09z.3108samp.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/cornell.2022-10-03_04-42-09z.5000samp.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/cornell.2022-10-03_05-51-26z.1203samp.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/cornell.2022-10-03_05-51-26z.2518samp.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/cornell.2022-10-03_08-10-45z.252samp.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/cornell.2022-10-03_08-22-15z.616samp.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/cornell.2022-10-03_08-28-21z.1112samp.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/cornell.2022-10-03_08-55-15z.613samp.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/cornell.2022-10-04_06-10-20z.409samp.png
Binary file added img/cornell.2022-10-04_06-13-06z.698samp.png
Binary file added img/cornell.2022-10-06_06-51-29z.1689samp.png
Binary file added img/cornell.2022-10-07_00-17-27z.838samp.png
Binary file added img/cornell.2022-10-08_05-56-57z.87samp.png
Binary file added img/cornell.2022-10-08_06-59-29z.1213samp.png
Binary file added img/cornell.2022-10-08_06-59-29z.1832samp.png
Binary file added img/cornell.2022-10-08_06-59-29z.1898samp.png
Binary file added img/cornell.2022-10-08_06-59-29z.2596samp.png
Binary file added img/cornell.2022-10-08_06-59-29z.352samp.png
Binary file added img/cornell.2022-10-08_06-59-29z.5000samp.png
Binary file added img/cornell.2022-10-08_06-59-29z.664samp.png
Binary file added img/cornell.2022-10-08_20-44-19z.5000samp.png
Binary file added img/cornell.2022-10-08_22-12-30z.5000samp.png
147 changes: 147 additions & 0 deletions scenes/antialiasing.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
// Emissive material (light)
MATERIAL 0
RGB 0.992 0.518 0.122
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 5

// 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 .8 .8 1
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0

// Diffuse green
MATERIAL 3
RGB .8 .8 1
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 white
MATERIAL 5
RGB 0.98 .98 .98
SPECEX 0
SPECRGB .91 .89 .867
REFL 0
REFR 0
REFRIOR 1.5
EMITTANCE 0

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

// Refractive white
MATERIAL 6
RGB .98 .98 .98
SPECEX 0
SPECRGB .98 .98 0
REFL 1
REFR 1
REFRIOR 1.5
EMITTANCE 0

// Camera
CAMERA
RES 1080 1080
FOVY 45
ITERATIONS 500
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

// Floor
OBJECT 1
cube
material 1
TRANS 0 0 0
ROTAT 0 0 0
SCALE 10 .01 10

// Ceiling
OBJECT 2
cube
material 1
TRANS 0 10 0
ROTAT 0 0 90
SCALE .01 10 10

// Back wall
OBJECT 3
cube
material 1
TRANS 0 5 -5
ROTAT 0 90 0
SCALE .01 10 10

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

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

// Sphere
OBJECT 6
../scenes/objFiles/cube.obj
material 5
TRANS 0 4 0
ROTAT 0 30 0
SCALE 4 4 4
80 changes: 75 additions & 5 deletions scenes/cornell.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 5
EMITTANCE 10

// Diffuse white
MATERIAL 1
Expand Down Expand Up @@ -48,6 +48,26 @@ REFR 0
REFRIOR 0
EMITTANCE 0

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

// Refractive yellow
MATERIAL 6
RGB .98 .98 .98
SPECEX 0
SPECRGB .98 .98 0
REFL 1
REFR 1
REFRIOR 1.5
EMITTANCE 0

// Camera
CAMERA
RES 800 800
Expand Down Expand Up @@ -110,8 +130,58 @@ SCALE .01 10 10

// Sphere
OBJECT 6
sphere
material 4
TRANS -1 4 -1
../scenes/objFiles/wahoo.obj
material 6
TRANS 2 4 0
ROTAT 0 0 0
SCALE 0.35 0.35 0.35


OBJECT 7
../scenes/objFiles/wahoo.obj
material 5
TRANS 0 4 2
ROTAT 0 0 0
SCALE 0.35 0.35 0.35

OBJECT 8
../scenes/objFiles/wahoo.obj
material 5
TRANS 2 1 0
ROTAT 0 0 0
SCALE 0.35 0.35 0.35

OBJECT 9
../scenes/objFiles/wahoo.obj
material 2
TRANS 0 1 2
ROTAT 0 0 0
SCALE 0.35 0.35 0.35

OBJECT 10
../scenes/objFiles/wahoo.obj
material 5
TRANS 3 1 2
ROTAT 0 0 0
SCALE 0.35 0.35 0.35

OBJECT 11
../scenes/objFiles/wahoo.obj
material 5
TRANS -2 4 -2
ROTAT 0 0 0
SCALE 0.35 0.35 0.35

OBJECT 12
../scenes/objFiles/Caitlyn.obj
material 5
TRANS 1 1 0
ROTAT 0 0 0
SCALE 2 2 2

OBJECT 13
../scenes/objFiles/melina.obj
material 5
TRANS -1 1 0
ROTAT 0 0 0
SCALE 3 3 3
SCALE 2 2 2
Loading