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
6 changes: 3 additions & 3 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,7 @@ install_manifest.txt
*.slo
*.lo
*.o
*.obj


# Precompiled Headers
*.gch
Expand Down Expand Up @@ -276,7 +277,6 @@ artifacts/
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
Expand Down
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ set(headers
src/sceneStructs.h
src/preview.h
src/utilities.h
src/tinyobj/tiny_obj_loader.h
src/bvh.h

src/ImGui/imconfig.h

src/ImGui/imgui.h
Expand All @@ -95,7 +98,8 @@ set(sources
src/scene.cpp
src/preview.cpp
src/utilities.cpp

src/tinyobj/tiny_obj_loader.cc
src/bvh.cpp
src/ImGui/imgui.cpp
src/ImGui/imgui_demo.cpp
src/ImGui/imgui_draw.cpp
Expand Down
57 changes: 51 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,58 @@
CUDA Path Tracer
**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)
* Shineng Tang
* [LinkedIn](https://www.linkedin.com/in/shineng-t-224192195/)
* Tested on: Windows 11, i9-10900k @3.7GHz 32GB, RTX 3090 24GB

### (TODO: Your README)

*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.
## **Project Description**
This is a CUDA-based path tracer capable of loading multiple OBJ files and rendering globally-illuminated images based on the model at fast speed using GPU parallelization.

![](img/tmp.png)
## **Main Features**
### **Stream compaction**
I used stream compaction to get rid of lights that have no intersections with the scene, which largely reduces the amount of useless rays being computed for intersections.
### **Refraction**
I used Schlick's approximation and `glm::refract` for Snell's law to implement refraction with Frensel effects. Given a specific refraction rate, it will create different effects.
| IOR 1.5 | IOR 3 |
| ---------------------------------| ----------------------------------|
| ![IOR 1.5](img/1.5.png) | ![IOR 3](img/3.png) |

### **Physically-based depth of field**
For this part, I implemented a thin-lens camera with focal distance and lens radius as its input. By tweaking these numbers, the camera will change its focal point to create this DOF effect. When the focal point is at the object, the object will be clear, otherwise, it will be vague.
| Focal Distance 6 | Focal Distance 14 |
| -----------------------------------------| --------------------------------------------|
| ![6](img/6.png) | ![14](img/14.png) |

### **Stochastic Anti-Aliasing**
| Without Anti-Aliasing | With Anti-Aliasing |
| ------------------------------------------------| ------------------------------------------------|
| ![Without Anti-Aliasing](img/noAA.png) | ![With Anti-Aliasing](img/AA.png) |

### **Custom Obj Mesh Loading**
I used tinyObj loader to get all the vertex positions and vertex normals from the obj files and passed them to the GPU for doing triangle intersection tests.
![Without Anti-Aliasing](img/single.png)
![](img/mesh.png)

### **BVH tree structure**
I implemented the Bounding Volume Hierarchy tree to accelerate the rendering process. I build the tree after all obj files are loaded on the cpu. To build the tree, I need to get the global positions of the bounding boxes of the triangles of the meshes. Based on the data of each bounding box, I can easily assign the bounding box to the tree node recursively. One thing to remember is that we have to deserialize the tree into an array so that it can be passed to the GPU. After finish building the tree, I pass the BVH tree "array" to the GPU to do ray intersection tests. If a ray hit the bounding box, then it keeps traversing the tree until the current bounding box belongs to a triangle of a mesh. By using BVH tree, we can save a lot of work doing useless intersection tests on irrelevant triangle primitives. For example, the following images would take forever to render without using BVH. With BVH, however, only takes me around fifteen minutes to render three refractive stanford dragons.

![](img/bvh1.png)
![](img/bvh2.png)

### **Performance Analysis for BVH tree**

![](img/chart1.png)

As we can tell from the diagram, there is a huge performance gap when between these two options. When we are dealing with obj files with relatively lower poly counts, such as wahoo, cow, we can get four times more fps if we use BVH. When we are dealing with obj files with high poly counts, the fps gap is incredible: for the Stanford dragon model, we can get 360 times more framerates per second! This results from the fact that for each ray, we only need to search a small range of bounding boxes to get to our target comparing to traversing through all the primitive triangles, 5,500,000 triangles for the Stanford Dragon, for example.

### **Performance Analysis for caching the first bounce**

Since the first intersection test for each iteration is always the same, we can cache it so that we can reuse it in the subsquent iterations. This can help us gain some performance.

![](img/chart2.png)

From the diagram above, I noticed that the gaps of using and not using caching among all max ray depths do not have a large difference, but it still has a pattern: the deeper the depth is, the smaller the gap between these two options. This is because of the more computation it needs for deeper depth so it will reduce the gap.
Binary file added img/1.5.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/14.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/3.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/6.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/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/bvh1.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/bvh2.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/chart1.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/chart2.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_00-09-08z.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_06-36-35z.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-27_06-18-42z.16samp.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-27_06-18-42z.93samp.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_04-31-18z.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-29_05-36-48z.1394samp.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_20-59-35z.1554samp.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-30_03-20-50z.2364samp.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-30_04-26-46z.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-30_04-28-25z.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-30_08-54-30z.517samp.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-02_07-17-29z.318samp.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-02_08-23-32z.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-02_08-28-06z.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-02_09-05-26z.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-02_09-10-29z.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-02_23-41-24z.64samp.png
Binary file added img/cornell.2022-10-03_00-51-04z.4samp.png
Binary file added img/cornell.2022-10-03_00-58-33z.5000samp.png
Binary file added img/cornell.2022-10-03_01-56-54z.138samp.png
Binary file added img/cornell.2022-10-03_01-59-51z.52samp.png
Binary file added img/cornell.2022-10-03_02-00-33z.5samp.png
Binary file added img/cornell.2022-10-03_02-42-04z.9samp.png
Binary file added img/cornell.2022-10-03_02-42-36z.7samp.png
Binary file added img/cornell.2022-10-03_02-53-21z.51samp.png
Binary file added img/cornell.2022-10-03_06-59-33z.57samp.png
Binary file added img/cornell.2022-10-03_07-04-43z.10000samp.png
Binary file added img/cornell.2022-10-03_07-33-55z.507samp.png
Binary file added img/cornell.2022-10-03_08-05-20z.118samp.png
Binary file added img/cornell.2022-10-03_08-06-23z.1335samp.png
Binary file added img/cornell.2022-10-04_04-07-13z.6samp.png
Binary file added img/cornell.2022-10-04_07-43-20z.846samp.png
Binary file added img/cornell.2022-10-04_07-46-28z.5000samp.png
Binary file added img/cornell.2022-10-04_09-01-32z.328samp.png
Binary file added img/cornell.2022-10-04_17-36-03z.52samp.png
Binary file added img/cornell.2022-10-05_08-02-30z.11samp.png
Binary file added img/cornell.2022-10-05_08-05-45z.1368samp.png
Binary file added img/cornell.2022-10-06_05-55-57z.1777samp.png
Binary file added img/cornell.2022-10-06_05-55-57z.1781samp.png
Binary file added img/cornell.2022-10-06_05-55-57z.1782samp.png
Binary file added img/cornell.2022-10-06_07-09-06z.5000samp.png
Binary file added img/cornell.2022-10-06_07-39-08z.5000samp.png
Binary file added img/cornell.2022-10-07_01-01-56z.3002samp.png
Binary file added img/cornell.2022-10-07_01-27-46z.5000samp.png
Binary file added img/cornell.2022-10-08_21-15-34z.5000samp.png
Binary file added img/noAA.png
Binary file added img/refraction.png
Binary file added img/single.png
Binary file added img/tmp.png
67 changes: 64 additions & 3 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 @@ -44,18 +44,40 @@ RGB .98 .98 .98
SPECEX 0
SPECRGB .98 .98 .98
REFL 1
REFR 1
REFRIOR 1.6
EMITTANCE 0

// Mirror
MATERIAL 5
RGB .98 .98 .98
SPECEX 0
SPECRGB .98 .98 .98
REFL 1
REFR 0
REFRIOR 0
EMITTANCE 0

// blue glass
MATERIAL 6
RGB 0.13725 0.67451 0.76863
SPECEX 0
SPECRGB .98 .98 .98
REFL 1
REFR 1
REFRIOR 3
EMITTANCE 0

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

Expand Down Expand Up @@ -108,10 +130,49 @@ TRANS 5 5 0
ROTAT 0 0 0
SCALE .01 10 10

// Right wall
/*OBJECT 6
sphere
material 4
TRANS 0 4 0
ROTAT 0 0 0
SCALE 5 5 5
*/
// Sphere
OBJECT 6
sphere
material 1
TRANS -3 3 0
ROTAT 0 0 0
SCALE 3 3 3

OBJECT 7
sphere
material 5
TRANS 0 5 0
ROTAT 0 0 0
SCALE 3 3 3

OBJECT 8
sphere
material 4
TRANS -1 4 -1
TRANS 3 3 0
ROTAT 0 0 0
SCALE 3 3 3




/*OBJECT 7
model ../scenes/obj_files/wahoo.obj
material 1
TRANS 3 4 -1
ROTAT 0 0 0
SCALE 1 1 1*/







Loading