Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project 3: DAVID GROSMAN #16

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
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
46 changes: 38 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
CUDA Path Tracer
================
# University of Pennsylvania, CIS 565: GPU Programming and Architecture.
Project 3 CUDA: Path Tracer
====================

**University of Pennsylvania, CIS 565: GPU Programming and Architecture, Project 3**
## User resources
- **Name:** David Grosman.
- **Tested on:** Microsoft Windows 7 Professional, i7-5600U @ 2.6GHz, 256GB, GeForce 840M (Personal laptop).

* (TODO) YOUR NAME HERE
* Tested on: (TODO) Windows 22, i7-2222 @ 2.22GHz 22GB, GTX 222 222MB (Moore 2222 Lab)
## Project description
This Project's purpose was to gain some experience with writing Graphics code that would benefit as much as possible from CUDA as possible. In fact, a path tracer is a very useful type of application to run on Cuda since each ray processed by the application can be done in a separate thread. Furthermore, computations such as intersection-testing and pixel coloring are very intensive and are thus most usefully done on GPU. Furthermore, there is no memory bandwidth from CPU to GPU to pass on the pixel buffer as is usually the case in a CPU implementation.
In this project, I have implemented several key features such as:

### (TODO: Your README)
1. Diffuse shading
2. Specular reflection and refraction.
3. Caching Initial rays.
4. Stream compaction on non-terminated paths during each iteration.
5. Sort Rays by material type they are intersecting with.
6. Depth of Field.
7. Better hemisphere sampling methods.

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


###Shading: Diffuse and Specular reflection, refraction.
The shading implemented for this project is pretty straight-forward and is inspired from http://graphics.stanford.edu/courses/cs148-10-summer/docs/2006--degreve--reflection_refraction.pdf. The reflectance factor used to determine how much of the reflecting vs. refracting ray to use for the final color was implemented using the Schlik's approximation, which is pretty Schlik. The ray used to determine the diffuse color is actually a cosine weighted hemisphere where there are fewer rays along the horizon and increase density as we go up.
![](img/RefrAndRefl.JPG)

###Caching Initial rays.
Since all initial rays go from the camera's position to each pixel of the screen, it is easy to cache the first intersection of each ray since they stay constant until the camera (or scene objects) move again. Unfortunately, there isn't much performance gain from doing this since we must not only use a lot of memory to store the intersections but we also only use them for the first ray bounce which is often a small portion of the time the path-tracer determines new intersections since each ray must bounce at least 8 times to get nice global illumination effects.

###Stream compaction on non-terminated paths.
As shown on the graph below, the performance increase in compacting non-terminated paths is non-negligent, especially when increasing the number of bounces per ray. This is the most important optimization done for this project.
![](img/PerfGivenRayBounces.JPG)

###Sort Rays by material type they are intersecting with.
This is an optimization which actually decreased the performance of the application: The time spent sorting the rays is non-negligeable, especially when there are so many rays and not space or time-coherent scheme is adopted to sort the rays faster. This optimization should be tested on Waverfont pathtracing where rays are grouped by material without a sorting pass.

###Depth of Field.
Depth of field is an easy technique to implement when ray-tracing since the only change is how rays are generated. In fact their origin should be located on the lens and their direction should be towards a point that is at a dustance specified by the focal distance.
![](img/DOF.JPG)

###Better hemisphere sampling methods.
I implemented Jittered, Halton and Sobel Pseudo-Random generators to improve the cosine weighted hemisphere generated when computing the diffuse component. Quasi-Random numbers as generated by Halton and Sobel schemes is pretty powerful since they can issue sequences of numbers specifically designed to fill an interval (typically [0…1] in n-dimensional space) in a relatively uniform way (compared to purely random or pseudo-random). In fact, each new number (or vector) in the sequence is spaced as far as possible from the previous ones. Their goal is to be able to generate randomized, but relatively uniformly spaced patterns, similar to jittering, but not requiring knowledge ahead of time about the total number of samples.
![](img/RefrOnRefl.JPG)
Binary file added img/DOF.JPG
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/PerfGivenRayBounces.JPG
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/RefrAndRefl.JPG
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/RefrOnRefl.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 6 additions & 4 deletions scenes/cornell.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ MATERIAL 4
RGB .98 .98 .98
SPECEX 0
SPECRGB .98 .98 .98
REFL 1
REFR 0
REFRIOR 0
REFL 0
REFR 1
REFRIOR 1.33
EMITTANCE 0

// Camera
Expand All @@ -58,6 +58,8 @@ FILE cornell
EYE 0.0 5 10.5
LOOKAT 0 5 0
UP 0 1 0
LENS_RADIUS 0.0
FOCAL_LENGTH 0.0


// Ceiling light
Expand Down Expand Up @@ -114,4 +116,4 @@ sphere
material 4
TRANS -1 4 -1
ROTAT 0 0 0
SCALE 3 3 3
SCALE 3 3 3
139 changes: 139 additions & 0 deletions scenes/cornellDOF.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// 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 0
REFR 1
REFRIOR 1.15
EMITTANCE 0

// Specular white
MATERIAL 5
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 5000
DEPTH 16
FILE cornell
EYE 0.0 5 10.5
LOOKAT 0 5 0
UP 0 1 0
LENS_RADIUS 0.5
FOCAL_LENGTH 5.5


// 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 5
TRANS -1 4 -1
ROTAT 0 0 0
SCALE 3 3 3


// Sphere
OBJECT 7
sphere
material 4
TRANS -1 4 4
ROTAT 0 0 0
SCALE 3 3 3
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ set(SOURCE_FILES
"preview.cpp"
"utilities.cpp"
"utilities.h"
"timer.cu"
"timer.h"
)

cuda_add_library(src
Expand Down
Loading