Skip to content

Project 3: Xueyin Wan #13

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

Open
wants to merge 34 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
118 changes: 110 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,115 @@
CUDA Path Tracer
================
####University of Pennsylvania
####CIS 565: GPU Programming and Architecture

**University of Pennsylvania, CIS 565: GPU Programming and Architecture, Project 3**
##Project 3 - CUDA Path Tracer
* Xueyin Wan
* Tested on: Windows 7, Xeon(R) E5-1630 @ 3.70GHz 32GB, GTX 1070 8192MB (Moore 103 SigLab)
* Compiled with Visual Studio 2013 and CUDA 7.5

* (TODO) YOUR NAME HERE
* Tested on: (TODO) Windows 22, i7-2222 @ 2.22GHz 22GB, GTX 222 222MB (Moore 2222 Lab)
==================================================================
##My Path Tracer Features
###Core Features
1. A shading kernel with BSDF evaluation:
* Ideal Diffuse surfaces
* Perfectly specular-reflective (mirrored) surfaces
2. Path continuation/termination using Stream Compaction
3. toggle between sorting path/intersection continuous by material type
4. toggle between cache first bounce

### (TODO: Your README)
###Extra Coolness
1. Refraction (e.g. glass/water) [PBRT 8.2] with Frensel effects using Schlick's approximation(finally...)
*Found great reference: http://graphics.stanford.edu/courses/cs148-10-summer/docs/2006--degreve--reflection_refraction.pdf*
2. Physically-based depth-of-field
3. Motion Blur
4. More is coming!

*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.
==================================================================
###Result In Progress

####Fresnel Refraction
Using Schlick's Approximation(http://graphics.stanford.edu/courses/cs148-10-summer/docs/2006--degreve--reflection_refraction.pdf)
![alt text](https://github.com/xueyinw/Project3-CUDA-Path-Tracer/blob/master/results/cornellTestFresnel.2016-10-09_23-18-37z.5000samp.png "Fresnel Refraction")

####Diffuse, Perfect Specular Wall, Transmissive and Depth of Field
* `Left Wall` : Reflection = 1
* `Left Blue Ball`: Refraction = 1
* `Middle Purple Ball`: Refraction + Reflection = 1, No Diffuse
* `Right Pink Ball`: Only Diffuse


|Original | With DOF |
|------|------|
|![alt text](https://github.com/xueyinw/Project3-CUDA-Path-Tracer/blob/master/results/cornellTestDOF.2016-10-11_03-52-19z.5000samp.png "Original") | ![alt text](https://github.com/xueyinw/Project3-CUDA-Path-Tracer/blob/master/results/cornellTestDOF.2016-10-09_19-18-26z.5000samp.png "Depth Of Field and Mirror") |

####Motion Blur
Motion Blur: The left sphere and middle cube is moving during the whole render process
![alt text](https://github.com/xueyinw/Project3-CUDA-Path-Tracer/blob/master/results/cornellTestFresnel.2016-10-10_00-02-09z.5000samp.png "Motion Blur")

|![alt text](https://github.com/xueyinw/Project3-CUDA-Path-Tracer/blob/master/results/cornellTestFresnel.2016-10-09_18-51-14z.5000samp.png "Motion Blur")


####Depth of Field Comparison
* `Left Ball` : Refraction = 1
* `Middle Cube`: Reflection = 0.4, Refraction = 0.6, Refraction + Reflection = 1, No Diffuse,
* `Right Ball`: Reflection = 0.2, Refraction = 0.2, Diffuse = 0.6

####Original Pic
![alt text](https://github.com/xueyinw/Project3-CUDA-Path-Tracer/blob/master/results/cornellTestFresnel.2016-10-10_00-49-35z.5000samp_original.png "Without DOF")

|Focal Length = 10.5 | Focal Length = 9 |
|------|------|
|![alt text](https://github.com/xueyinw/Project3-CUDA-Path-Tracer/blob/master/results/cornellTestFresnel.2016-10-10_00-57-14z.5000samp_10_5.png "DOF, FOCAL LENGTH = 10.5") | ![alt text](https://github.com/xueyinw/Project3-CUDA-Path-Tracer/blob/master/results/cornellTestFresnel.2016-10-10_01-01-39z.5000samp_9.png "DOF, FOCAL LENGTH = 9") |

####SEE WHERE I START FROM...
####BE CONFIDENT ABOUT YOUR HARD WORK!!! BE CONFIDENT ON THE WAY OF GPU!!! BE CONFIDENT WHEN FINDING A JOB!!!

|Ideal Diffuse surfaces | Perfectly specular-reflective surfaces |
|------|------|
|![alt text](https://github.com/xueyinw/Project3-CUDA-Path-Tracer/blob/master/results/cornell.2016-10-03_01-03-54z.5000samp.png "Ideal Diffuse surfaces") | ![alt text](https://github.com/xueyinw/Project3-CUDA-Path-Tracer/blob/master/results/cornell.2016-10-03_13-08-43z.5000samp.png "Perfectly specular-reflective surfaces") |

==================================================================
###ON or OFF? SORT_BY_MATERIAL, CACHE_FIRST_BOUNCE, STREAM_COMPATION
STATUS | SORT_BY_MATERIAL | CACHE_FIRST_BOUNCE | STREAM_COMPATION | 5000 INTERATIONS TOTAL TIME (s)
--- | --- | --- | --- | ---
| ON | OFF | OFF | 670.627
| OFF| ON | OFF | 100.689
| OFF| OFF | ON | 169.234
| OFF| OFF | OFF | 117.215
![alt text](https://github.com/xueyinw/Project3-CUDA-Path-Tracer/blob/master/results/performance_form.png "Table")

Above results is based on my cornellTestDOFLAB.txt.
I used Siglab Machine to run all the results.

###How to implement these Toggle?
In pathtrace.cu, using Macro definition to realize this :)
```java
#define SORT_BY_MATERIAL 0
#define CACHE_FIRST_INTERSECTION 0
#define STREAM_COMPACTION 0
```
Thanks google groups!

For `STREAM_COMPACTION`, I used `thrust::partition()` method to calculate number of paths alive.

For `CACHE_FIRST_INTERSECTION`, I made two helper variables:
```java
bool cache_first_intersection
static ShadeableIntersection * dev_first_intersections
```
and use cudaMemcpy() method to copy the first batch of intersections into dev_first_intersection memory.

For `SORT_BY_MATERIAL`, I made helper comparator `MaterialComparator()` and used `thrust::sort_by_key()` method to realize sorting by mateiral.

###What can we learn from the table above?
* SORT_BY_MATERIAL is the slowest one.. If there're a lot of materials in this code, I think that should be better.
* CACHE_FIRST_INTERSECTION : Totally went wrong when I opened DOF. But without DOF, result is good.
* STREAM_COMPACTION : Slower than all-OFF, I think maybe the ray's amount is huge, so the method takes unnecessary time. The method itself is good, yet sorting/compaction is slow (which is a pity :(.

###Dive into CUDA
![alt text](https://github.com/xueyinw/Project3-CUDA-Path-Tracer/blob/master/results/CUDA_SUMMARY_ONE.png "CUDA_TIMELINE")

![alt text](https://github.com/xueyinw/Project3-CUDA-Path-Tracer/blob/master/results/CUDA_SUMMARY.PNG "CUDA_SUMMARY")
From the pictures above, we could see `ComputerIntersections` is the most time wasted(72.79%), since this function is used to calculate all the intersections, and as we noticed, the ray's amount is huge.

The second part is `shadeFakeMaterial`, since we need to deal with each ray's color, remainging bounces information.

Binary file added results/CUDA_SUMMARY.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 results/CUDA_SUMMARY_ONE.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 results/cornell.2016-10-03_01-03-54z.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 results/cornell.2016-10-03_13-08-43z.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 results/cornell.2016-10-09_03-39-16z.2452samp.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 results/cornell.2016-10-09_05-48-25z.2806samp.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.
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 results/performance_form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 15 additions & 5 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 2.75
EMITTANCE 0

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

LENSRADIUS 1
FOCALDISTANCE 10.5

// Ceiling light
OBJECT 0
Expand Down Expand Up @@ -112,6 +113,15 @@ SCALE .01 10 10
OBJECT 6
sphere
material 4
TRANS -1 4 -1
TRANS -3 4 -1
ROTAT 0 0 0
SCALE 3 3 3

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

154 changes: 154 additions & 0 deletions scenes/cornellTestDOF.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
// 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

MATERIAL 4
RGB .98 .98 .98
SPECEX 0
SPECRGB .98 .98 .98
REFL 0
REFR 1
REFRIOR 2.75
EMITTANCE 0

// Diffuse
MATERIAL 5
RGB 0.8 0.5 0.2
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0

MATERIAL 6
RGB .98 .98 .98
SPECEX 0
SPECRGB .98 .98 .98
REFL 0.2
REFR 0.2
REFRIOR 2.5
EMITTANCE 0

// Camera
CAMERA
RES 800 800
FOVY 45
ITERATIONS 5000
DEPTH 8
FILE cornellTestDOF
EYE 0.0 5 10.5
LOOKAT 0 5 0
UP 0 1 0
LENSRADIUS 1
FOCALDISTANCE 9


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

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

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

Loading