Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
884fe0b
TabSpace formatting changes - Starting to make sense
botforge Sep 29, 2019
d84fac7
implemented scatterRay trivial, build errors
botforge Sep 29, 2019
ed8e6fd
too bright problem
botforge Sep 29, 2019
773672a
Finally good the base working
botforge Sep 29, 2019
76d4155
reflections and diffuse easy money
botforge Sep 29, 2019
d6d253c
Part 1 all done
botforge Sep 29, 2019
00d7ff2
refraction almost done
botforge Sep 29, 2019
388c228
Refraction does not work properly
botforge Sep 29, 2019
d5389d2
I hate release mode. always clean and rebuild.
botforge Sep 30, 2019
0661a65
refraction kind of works but I still hate it
botforge Sep 30, 2019
07641b4
Refraction finally works
botforge Sep 30, 2019
204afbe
Motionblur added
botforge Sep 30, 2019
02d05d4
can now do motion blur
botforge Sep 30, 2019
c27c9d1
fixed cute bug in motionblur and added some cool images
botforge Sep 30, 2019
1581043
CSG DONE
botforge Sep 30, 2019
e204eca
almost done
botforge Sep 30, 2019
fa07369
Update README.md
botforge Sep 30, 2019
3960ec1
Update README.md
botforge Sep 30, 2019
6248537
Update README.md
botforge Sep 30, 2019
d56c4f5
Update README.md
botforge Sep 30, 2019
69a2035
New Images
botforge Oct 1, 2019
20fd28a
Merge branch 'master' of https://github.com/botforge/Project3-CUDA-Pa…
botforge Oct 1, 2019
fdfe786
Update README.md
botforge Oct 1, 2019
5830e52
Update README.md
botforge Oct 1, 2019
6f2a76d
Update README.md
botforge Oct 1, 2019
816d9df
Update README.md
botforge Oct 1, 2019
5e532d1
Update README.md
botforge Oct 1, 2019
5efd48e
Update README.md
botforge Oct 1, 2019
bf28f68
Update README.md
botforge Oct 1, 2019
0597dc7
Update README.md
botforge Oct 1, 2019
8790074
Update README.md
botforge Oct 1, 2019
fbcf17f
Update README.md
botforge Oct 1, 2019
43f7903
new imgs
botforge Oct 1, 2019
bbfc8fc
Update README.md
botforge Oct 1, 2019
0ca03ed
Update README.md
botforge Oct 1, 2019
15cfcf0
Update README.md
botforge Oct 1, 2019
e42f0cd
Update README.md
botforge Oct 1, 2019
0afb562
Update README.md
botforge Oct 1, 2019
ac7e174
Update README.md
botforge Oct 1, 2019
a3d5a21
Update README.md
botforge Oct 1, 2019
d528585
changes filenames
botforge Oct 1, 2019
a2c355d
Merge branch 'master' of https://github.com/botforge/Project3-CUDA-Pa…
botforge Oct 1, 2019
6404349
Update README.md
botforge Oct 1, 2019
6f5240b
pre and postAA
botforge Oct 1, 2019
8345fd0
Merge branch 'master' of https://github.com/botforge/Project3-CUDA-Pa…
botforge Oct 1, 2019
75a0565
Update README.md
botforge Oct 1, 2019
a7df3e2
Update README.md
botforge Oct 1, 2019
bac06a9
Update README.md
botforge Oct 1, 2019
b0a3f11
Update README.md
botforge Oct 1, 2019
4986688
Update README.md
botforge Oct 1, 2019
8da6fcf
Update README.md
botforge Oct 1, 2019
3f54bdf
added wasted file
botforge Oct 1, 2019
96a3719
Merge branch 'master' of https://github.com/botforge/Project3-CUDA-Pa…
botforge Oct 1, 2019
8d38c5e
Update README.md
botforge Oct 1, 2019
9e04b0a
Update README.md
botforge Oct 1, 2019
db764b8
Update README.md
botforge Oct 1, 2019
56b7e94
Update README.md
botforge Oct 1, 2019
6202bdf
Update README.md
botforge Oct 1, 2019
5c1b870
Update README.md
botforge Oct 1, 2019
e13f41a
Update README.md
botforge Oct 1, 2019
6e6fef5
Update README.md
botforge Oct 1, 2019
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: 88 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,93 @@
CUDA Path Tracer
================

**University of Pennsylvania, CIS 565: GPU Programming and Architecture, Project 3**
CUDA PATH TRACER
==================================================================

* (TODO) YOUR NAME HERE
* Tested on: (TODO) Windows 22, i7-2222 @ 2.22GHz 22GB, GTX 222 222MB (Moore 2222 Lab)
**University of Pennsylvania, CIS 565: GPU Programming and Architecture**

### (TODO: Your README)
Dhruv Karthik: [LinkedIn](https://www.linkedin.com/in/dhruv_karthik/)

*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.
Tested on: Windows 10 Home, Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz, 16GM, GTX 2070 - Compute Capability 7.5
____________________________________________________________________________________
![Developer](https://img.shields.io/badge/Developer-Dhruv-0f97ff.svg?style=flat) ![CUDA 10.1](https://img.shields.io/badge/CUDA-10.1-yellow.svg) ![Built](https://img.shields.io/appveyor/ci/gruntjs/grunt.svg) ![Issues](https://img.shields.io/badge/issues-none-green.svg)
____________________________________________________________________________________
<p align="center">
<img src="img/frontpage.png">
</p>

Table of contents
=================
* [What is Path Tracing](#what-is-path-tracing)
* [Features Overview](#features-overview)
* [BSDF Scattering: Diffuse, Specular-Reflective, Specular Transmissive](#bsdf-scattering)
* [Procedural Shapes](#procedural-shapes)
* [Stochastic Sampled Anti Aliasing](#stochastic-sampled-anti-aliasing)
* [Motion Blur](#motion-blur)
* [Optimizations ](#optimizations)
* [Stream compaction to remove terminated rays](#stream-compaction-to-remove-terminated-rays)
* [First bounce caching](#first-bounce-caching)
* [Sort by Material](#sort-by-material)
* [Questions](#questions)
* [Performance Analysis](#performance-analysis)
* [Credits & Acknowledgments](#credits)

# What is path tracing?
Path tracing refers to a set of techniques to virtually render images by emulating certain physical properties of light. In real life, Rays of light leave light sources, bounce around the world, and hit pixels in the camera. Path traces simulates this effect by firing 'rays' out of the camera pixels, and considering those that hit a light source.
<p align="center">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/5c/Ray_trace_diagram.png/320px-Ray_trace_diagram.png"
alt="Pathtrace" />
</p>

# Features Overview
## BSDF Scattering
A combination of ***reflection*** and ***transmission*** functions that describe how rays must bounce once they intersect an object. For transmissive and refractive objects, I used schlicks approximation to calculate the probability of the refractive surface being reflective at high incidence angles. The following illustrates BSDF on three material properties:

| Diffuse | Reflective | Refractive |
| ------------- | ----------- |----------- |
| ![](img/bsdf3.png) | ![](img/bsdf1.png) | ![](img/bsdf2.png) |

## Procedural Shapes
I created procedural shapes via a variation of ***Constructive Solid Geometry*** ray tracing. Using the provided primitives, I modified in the code in ```intersection.h``` to generate three different constructive of the original primitive geometry that used portions of the original geometry and negated others:

| 1 | 2 | 3 |
| ------------- | ----------- |----------- |
| ![](img/SphereAndNotCube.PNG) | ![](img/SphereCubeUnion.PNG) | ![](img/SphereAndCubeMatrix.PNG) |

## Stochastic Sampled Anti Aliasing
Implementing this simply required that randomly I nudge the ray direction by epsilon in the x & and y axis. Notice how the pre-AA image has jagged edges where the yellow light reflects off it. Notice how this issue dissappears post AA!

| Pre AA | Post AA |
| ------------- | ----------- |
| ![](img/preAA.jpg) | ![](img/postAA.jpg) |

## Motion Blur
I created a kernel function ```blurGeom``` that allows users to specify a ``glm::vec3 offset`` so they could direct the blur towards their desired position. I implemented motion blur by targeting a subset of ``geom`` objects to respond to changes in ``dt = epsilon * iter``. The second run illustrates motion blur with first bounce cache on - This is not the right thing to do, but resulted in a cool image.

| 1 | 2 | 3 |
| ------------- | ----------- | ----------- |
| ![](img/mblurmirror.PNG) | ![](img/mirrordim.PNG) | ![](img/motionblur.PNG) |

# Optimizations
## Stream Compaction to Remove Terminated Rays
CUDA can only launch a fininite number of blocks at a time. As a result, if some threads are tracing more bounces, and some are tracing a few, we can end up with a lot of idling threads. One solution to this is to stream compact away idling threads. This means terminated threads are removed at the every kernel's launch, so that running threads are grouped together.
## First Bounce Caching
This is a clever optimization to avoid recomputing the first bounce for depth=0. This is because this bounce stays the same regardless of iterations, so we precompute this in the first bounce and reload it whenvever depth=0.
## Sort By Material
Divergence is a seriously perfomance killer in CUDA, as if different threads in a warp diverge then the benefits of parralelilzation begin to dissapear. This would most likely happen in a path tracing scenario when materials that reflect differently run at the same time. To avoid warp divergence while the kernel is running, I sorted by material to ensure that similar materials most likley get placed in the same warp as they are contiguous in memory.

# Performance Analysis
I proceeded to remove walls from my cornell scene and to printed out the decrease in number of elements left in the array post stream compaction. Removing walls exposed more black space and thereby would result in a more rapid decrease of elements in the compacted array. I started with only 2 walls, and this had the greatest decrease as it started at approx 2000 values and went to near zero in about 4 bounces.

# Questions

**Compare scenes which are open (like the given cornell box) and closed (i.e. no light can escape the scene). Again, compare the performance effects of stream compaction! Remember, stream compaction only affects rays which terminate, so what might you expect?**
If no light can escape the scene, then the benefits of stream compaction are nullified as rays only terminate when they reach the end of their depth. As a result, the presence of stream compaction had no effect on the closed box scene.

# Bloopers
See wayyy more images and bloopers in the imgs folder!
Messed up refraction
![](img/something.PNG)


# Credits
[rayttracing.github.io](raytracing.github.io)

Binary file added img/0.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/1.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/2.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/3.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/Antialiasing.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/MirrorDimension.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 Mirror Dimension2.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/MotionBlurMirrorDim.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/Sphere and NotCube.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/SphereAndCubeMatrix.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/SphereAndNotCube.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/SphereCubeUnion.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/SphereCubeUnion2.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/Spotlight Image.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/bsdf1.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/bsdf2.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/bsdf3.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/frontpage.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/mblurmirror.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/mirrordim.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/motionblur.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/postAA.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/pre-aa.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/preAA.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/something.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/wasted.PNG
22 changes: 17 additions & 5 deletions scenes/cornell.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 5
EMITTANCE 10

// Diffuse white
MATERIAL 1
Expand Down Expand Up @@ -48,6 +48,18 @@ REFR 0
REFRIOR 0
EMITTANCE 0

// Glass white
MATERIAL 5
RGB 1 1 1
SPECEX 0
SPECRGB 1 1 1
REFL 0.5
REFR 0.5
REFRIOR 1.50s
EMITTANCE 0



// Camera
CAMERA
RES 800 800
Expand Down Expand Up @@ -95,7 +107,7 @@ SCALE .01 10 10
// Left wall
OBJECT 4
cube
material 2
material 1
TRANS -5 5 0
ROTAT 0 0 0
SCALE .01 10 10
Expand All @@ -111,7 +123,7 @@ SCALE .01 10 10
// Sphere
OBJECT 6
sphere
material 4
TRANS -1 4 -1
material 5
TRANS -1 5 -1
ROTAT 0 0 0
SCALE 3 3 3
SCALE 5 5 5
219 changes: 219 additions & 0 deletions scenes/fourlightroom.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
// Emissive Blue material (light)
MATERIAL 0
RGB 0.8 0.8 0.0
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 10

// Emissive Red material (light)
MATERIAL 1
RGB 1 0.0 0.3
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 5


// Emissive Blue material (light)
MATERIAL 2
RGB 0 1 0.5
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 5

// Emissive Green material (light)
MATERIAL 3
RGB 0.01 0.95 0.1
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 10

// Diffuse white
MATERIAL 4
RGB .98 .98 .98
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0

// Diffuse red
MATERIAL 5
RGB .85 .35 .35
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0

// Diffuse green
MATERIAL 6
RGB .1 1.0 0.1
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0

// Diffuse Dark Blue
MATERIAL 7
RGB 0.9 0.5 0.9
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0

// Reflection & Refraction
MATERIAL 8
RGB 0.8 0.4 0.4
SPECEX 0
SPECRGB 1 1 1
REFL 0.7
REFR 0.3
REFRIOR 1.35
EMITTANCE 0

// Reflection & Refraction
MATERIAL 9
RGB 0.8 0.6 0.8
SPECEX 0
SPECRGB 1.0 1.0 1.0
REFL 1.0
REFR 0.0
REFRIOR 0
EMITTANCE 0

// Reflection & Refraction
MATERIAL 10
RGB 1.0 1.0 1.0
SPECEX 0
SPECRGB 1.0 1.0 1.0
REFL 0.5
REFR 0.5
REFRIOR 1.56
EMITTANCE 0

// Reflection & Refraction
MATERIAL 11
RGB 0.1 1.0 1.0
SPECEX 0
SPECRGB 1.0 1.0 1.0
REFL 0.9
REFR 0.1
REFRIOR 1.2
EMITTANCE 0


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


// Ceiling Blue Light
OBJECT 0
cube
material 0
TRANS 0 10 0
ROTAT 0 0 0
SCALE 3 .3 3


// Left Pink Light
OBJECT 1
cube
material 1
TRANS -5 500 0
ROTAT 0 0 90
SCALE 3 .3 3


// Right Yellow light
OBJECT 2
cube
material 2
TRANS 5 500 0
ROTAT 0 0 90
SCALE 3 .3 3


// Floor Green light
OBJECT 3
cube
material 3
TRANS 0 0 0
ROTAT 0 0 0
SCALE 3 .3 3


// Floor
OBJECT 4
cube
material 7
TRANS 0 0 0
ROTAT 0 0 180
SCALE 10 .01 10

// Ceiling
OBJECT 5
cube
material 7
TRANS 0 10 0
ROTAT 0 0 90
SCALE .01 10 10

// Back wall
OBJECT 6
cube
material 7
TRANS 0 5 -5
ROTAT 0 90 0
SCALE .01 10 10

// Left wall
OBJECT 7
cube
material 9
TRANS -5 5 0
ROTAT 0 0 0s
SCALE .01 10 10

// Right wall
OBJECT 8
cube
material 9
TRANS 5 5 0
ROTAT 0 0 0
SCALE .01 10 10


// SphereandNotCUBE
OBJECT 9
sphereAndNotCube
material 8
TRANS -1 4 -1
ROTAT 0 10 45
SCALE 3 3 3

Loading