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
71 changes: 66 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,72 @@ 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)
* Yuru Wang
* Tested on: Windows 10, i7-7700HQ @ 2.5GHz 128GB, GTX 1050 Ti 8GB (personal computer)
* Modified CMakeList.txt: changed sm_20 to sm_61 inside cuda_add_library

### (TODO: Your README)
## Project Description ##
This project implements a CUDA-based path tracer capable of rendering globally-illuminated images very quickly.

*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.
A list of features implemented in this project is as follows:
* A shading kernel with BSDF evaluation
* Path continuation/termination using Stream Compaction (with thrust::remove_if)
* Sorting paths by material types (with thrust::sort_by_key)
* Cache first bounce intersections for re-use.
* **Physically-based depth-of-field** by jittering rays within an aperture
* **Stochastic Sampled Antialiasing**
* **Refraction with Snell's law**
* **Motion blur** by averaging samples at different times in the animation

## Results ##
All images below are rendered with 5000 samples and 8 depths.

### Basic Path tracer
![](img/basic.png)

### Different Materials
_Perfect surfaces_
![](img/three_materials.png)

Left to right: Ideal diffuse surface, Perfectly specular-reflective surface, and fully refractive surface

_Composite materials_
![](img/composite_materials.png)

Left to right (reflect/refract/diffuse): 0.3/0.0/0.7, 0.3/0.3/0.4, 0、0.5/0.5.
Light emissive: 10

### Depth of field
![](img/DOF.png)

Reference for Concentric Sample Disk function from https://www.dartdocs.org/documentation/dartray/0.0.1/core/ConcentricSampleDisk.html

### Motion blur
| Without Motion Blur | With Motion Blur |
|------|------|
| ![](img/without_motionBlur.png) | ![](img/motion_blur.png) |

The cube has a velocity of 1 along y axis, and rotates about its z axis by 45 degrees.

### Antialiasing
| Without AA | With AA |
|------|------|
| ![](img/without_antialiazing.png) | ![](img/with_antialiazing.png) |

## Performance Analysis and Questions ##
![](img/numOfPathsRemaining.png)

The x horizontal axis of above diagram represents the number of remaining trace depths. As shown on the diagram above, at the end of each bounce, the number of remaining rays is decreasing. The performance regarding stream compaction is explained below.

![](img/performanceWithOptimizations.png)

The above figure showing the performances of each optimization tricks. Caching the first bounce intersections did slightly better job than no caching, which is expected because it eliminates one kernel call (calculating initial rays) per iteration. However, unexpectedly, with stream compaction and sorting rays did not actually improve the performance and they even slow down the rendering. I guess that because I used thrust::remove if and thrust::sort_by_key to perform stream compaction and sorting, these two function calls have large overhead which costs more time than directly shading simple materials and geometries. I guess the advantage of using stream compaction and sorting rays would pay off when render large amount of rays/depths and render complex materials.

![](img/open_closed.png)

It can be observed from the diagram above that with stream compaction, the performance is worse than without stream compaction in both open and closed case. As I mentioned above, thrust::remove_if has overhead which kills its advantage in my simple scene settings. However, we can still observe the fact that, with stream compaction, performance in open space is way better than closed space. This is because in open space, many rays would shoot out from the box at every iteration, which means the number of eligible rays would decrease quicker than that in closed box. While for the closed case, all rays are bouncing off in the box until they hit the light source or reach the maximum number of bounces, in which case the stream compaction could only eliminates less rays than that in open space.

## Debugging Log ##
![](img/bug.png)

This bug is caused by forgetting to add a small offset to the origin of each new ray. Forgetting to do so makes calculating intersections for those new rays get errors (always get the same intersections as last bounce so that those rays are not able to reach light source)
Binary file added img/DOF.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added img/bug.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/composite_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/cornell.2018-09-29_01-50-57z.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/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/numOfPathsRemaining.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/open_closed.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/performanceWithOptimizations.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/three_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/with_antialiazing.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/without_antialiazing.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/without_motionBlur.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
145 changes: 145 additions & 0 deletions scenes/cornell-3materials.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// Emissive material (light)
MATERIAL 0
RGB 1 1 1
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 .85 .35 .35
SPECEX 0
SPECRGB 0 0 0
REFL 0
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 .98 .98 .98
REFL 1
REFR 0
REFRIOR 0
EMITTANCE 0

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

// Camera
CAMERA
RES 800 800
FOVY 45
FOCUS_DIST 11
LENS_RADIUS 1
ITERATIONS 5000
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
sphere
material 1
TRANS 0 2 -1
ROTAT 0 0 0
SCALE 3 3 3

// Sphere
OBJECT 7
sphere
material 4
TRANS -3 2 -1
ROTAT 0 0 0
SCALE 3 3 3

// Sphere
OBJECT 8
sphere
material 5
TRANS 3 2 -1
ROTAT 0 0 0
SCALE 3 3 3
171 changes: 171 additions & 0 deletions scenes/cornell-DOF.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
// Emissive material (light)
MATERIAL 0
RGB 1 1 1
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 10

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

// Camera
CAMERA
RES 800 800
FOVY 45
FOCUS_DIST 2.5
LENS_RADIUS 0.2
ITERATIONS 5000
DEPTH 8
FILE cornell
EYE 2 2 2
LOOKAT 0 2 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
sphere
material 4
TRANS 0 1 -3
ROTAT 0 0 0
SCALE 2 2 2

// Sphere
OBJECT 7
sphere
material 4
TRANS 0 1 -0
ROTAT 0 0 0
SCALE 2 2 2


// Sphere
OBJECT 8
sphere
material 4
TRANS 0 1 3
ROTAT 0 0 0
SCALE 2 2 2


// Sphere
OBJECT 9
sphere
material 4
TRANS 0 1 5
ROTAT 0 0 0
SCALE 2 2 2


// Sphere
OBJECT 10
sphere
material 4
TRANS 0 1 -5
ROTAT 0 0 0
SCALE 2 2 2

// Sphere
OBJECT 11
sphere
material 4
TRANS 2.5 1 3.5
ROTAT 0 0 0
SCALE 2 2 2

// Sphere
OBJECT 12
sphere
material 4
TRANS -4 1 -1
ROTAT 0 0 0
SCALE 2 2 2

Loading