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
9b5e5ab
basic pathtracing working
Sep 22, 2017
56c17c0
implemented reflection and diffuse combined
Sep 22, 2017
1958d58
Added stream compaction files and edited pathtrace
Sep 25, 2017
7afee0f
added EPSILON to remove 1 artifact
Sep 25, 2017
0174444
added thrust stream compaction
Sep 25, 2017
8713093
Update cornell.txt
Sep 25, 2017
f0274f7
more changes
Sep 25, 2017
98c1dc5
Merge remote-tracking branch 'origin/master'
Sep 25, 2017
7794e14
Update cornell.txt
Sep 25, 2017
f05b3f1
added images
Sep 25, 2017
4bc4ec6
Merge remote-tracking branch 'origin/master'
Sep 25, 2017
bc7860e
made scene changes
Sep 25, 2017
2503607
cached first bounce
Sep 26, 2017
9162200
sorted by materials
Sep 26, 2017
4b08837
Update cornell.txt
Sep 28, 2017
61c62e1
Merge remote-tracking branch 'origin/master'
Sep 28, 2017
d2271a2
basic refraction
Sep 28, 2017
3bdbcf8
trying to make refraction work - debugging
Sep 28, 2017
8829b46
refraction without diffuse working
Sep 29, 2017
d484370
depth of field more or less working
Sep 29, 2017
bda7fdc
added some direct lighting parameters
Sep 29, 2017
559060e
direct lighting works with one ceiling light
Sep 29, 2017
02ccf48
direct lighting finished
Sep 29, 2017
f7866c8
images
Sep 29, 2017
93b67bd
profiling data gathering
Oct 1, 2017
7d087f7
charts
Oct 2, 2017
5f7d296
Added Analysis
Oct 2, 2017
4c1cb09
Update README.md
Oct 2, 2017
2c4bc9d
Update README.md
Oct 2, 2017
174cba2
Update README.md
Oct 2, 2017
29c3acd
Update README.md
Oct 2, 2017
9d917ed
Update README.md
Oct 5, 2017
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
72 changes: 67 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,73 @@ 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)
* Name: William Ho
* Email: willho@seas.upenn.edu
* Tested on: Windows 7 Professional, i7-6700 @ 3.40 GHz 16.0GB, NVIDIA QuadroK620 (Moore 100C Lab)

### (TODO: Your README)
## Overview

*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.
![](img/cornell.2017-10-01_22-16-11z.5000samp.png)

This is an implementation of a GPU pathtracer. Due to how easy it tends to make it to simulate physically accurate light behavior, pathtracing has become a popular technique for rendering 3D scenes.

At its core, pathtracing is a technique that employs rays shot out of a virtual camera, which bounce around our 3D scene until they strike a light source, from which we can compute the rays contribution to a pixel color. The computations for evaluating our rays are easily parallelizable, making pathtracing a particularly good candidate for implementation on the GPU.

## Basic Pathtracer

![](img/cornell.2017-09-25_17-27-16z.1146samp.png)

The first iteration of my pathtracer employed basic Bidirectional Scattering Distribution Functions (BSDF) for diffuse and reflective surfaces. Diffusion was uniform distribution and reflection was perfect reflection.

## Additional Features

### Refraction

![](img/cornell.2017-09-29_01-47-17z.1109samp.png)

Refraction behaviors occur when light moves through a medium. Since light travels at different speed in different materials, it can be said to bend upon moving from one medium to another.

### Direct Lighting
![](img/cornell.2017-09-29_19-20-16z.83samp.png)
One technique for adding shaper shadows to a pathtraced image, and terminating rays faster, is to calculate some rays through direct lighting. That is to say, instead of computing bounces through a BSDF, one instead computes a bounce directly to a light by sampling points on lights in the scene.

### Depth of Field

![](img/cornell.2017-10-01_21-45-41z.3000samp.png)

Real-world cameras use lenses, which refract light in such a way as to make images clearer at a focal distance away from the camera.

## Optimizations and Evaluations

### Stream Compaction
Once a ray hits a light source, or fails to interesect an object in the scene and can be said to have "escaped" (i.e. gone out of a window or opening in the scene), we can terminate that ray and flag it as no longer necessary to evaluate. This allows us to use **Stream Compaction** to cull our unnecessary rays. (See my exploration into Stream Compaction [here]()) For this pathtracer, I used [Thrust's]() partition implementation.

![](img/RaysStreamCompact.PNG)
![](img/TimeStreamCompact.PNG)

These charts show a comparison between the efficacy of Stream Compaction in our open Cornell box scene and our closed Cornell Box scene. As to be expected in our open scene, where the open box allows a large number of rays to escape, we gain significant speed improvements in subsequent ray bounces by culling rays. The wins in the closed Cornell Box Scene are not as dramatic, as the only rays we can cull are those which intersect a light source. Still, this optimization still proves useful.

### First Bounce Caching
Since we generate the same set of rays from the camera on every iteration, computing these rays' first intersections really only needs to be done once. Thus, for consecutive iterations of our pathtracer for which the camera location and the scene objects locations remain the same, we can store our first bounce iterations.

![](img/FirstBounce.PNG)

Here, we see that caching the first bounce is a somewhat effective optimization, one which compounds as I perform more iterations over a single image. However, its benefit decreases as I increase the maximum depth of our paths, as only our first bounce is pre-determined.

### Sorting Paths and Intersections by Materials
The memory access patterns of my kernels could use significant optimization. I experimented with preprocesssing my paths and intersections between bounce calculations; sorting them so that intersections on the same materials would be contiguous in memory. I do not believe my kernels currently leverage the advantages of having contiguous data. this might require separating out my materials evaluation into separate per-material kernels. However, it is still useful to include a visual on this attempted optimization.

![](img/SortByMaterial.PNG)

## The Process
![](img/basicPathTracer001.png)
![](img/basicPathTracer003.png)
![](img/cornell.2017-09-29_03-02-34z.54samp.png)
![](img/cornell.2017-09-28_19-31-31z.7samp.png)
![](img/cornell.2017-09-28_18-29-39z.10samp.png)
![](img/cornell.2017-09-26_15-32-21z.105samp.png)

## References
[Path Tracing Lecture Slides](https://docs.google.com/presentation/d/1q3h2GVDorEFzmESNfFwR6mODnzS6WbftiVsvaFNGihQ/edit)
Physically Based Rendering by Greg Humphrey

Binary file added img/BaseClosed.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/BaseOpen.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/FirstBounce.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/Iteration16ClosedFirstBounce.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/Iteration16ClosedNoFirstBounce.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/Iteration16FirstBounce.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/Iteration16FirstBounceNoDL.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/Iteration16NoFirstBounce.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/Iteration16NoFirstBounceNoDL.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/Iteration16NoFirstBounceSorted.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/Iteration8NoFirstBounce.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/RaysStreamCompact.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/SortByMaterial.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/TimeStreamCompact.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/basicPathTracer001.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/basicPathTracer002.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/basicPathTracer003.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.2017-09-25_02-07-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.2017-09-25_17-14-46z.181samp.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.2017-09-25_17-27-16z.1146samp.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.2017-09-26_15-32-21z.105samp.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.2017-09-26_15-32-21z.45samp.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.2017-09-26_15-32-21z.5samp.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.2017-09-26_15-38-53z.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.2017-09-28_17-01-04z.29samp.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.2017-09-28_18-29-39z.10samp.png
Binary file added img/cornell.2017-09-28_19-31-31z.5samp.png
Binary file added img/cornell.2017-09-28_19-31-31z.7samp.png
Binary file added img/cornell.2017-09-28_19-31-31z.8samp.png
Binary file added img/cornell.2017-09-29_01-47-17z.1109samp.png
Binary file added img/cornell.2017-09-29_01-57-06z.633samp.png
Binary file added img/cornell.2017-09-29_02-56-41z.1315samp.png
Binary file added img/cornell.2017-09-29_03-02-34z.54samp.png
Binary file added img/cornell.2017-09-29_03-32-32z.1978samp.png
Binary file added img/cornell.2017-09-29_04-11-02z.2671samp.png
Binary file added img/cornell.2017-09-29_18-38-55z.15samp.png
Binary file added img/cornell.2017-09-29_19-09-42z.137samp.png
Binary file added img/cornell.2017-09-29_19-20-16z.83samp.png
Binary file added img/cornell.2017-09-29_19-25-03z.113samp.png
Binary file added img/cornell.2017-09-29_19-26-35z.175samp.png
Binary file added img/cornell.2017-09-29_19-41-14z.1132samp.png
Binary file added img/cornell.2017-10-01_21-05-23z.2015samp.png
Binary file added img/cornell.2017-10-01_21-29-08z.5000samp.png
Binary file added img/cornell.2017-10-01_21-45-41z.1913samp.png
Binary file added img/cornell.2017-10-01_21-45-41z.2429samp.png
Binary file added img/cornell.2017-10-01_21-45-41z.2997samp.png
Binary file added img/cornell.2017-10-01_21-45-41z.3000samp.png
Binary file added img/cornell.2017-10-01_22-16-11z.5000samp.png
226 changes: 226 additions & 0 deletions scenes/DepthofField.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
// Emissive material (light)
MATERIAL 0
RGB 1 1 1
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 13

// 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

// Reflective blue
MATERIAL 5
RGB 0.6 0.6 0.98
SPECEX 0
SPECRGB .98 .98 .98
REFL 1
REFR 0
REFRIOR 0
EMITTANCE 0

//Glass
MATERIAL 6
RGB 0.2 0.2 0.98
SPECEX 0
SPECRGB .98 .98 .98
REFL 1
REFR 1
REFRIOR 1.5
EMITTANCE 0

// Camera
CAMERA
RES 800 800
FOVY 45
ITERATIONS 5000
DEPTH 3
FILE cornell
EYE 0 5.5 6.5
LOOKAT 0 5 0
UP 0 1 0


// Ceiling light
OBJECT 0
cube
material 0
TRANS -1 10 5
ROTAT 0 0 0
SCALE 3 0.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 2
TRANS -3 4 -5
ROTAT 0 0 0
SCALE 1 1 1

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

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

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

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

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

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

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

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

// Sphere
OBJECT 15
sphere
material 3
TRANS 2.4 4 4
ROTAT 0 0 0
SCALE 1 1 1


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

//Table
OBJECT 17
cube
material 6
TRANS 0 3.4 0
ROTAT 0 0 0
SCALE 10 0.2 10
56 changes: 54 additions & 2 deletions scenes/cornell.txt
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,32 @@ REFR 0
REFRIOR 0
EMITTANCE 0

// Reflective blue
MATERIAL 5
RGB 0.6 0.6 0.98
SPECEX 0
SPECRGB .98 .98 .98
REFL 1
REFR 0
REFRIOR 0
EMITTANCE 0

//Glass
MATERIAL 6
RGB 0.98 0.98 0.98
SPECEX 0
SPECRGB .98 .98 .98
REFL 1
REFR 1
REFRIOR 1.5
EMITTANCE 0

// Camera
CAMERA
RES 800 800
FOVY 45
ITERATIONS 5000
DEPTH 8
DEPTH 64
FILE cornell
EYE 0.0 5 10.5
LOOKAT 0 5 0
Expand Down Expand Up @@ -111,7 +131,39 @@ SCALE .01 10 10
// Sphere
OBJECT 6
sphere
material 4
material 6
TRANS -1 4 -1
ROTAT 0 0 0
SCALE 3 3 3

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

// Light 2
//OBJECT 7
//cube
//material 0
//TRANS 0 0 0
//ROTAT 0 0 0
//SCALE 3 .3 3

// Blue Cube
OBJECT 8
cube
material 5
TRANS 2 5 -2
ROTAT .5 -45 0
SCALE 4 4 0.3

//Refractive sphere
OBJECT 9
cube
material 6
TRANS 0 1 0
ROTAT 0 0 0
SCALE 8 .1 8
Loading