Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
00b3649
Basic path tracer setup
EvsChen Sep 30, 2020
e7c1aa6
Debug
EvsChen Sep 30, 2020
3fe0917
Add perf measure code
EvsChen Sep 30, 2020
b9130c1
Check bugs
EvsChen Oct 1, 2020
7090273
Add pic
EvsChen Oct 1, 2020
919e2c3
Add perf analysis and basic readme
EvsChen Oct 1, 2020
b9f1e0c
Fix bugs
EvsChen Oct 7, 2020
d418775
Merge branch 'master' of https://github.com/EvsChen/Project3-CUDA-Pat…
EvsChen Oct 7, 2020
3b38aa0
Add refraction code
EvsChen Oct 7, 2020
33e7790
Change refrac scene
EvsChen Oct 7, 2020
3a3ee48
Change schlick approx
EvsChen Oct 7, 2020
51f2b73
Add antialiasing
EvsChen Oct 7, 2020
bd088ca
Add obj loading
EvsChen Oct 8, 2020
2d601c6
Add obj loader code
EvsChen Oct 9, 2020
eb489d7
Change gitignore
EvsChen Oct 9, 2020
e01d4eb
Add obj files
EvsChen Oct 9, 2020
5c77ba9
Add scene scale and obj sample scene
EvsChen Oct 9, 2020
6a5dfdb
Fix bugs
EvsChen Oct 9, 2020
7571fd9
Add visual improvements
EvsChen Oct 9, 2020
3b4dfa6
Add custom scene
EvsChen Oct 10, 2020
5bedc8d
Change obj
EvsChen Oct 10, 2020
4f56575
Change obj
EvsChen Oct 10, 2020
5f8a4f4
Add images
EvsChen Oct 10, 2020
870c51a
Add multishape loading
EvsChen Oct 10, 2020
c598729
Add more scenes
EvsChen Oct 11, 2020
e3a9ae6
Add material scene
EvsChen Oct 11, 2020
87c83d5
Change float format
EvsChen Oct 11, 2020
b14837f
Remove empty char
EvsChen Oct 11, 2020
f50aaa7
Add perf images
EvsChen Oct 11, 2020
5bacfdb
Add more mat scene
EvsChen Oct 11, 2020
f8466c9
commit
EvsChen Oct 11, 2020
c273fc0
Finish readme
EvsChen Oct 11, 2020
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
5 changes: 2 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,6 @@ install_manifest.txt
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
Expand Down Expand Up @@ -276,7 +276,6 @@ artifacts/
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
Expand Down
77 changes: 77 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"files.associations": {
"*.js ": "javascript",
"string": "cpp",
"xstring": "cpp",
"algorithm": "cpp",
"atomic": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"exception": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"locale": "cpp",
"map": "cpp",
"memory": "cpp",
"new": "cpp",
"ostream": "cpp",
"ratio": "cpp",
"set": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"utility": "cpp",
"vector": "cpp",
"xfacet": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xstddef": "cpp",
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp",
"array": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"clocale": "cpp",
"complex": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"unordered_map": "cpp",
"functional": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"string_view": "cpp",
"cinttypes": "cpp"
}
}
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ set(headers
src/sceneStructs.h
src/preview.h
src/utilities.h
src/tinyobj.h
)

set(sources
Expand All @@ -84,6 +85,7 @@ set(sources
src/scene.cpp
src/preview.cpp
src/utilities.cpp
src/tinyobj.cc
)

list(SORT headers)
Expand Down
60 changes: 55 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,61 @@ 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)
* Shenyue Chen
* [LinkedIn](https://www.linkedin.com/in/shenyue-chen-5b2728119/), [personal website](http://github.com/EvsChen)
* Tested on: Windows 10, Intel Xeon Platinum 8259CL @ 2.50GHz 16GB, Tesla T4 (AWS g4dn-xlarge)

### (TODO: Your README)
### Output
<p align="center">
<img src="./img/custom_scene.png" />
<span>Custom OBJ file loading</span>
<img src="./img/materials.png" />
<span>Scenes used for materials sorting test</span>
<img src="./img/two-balls.png" />
<span>Two balls</span>
<img src="./img/two-balls-dof.png" />
<span>Two balls with depth of field</span>
<img src="./img/motion-blur.png" />
<span>Motion blur</span>
</p>

*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
Part 1
* Specular and diffuse shading
* Stream compaction to terminate rays
* Materials sorting
* First bounce cache

Part 2
* .OBJ file loading using [tinyobj](https://github.com/tinyobjloader/tinyobjloader)
* Motion blur
* Refraction and Schlick approximation

Part 3
* Depth of field
* Anti-aliasing
* [Small script](./scenes/gen_scene.py) for scene generation

### Performance analysis
#### Stream compaction for path termination
Below is the change of paths in the first 10 iterations of the cornell box image, with the basic diffuse and specular shading.
<p align="center">
<img src="./img/path-termination.png" />
</p>
From the plot we can observe that the number of paths reduces greatly when the depth increases, because many rays terminated by not intersecting or intersecting with a light source. The number of paths is equal to the number of threads we launched in each kernel run. Therefore we increase the thread utilization by reducing the number of threads in kernel launch configuration.


#### Different optimization techniques
In this section, we measured the average time per iteration for the basic cornell box scene with different optimization techniques, for the first 1000 iterations. The result can be seen in the plot below.
<p align="center">
<img src="./img/diff_opti.png" />
</p>
We notice the the first bounce cache can improve the performance by a little bit. But the other parts seem to play a negative role. I assume this is because the scene is too simple and the sorting overhead is much over than the optimization is causes.


#### Material sorting testing
Specifically, I want to see whether more materials will affect the effect of optimization caused by the material sorting. So I created a scene of more than 30 materials and 30 objects, [materials.txt](./scenes/materials.txt). The rendered scene is on the top of the readme. And the time measures is shown below.
<p align="center">
<img src="./img/mat_sort_perf.png" />
</p>
Unfortunately, the sorting still decreases the performance. But the overhead is not so serious compared to the simple scene.
65 changes: 65 additions & 0 deletions analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import csv
import matplotlib.pyplot as plt

# data = []
# with open('path-termination.csv', 'r') as csvfile:
# spamreader = csv.reader(csvfile, delimiter=',')
# for row in spamreader:
# drow = []
# for data_str in row:
# drow.append(int(data_str))
# data.append(drow)

# fig, ax = plt.subplots()

# for i in range(0, len(data)):
# row = data[i]
# x = [j for j in range(0, len(row))]
# plt.plot(x, row)

# plt.title("Change of paths in first 10 iterations")
# plt.xlabel("Depth")
# plt.ylabel("Path count")
# plt.show()

# base = [13.9153, 13.4523, 13.2604, 13.0256, 12.8251, 12.6814, 12.584, 12.467, 12.3808,
# 12.3539, 12.3, 12.2559, 12.2064, 12.1793, 12.157, 12.1449, 12.1508, 12.1537, 12.147, 12.152]
# first_cache = [13.994, 13.5278, 12.9571, 12.4803, 12.1568, 11.9892, 11.8137, 11.7125, 11.6294,
# 11.5688, 11.602, 11.5473, 11.5048, 11.4699, 11.4974, 11.476, 11.4706, 11.4416, 11.4178, 11.411]
# ray_term = [43.3666, 39.4445, 37.9706, 37.2061, 36.8238, 36.464, 36.3297, 36.1474, 36.0439,
# 35.9822, 35.937, 35.907, 35.8626, 35.8245, 35.7628, 35.7196, 35.6834, 35.6314, 35.5985, 35.5634]
# mat_sorting = [92.1103, 90.0405, 89.2113, 88.785, 88.5098, 88.3835, 88.2686, 88.1703, 88.1409,
# 88.0665, 88.0275, 88.0738, 88.1269, 88.1731, 88.2425, 88.2707, 88.309, 88.3622, 88.4123, 88.4398]

# x = [i * 50 for i in range(1, 21)]

# fig, ax = plt.subplots()

# plt.plot(x, base, label="base")
# plt.plot(x, first_cache, label="first bounce cache")
# plt.plot(x, ray_term, label="stream compaction")
# plt.plot(x, mat_sorting, label="material sorting")

# plt.title("Average time per iteration for different optimizations")
# plt.xlabel("First # of iterations")
# plt.ylabel("Average time (ms)")
# plt.legend()
# plt.show()

mat_scene_with_sort = [77.1336, 75.3321, 74.7839, 74.586, 74.8918, 75.1525, 74.7427, 74.6345, 74.6205,
74.6913, 74.7094, 74.7804, 74.789, 74.7278, 74.6984, 74.7119, 74.7549, 74.8404, 74.8833, 74.86]

mat_scene = [42.1215, 40.9768, 40.5953, 40.4929, 40.7369, 40.6872, 40.7313, 40.7851, 40.8242, 40.67, 40.2865, 39.918, 39.6168, 39.3591, 39.1535, 38.9644, 38.8111, 38.6765, 38.569, 38.458]

x = [i * 50 for i in range(1, 21)]

fig, ax = plt.subplots()

plt.plot(x, mat_scene, label="base")
plt.plot(x, mat_scene_with_sort, label="with material sorting")

plt.title("Average time per iteration for material sorting")
plt.xlabel("First # of iterations")
plt.ylabel("Average time (ms)")
plt.legend()
plt.show()
Binary file added img/cornell-mid.2469samp.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.2020-09-30_22-19-13z.378samp.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.2020-09-30_22-33-42z.3199samp.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.2020-10-01_00-14-41z.2419samp.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.2020-10-09_07-33-22z.611samp.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.2020-10-10_07-55-37z.3395samp.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.2020-10-10_07-55-37z.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.2020-10-10_21-45-26z.1092samp.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.2020-10-10_23-21-51z.1593samp.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.2020-10-10_23-21-51z.2711samp.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.2020-10-10_23-21-51z.3090samp.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/custom_scene.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/diff_opti.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/mat_sort_perf.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/materials.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/motion-blur.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/path-termination.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/two-balls-dof.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/two-balls.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions path-termination.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
640000,523159,362728,280463,223214,180495,146740,119710
640000,523159,362288,280306,223398,180778,147049,120156
640000,523159,362267,279749,223067,180340,146656,119784
640000,523159,362483,280166,223311,180560,146641,119595
640000,523159,362403,280050,223341,180564,146528,119454
640000,523159,362148,280058,222828,180016,146613,119768
640000,523159,362432,279908,222710,179843,146030,119223
640000,523159,362638,279881,223265,180436,146775,119600
640000,523159,362086,279934,223102,180527,147037,120059
640000,523159,362323,279620,222546,179910,146255,119561
Loading