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
96 changes: 91 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,97 @@ 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)
* Wanru Zhao
* [LinkedIn](www.linkedin.com/in/wanru-zhao).
* Tested on: Windows 10, Intel(R) Core(TM) i7-8750H [email protected], GTX 1070 with Max-Q Design(Personal Laptop)

### (TODO: Your README)
### Final
<p align="middle">
<img src="img/final/cornell.2018-10-02_07-15-51z.10000samp.png" width="432" />
<img src="img/final/cornell.2018-10-02_07-43-16z.10000samp.png" width="432" />
</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

- Shading kernel with BSDF features: diffuse and perfectly specular
- Path termination with stream compaction
- Material sort
- First cache
- Refraction with fresnel effects
- Physically based depth of field
- Stochastic sampled antialiasing
- Direct lighting
- Motion blur

### Analysis
#### Stream compaction

In each iteration, apply stream compaction on pathsegments according their remaining bounces after each bounce, remove the pathsegments with 0 remaining bounce, and adjust the number of launched threads. When there is no pathsegments alive left, bouncing can be terminated earlier.

![](img/final/raybounce.png)


#### Cache first intersection

Cache first intersection at the first bounce and first iteration. Cached data is used for initializing following iterations as results for first bounce. This skips the same intersection calculation. (Since this assuming the intersectionsof first bounce are always the same, this cannot be used with antialiasing.)

![](img/final/Running-Time-Comparison-WO-First-Cache.png)

From above image, we can see for depth from 6 to 16, performance with cache first intersection is slightly better than naive way, for it reduces the calculation of first bounce for iteration 2 to iteration 5000. However, when bounce count increases from 16 to 20, performance of caching is worse than naive way. I think this is because when bounce times is large enough and the number of iterations is the same, the benefit from reducing first bounce calculation can not exceed the increasing cost of branching.

#### Material sort

Sort the rays/path segments so that rays/paths interacting with the same material are contiguous in memory before shading.

![](img/final/materialsort.png)

The performance of material sort is much worse than naive way, since it does the sorting each bounce each iteration, which consumes a lot of time. This might be optimized by better sorting algorithm and the following optimization of shading with different materials.

#### Different materials

Diffuse, perfect specular, refraction (5000 iterations, 8 bounces)

![](img/final/cornell.2018-10-02_03-44-40z.5000samp.png)

#### Antialiasing

Perform antialiasing by jittering ray direction calculated by camera and averaging results of multiple iterations.

(5000 iterations, 8 bounces)

<p align="middle">
<img src="img/final/origin.PNG" width="300"/>
</p>

<p align="middle">
<img src="img/final/anti.PNG" width="300"/>
</p>


#### Depth of field

Jitter the ray origin and direction from camera according to lens effects.

DOF
:--:
![](img/final/cornell.2018-09-29_21-38-52z.5000samp.png)
(5000 iterations, 8 bounces, len radius 0.5, focal distance 7.0)


#### Direct lighting

Take the final ray directly to a random point on an emissive object.

Sample final ray direction | Without direct lighting | Direct lighting
:--:|:--:|:--:
![](img/final/cornell.2018-10-02_01-06-49z.10samp.png) | ![](img/final/cornell.2018-10-02_02-18-51z.5000samp-streamcompact.png) | ![](img/final/cornell.2018-10-02_03-13-11z.5000samp.png)
(5000 iterations, 8 bounces) |(5000 iterations, 8 bounces)| (5000 iterations, 8 bounces)

#### Motion blur

Average samples at different times in the animation.

Motion Blur
:--:
![](img/final/cornell.2018-10-02_03-23-43z.5000samp.png)
(5000 iterations, 8 bounces)
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/final/anti.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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/final/cornell.2018-10-02_01-06-49z.10samp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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/final/materialsort.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/final/origin.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/final/raybounce.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion scenes/cornell.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ material 0
TRANS 0 10 0
ROTAT 0 0 0
SCALE 3 .3 3
MOTION 0

// Floor
OBJECT 1
Expand All @@ -75,6 +76,7 @@ material 1
TRANS 0 0 0
ROTAT 0 0 0
SCALE 10 .01 10
MOTION 0

// Ceiling
OBJECT 2
Expand All @@ -83,6 +85,7 @@ material 1
TRANS 0 10 0
ROTAT 0 0 90
SCALE .01 10 10
MOTION 0

// Back wall
OBJECT 3
Expand All @@ -91,6 +94,7 @@ material 1
TRANS 0 5 -5
ROTAT 0 90 0
SCALE .01 10 10
MOTION 0

// Left wall
OBJECT 4
Expand All @@ -99,6 +103,7 @@ material 2
TRANS -5 5 0
ROTAT 0 0 0
SCALE .01 10 10
MOTION 0

// Right wall
OBJECT 5
Expand All @@ -107,11 +112,13 @@ material 3
TRANS 5 5 0
ROTAT 0 0 0
SCALE .01 10 10
MOTION 0

// Sphere
OBJECT 6
sphere
material 4
TRANS -1 4 -1
TRANS 0 3 0
ROTAT 0 0 0
SCALE 3 3 3
MOTION 1
190 changes: 190 additions & 0 deletions scenes/cornellbox.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
// Emissive material (light)
MATERIAL 0
RGB 0.96 0.69 0.25
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 20

// 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 .85 .35 .35
REFL 0.6
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 1 1 1
REFL 0.2
REFR 0.8
REFRIOR 1.5
EMITTANCE 0

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

// Emissive material (light)
MATERIAL 6
RGB 0.36 0.67 0.88
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 20

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

// Camera
CAMERA
RES 800 800
FOVY 45
ITERATIONS 10000
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 -5 16 0
ROTAT 0 0 0
SCALE 3 .3 3
MOTION 0

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

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

// Back wall
OBJECT 3
cube
material 1
TRANS 0 8 -8
ROTAT 0 90 0
SCALE .01 16 16
MOTION 0

// Left wall
OBJECT 4
cube
material 2
TRANS -8 8 0
ROTAT 0 0 0
SCALE .01 16 16
MOTION 0

// Right wall
OBJECT 5
cube
material 3
TRANS 8 8 0
ROTAT 0 0 0
SCALE .01 16 16
MOTION 0

// Box
OBJECT 6
sphere
material 5
TRANS -2 1.5 -2
ROTAT 0 0 0
SCALE 3 3 3
MOTION 0

// Box
OBJECT 7
sphere
material 7
TRANS 2 1.5 0
ROTAT 0 0 0
SCALE 3 3 3
MOTION 0

// Ceiling light
OBJECT 8
cube
material 6
TRANS 5 16 0
ROTAT 0 0 0
SCALE 3 .3 3
MOTION 0

// Sphere
OBJECT 9
sphere
material 4
TRANS -1 1.5 2
ROTAT 0 0 0
SCALE 3 3 3
MOTION 0

// Back wall
OBJECT 10
cube
material 1
TRANS 0 8 8
ROTAT 0 90 0
SCALE .01 16 16
MOTION 0
Loading