Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
1bc65bf
add nothing but indent
Jack12xl Sep 29, 2020
f1c4811
add thrust head to suppress error
Jack12xl Sep 29, 2020
5c1049d
SL tend to render white
Jack12xl Sep 29, 2020
66c2e0f
SL, basic implementation with bug, where the ceiling square area too …
Jack12xl Sep 29, 2020
b997d4d
refine interaction with probability
Jack12xl Sep 29, 2020
f4e09ad
the image would grow dark
Jack12xl Sep 29, 2020
ae18b02
basically work
Jack12xl Sep 29, 2020
eea1bca
switch to stable_partition, thought it more elegant than remove if
Jack12xl Sep 30, 2020
ed16c0d
add timer
Jack12xl Sep 30, 2020
ad767e2
SL for performancetimer
Jack12xl Sep 30, 2020
c0bc3cc
sys clock not working
Jack12xl Sep 30, 2020
a043b9a
add timer
Jack12xl Sep 30, 2020
78fd37b
add cfg.h
Jack12xl Sep 30, 2020
7498b07
add material sort
Jack12xl Sep 30, 2020
f96dce5
to commit
Jack12xl Sep 30, 2020
0e39bb4
add readme
Jack12xl Sep 30, 2020
782fac0
add img
Jack12xl Sep 30, 2020
57a4ed9
update readme
Jack12xl Sep 30, 2020
6aca8bf
update
Jack12xl Sep 30, 2020
4c75bef
add refraction, fresnel, imperfect
Jack12xl Oct 3, 2020
f332518
should add more info in intersection
Jack12xl Oct 3, 2020
51e218e
remove 0 color
Jack12xl Oct 3, 2020
bfbda88
fix part of the bug
Jack12xl Oct 3, 2020
726a72a
add dof, not test yet
Jack12xl Oct 4, 2020
9b8b66a
add not working stratified sampled
Jack12xl Oct 5, 2020
914e0c3
no idea whether stratified sample is done right
Jack12xl Oct 6, 2020
4456f55
so this is it? seems to successfully install gltf, havent try though
Jack12xl Oct 6, 2020
c90bd33
SL for gltf loading
Jack12xl Oct 6, 2020
da631c0
change anti alias para
Jack12xl Oct 6, 2020
47dd7c6
gitignore gltf_model
Jack12xl Oct 6, 2020
748a440
add load gltf, not test, next intersection
Jack12xl Oct 6, 2020
50f0f10
SL for triangle bbox intersection
Jack12xl Oct 7, 2020
2278885
SL for intesection, to test
Jack12xl Oct 7, 2020
07485ad
resolve ambigous cout, current meet with example loadGLTF link problem
Jack12xl Oct 7, 2020
afaa423
add intersect mesh at pathtrace.cu, finally fix the example link erro…
Jack12xl Oct 7, 2020
b39cef5
annote some output and wanna add scnee file to vs
Jack12xl Oct 7, 2020
4676683
can finally add gltf, but normal seems not right
Jack12xl Oct 7, 2020
2622636
vertex or normal maybe not that correct
Jack12xl Oct 7, 2020
ef2519e
wanna try motion blur
Jack12xl Oct 7, 2020
9d15242
try to change norm idx
Jack12xl Oct 7, 2020
842ed9f
add motion blur
Jack12xl Oct 7, 2020
913e6d0
still not fix gltf
Jack12xl Oct 8, 2020
b4830c1
SL for readme
Jack12xl Oct 8, 2020
d178a26
change img name and update blooper
Jack12xl Oct 8, 2020
ae39f27
update image
Jack12xl Oct 8, 2020
13bb8f1
update image
Jack12xl Oct 8, 2020
f9857f8
update readme
Jack12xl Oct 8, 2020
ba1d646
fix typo in image iteration -> depth
Jack12xl Oct 8, 2020
3df29db
fffffffffffffffff**ck, actually I made a so stupid mistake on normal …
Jack12xl Oct 8, 2020
ba4c8ac
update kirby image
Jack12xl Oct 8, 2020
411ba25
update readme
Jack12xl Oct 8, 2020
7d3880a
Fix gltf load (#1)
Jack12xl Jun 6, 2022
d21feb9
Add MIS and microface reflection (#2)
Jack12xl Jul 7, 2022
3fc8f6c
Bvh (#3)
Jack12xl Sep 26, 2022
c08a89f
Check direct light (#4)
Jack12xl Oct 4, 2022
36c9c47
Environment light (#5)
Jack12xl Oct 23, 2022
a53b17d
Normal mapping (#6)
Jack12xl Oct 29, 2022
731e69c
Disney brdf (#7)
Jack12xl Mar 19, 2023
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -558,3 +558,6 @@ xcuserdata
*.xccheckout
*.moved-aside
*.xcuserstate

# Jack12
gltf_mesh/*
Expand Down
26 changes: 26 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ endif(UNIX)
set(GLM_ROOT_DIR "external")
find_package(GLM REQUIRED)
include_directories(${GLM_INCLUDE_DIRS})
include_directories(${EXTERNAL}/include/raytrace)
#include_directories(scenes)

set(headers
src/bvh.h
src/main.h
src/image.h
src/interactions.h
Expand All @@ -73,24 +76,47 @@ set(headers
src/sceneStructs.h
src/preview.h
src/utilities.h
src/PerformanceTimer.h
src/cfg.h
src/microface.h
src/cudaUtils.cuh
src/sampler.h
src/cudahelper.h
src/disney.h
src/Constants.h
external/include/raytrace/gltf-loader.h
)

set(sources
src/bvh.cpp
src/main.cpp
src/stb.cpp
src/image.cpp
src/glslUtility.cpp
src/pathtrace.cu
src/scene.cpp
src/sceneStructs.cpp
src/preview.cpp
src/utilities.cpp
src/sampler.cpp
src/cudahelper.cpp
#external/include/raytrace/gltf-loader.cc
)

#set(scenestxt
# scenes/cornell.txt
# scenes/cornell_dof_example.txt
# scenes/cornell_fresnel.txt
# )
#file(GLOB scenestxt scenes/*.txt)

list(SORT headers)
list(SORT sources)
#list(SORT scenestxt)

source_group(Headers FILES ${headers})
source_group(Sources FILES ${sources})
#source_group(Scenes FILES ${scenestxt})

#add_subdirectory(stream_compaction) # TODO: uncomment if using your stream compaction

Expand Down
215 changes: 210 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,216 @@ 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)
* Ling Xie
* [LinkedIn](https://www.linkedin.com/in/ling-xie-94b939182/),
* [personal website](https://jack12xl.netlify.app).
* Tested on:
* Windows 10, Intel(R) Xeon(R) CPU E5-2650 v4 @ 2.20GHz 2.20GHz ( two processors)
* 64.0 GB memory
* NVIDIA TITAN XP GP102

### (TODO: Your README)
Thanks to [FLARE LAB](http://faculty.sist.shanghaitech.edu.cn/faculty/liuxp/flare/index.html) for this ferocious monster.

*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.
#### Intro

Yet another Path tracer written in CUDA.

### Current feature

##### BxDF

- [x] Diffuse
- [x] Specular
- [x] perfect Specular
- [x] imperfect Specular
- [x] Refraction
- [x] Schlick Fresnel approximate
- [ ] Micro-face
- [x] Reflection
- [ ] Transmission


##### Better Sample

- [x] stratified sampling ( Results not obvious though )
- [x] Anti-aliasing
- [x] Multiple Importance Sampling

##### Visual effects

- [x] lens based depth of field
- [x] motion blur

##### IO

- [x] Load GLTF based on tiny_gltf ( kind of buggy though)
- [x] bounding box per mesh
- [x] Linear BVH

##### Speed Optimization

- [x] Path continuation/termination with thrust
- [x] First bounce cache
- [x] contiguous memory shuffle by material sort

#### Demo Gallery

![alt text](https://github.com/Jack12xl/public_file/raw/master/CIS565-GPU/PathTracer/cornell_box_v002.png)

Since I'm not good at setting up fascinating scenes, here I borrow scenes settings from [jmrcao](https://github.com/jmarcao) as a fast test for my algorithm. Thanks **jmrcao**!

##### Imperfect specular

Combing diffuse scattering and specular reflection can bring more vivacity and realness to the material. Here we randomly decide to do diffuse or specular based on the material shininess property. From left to right, shininess ranges from **5** to **Inf**.

![alt text](https://github.com/Jack12xl/Project3-CUDA-Path-Tracer/blob/master/img/imperfect_spec.png)

##### Refractive transmission

Refraction basically refers to light transmitting from material to another material based on index of refraction(**IOR**). Here I assume the atmosphere is surrounded with Air (**IOR** = 1). After some critical angle for a certain **IOR**, it would cause total internal reflection.

Here, from left to right, the index of refraction keeps increasing from 1 (Air) to 2.42(diamond), whose setting is exactly the same as [jmarcao](https://github.com/jmarcao/CUDA-Path-Tracer#refractive-transmission-scattering-function). So it achieves a comparable result with former.

![alt text](https://github.com/Jack12xl/Project3-CUDA-Path-Tracer/blob/master/img/refraction.png)



##### Fresnel effect

It refers to the phenomenon that reflections easily appear when infer angle is smaller. Here I use [Shlick's approximation](https://en.wikipedia.org/wiki/Schlick%27s_approximation) to fit the ideal curve that light would transmit through or simply reflect on expectation.

Notice in the followed light starts to reflect in a narrower angle. After some critical angle, it directly transmits through the material.

![alt text](https://github.com/Jack12xl/Project3-CUDA-Path-Tracer/blob/master/img/fresnel.png)

#### Stratified sampling

Compared with uniform sampling, stratified sampling basically subdivides area and then sample in each block, which could reduces clustering of samples and bring little noise especially around the edge.

However, in my implementation, the results basically demonstrate comparable results between stratified and uniform sampling.

![alt text](https://github.com/Jack12xl/Project3-CUDA-Path-Tracer/blob/master/img/sample_camparison.png)



#### Anti-aliasing

Here I implement the anti-aliasing by randomly jitter the ray shot from camera.

As you can see, the **left** is anti-aliasing, which a smoother edge than the right one.

![alt text](https://github.com/Jack12xl/Project3-CUDA-Path-Tracer/blob/master/img/compare_jitter.png)

#### Multiple Importance Sampling

Here showed three surfaces ranging from very smooth (top) to very rough (bottom) illuminated by spherical light sources of decreasing size and rendered with different sampling techniques

As explained in [PBRT 14.3.1](https://pbr-book.org/3ed-2018/Light_Transport_I_Surface_Reflection/Direct_Lighting), sampling the `BSDF` is more effective for highly specular materials and large light sources, while sampling the light source is better on small sources and rough materials

| MIS | ![](https://github.com/Jack12xl/public_file/raw/master/CIS565-GPU/PathTracer/MIS.png) |
| ------------------ | ------------------------------------------------------------ |
| Sample `BSDF` only | ![](https://github.com/Jack12xl/public_file/raw/master/CIS565-GPU/PathTracer/sample_bsdf.png) |
| Sample Light only | ![](https://github.com/Jack12xl/public_file/raw/master/CIS565-GPU/PathTracer/sample_light.png) |



### Visual effects

##### Depth of field

To simulate a real camera(with circle of confusion), instead of shooting rays from camera center as default, here we shoot rays from a small concentric disk with given radius **r** and focal distance **f**.

Here **r** = 0.5, **f** = 15.

![alt text](https://github.com/Jack12xl/Project3-CUDA-Path-Tracer/blob/master/img/dof.png)



**Motion blur**

To simulate a scene with the effect like time of exposure and moving objects, we randomly change the objects transform along its given speed. How much the motion would "blur " depends on its magnitude of speed.

![alt text](https://github.com/Jack12xl/Project3-CUDA-Path-Tracer/blob/master/img/motion_blur.png)



### glTF mesh loading

Here we implement the glTF loading function, which can load the glTF format mesh.

![alt text](https://github.com/Jack12xl/public_file/raw/master/CIS565-GPU/PathTracer/test_gltf.png)

##### Bounding box

A bounding box is created to do ray intersection culling. Which could avoid unnecessary ray-triangle intersection.

**Linear BVH**(to opimize)

Constructed on CPU(Static scene, so we only construct once), traverse on GPU. Currently, traversing with BVH is even slower than the **bounding box** method. Through profiling with **Nsight Compute**, the throughput is very low(`23.67%`). Maybe it's due to the warp-divergence(caused by `for loop` and `if`) when traversing the tree.

### First bounce cache

Basically, first bounce cache is a time-space trade-off that using memory to store the first intersection results, then in further iterations when `depth == 1`read them(instead of calculating.)

##### Here shows the results

![alt text](https://github.com/Jack12xl/Project3-CUDA-Path-Tracer/blob/mid-submit/img/First_bounce_cache.svg)

Well, obviously cache can trigger more performance with same results.

**Warning** when those (motion blur, material sort) with random ray are applied, we can not use first bounce cache here.



### **Material Sort**

Material sort tries to sort the shader working sequence on material ID, which can makes threads do the same job as much as possible.

| | With material sort | Without |
| ------------------------------ | ------------------- | ------------------- |
| **Elapsed time per iteration** | 122.94 milliseconds | 62.412 milliseconds |

However, for scenes simple like Cornell box, the more contiguous memory read can not cover the overhead of sorting(we use thrust::sort, basically a O(n) radix sort).



#### Blooper

##### Wrong GLTF model loading

Funny thing, I debugged this for almost 1.5 years haha.

![alt text](https://github.com/Jack12xl/Project3-CUDA-Path-Tracer/blob/master/img/gltf_load.svg)

![alt text](https://github.com/Jack12xl/Project3-CUDA-Path-Tracer/blob/master/img/bloopers/failed_dof.png)

![alt text](https://github.com/Jack12xl/Project3-CUDA-Path-Tracer/blob/master/img/bloopers/wrong1.png)

![alt text](https://github.com/Jack12xl/Project3-CUDA-Path-Tracer/blob/master/img/bloopers/wrong2.png)

![alt text](https://github.com/Jack12xl/Project3-CUDA-Path-Tracer/blob/master/img/bloopers/wrong3.png)

![alt text](https://github.com/Jack12xl/Project3-CUDA-Path-Tracer/blob/master/img/bloopers/wrong4.png)



### Acknowledgement

[CUDA PATH Tracer](https://github.com/jmarcao/CUDA-Path-Tracer) by [Jmarcao](https://github.com/jmarcao): for the test scene he provides.

[tiny_gltf](https://github.com/syoyo/tinygltf) by [syoyo](https://github.com/syoyo)

[Ray tracing in one weekend](https://raytracing.github.io/books/RayTracingInOneWeekend.html)

For fast look up

[Physically based rendering](http://www.pbr-book.org/)

The most comprehensive book I ever found.

[Comparing hemisphere sampling techniques for obscurance computation](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.468.4690&rep=rep1&type=pdf)

for stratified sampling.

####

Loading