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: Richard Lee #25

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
50 changes: 45 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,51 @@ 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)
* Richard Lee
* Tested on: Windows 7, i7-3720QM @ 2.60GHz 8GB, GT 650M 4GB (Personal Computer)

### (TODO: Your README)
## Features

*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.
* Diffuse, Reflective, and Refractive (with Fresnel) Materials
* Stream compaction
* Raycast cache optimization
* Stochastic supersampling
* Adaptive supersampling

#### Materials

The shading kernel deals with diffuse, perfect specular, and refractive materials. Fresnel effects for the glass material were implemented using Schlick's Approximation.

<img src="img/renders/cornell_scene/2000_aa.png" width="800" height="800">

#### Stream Compaction

Stream compaction allowed for a significant increase in performance in open scenes, as large portions of the path pool were able to leave the scene and terminate without needing to be processed on subsequent bounces. However, as we can see, stream compaction had much less effect on a closed scene, in which the paths would only terminate prematurely if they happened to hit a light.

<img src="img/stream_compaction_active_paths.png" width="652" height="400"> <img src="img/stream_compaction_performance.png" width="637" height="400">

#### Contiguous Material Shading

Sorting the materials before each shading pass had very little effect on the average runtime of the shading stage, possibly due to the small number of materials used in the test scene. However, sorting the materials themselves led to a significant hit on the overall performance of each iteration, and this optimization would most likely be detrimental without a much larger scene.

<img src="img/contiguous_materials_performance.png" width="555" height="350">

#### Stochastic Supersampling and Adaptive Supersampling

<img src="img/renders/cornell_scene/2000_noaa.png" width="400" height="400"><img src="img/renders/cornell_scene/2000_aa.png" width="400" height="400">

Antialiasing was implemented through supersampling, in which pixels were divided into 4 quadrants, with a jittered ray cast through each subpixel. This method effectively renders the image at 4x resolution, reducing any aliasing artifacts.
However, while supersampling allowed for antialiasing, it also required 4 times as many paths, and was much less efficient in terms of memory and time taken for the raycast.

<img src="img/antialiasing_comparison.png" width="656" height="250">

In order to address the fact that most supersampled pixels would not actually fix any aliasing artifacts, adaptive antialiasing was implemented to only supersample pixels which were located at edges where aliasing was likely to occur. The edge pass was generated by analyzing the normals of each pixel relative to its neighbors. This method led to a significant improvement in performance, with a minimal sacrifice in quality. However, there were still some artifacts in the adaptive supersampling method which could be addressed with a more robust edge detection algorithm.

<img src="img/renders/cornell_scene/edges.png" width="500" height="500">
<img src="img/antialiasing_performance.png" width="625" height="371">

#### Raycast and First Bounce Caching

The rays cast from the supersampling stage were generated the same way each time in order to store the first raycast and intersection. This had marginal benefits without antialiasing, but had significant improvements for the antialiasing methods, as reusing the cache allowed for the expensive raycast to be skipped on subsequent iterations.

<img src="img/caching_performance.png" width="652" height="446">
Binary file added img/antialiasing_comparison.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_performance.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/caching_performance.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/contiguous_materials_performance.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/renders/cornell_empty/1000_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/renders/cornell_empty/1000_adaptive.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/renders/cornell_empty/1000_noaa.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/renders/cornell_empty/2000_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/renders/cornell_empty/2000_adaptive.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/renders/cornell_empty/2000_noaa.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/renders/cornell_scene/1000_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/renders/cornell_scene/1000_adaptive.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/renders/cornell_scene/1000_noaa.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/renders/cornell_scene/2000_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/renders/cornell_scene/2000_adaptive.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/renders/cornell_scene/2000_noaa.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/renders/cornell_scene/edges.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/stream_compaction_active_paths.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/stream_compaction_performance.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 68 additions & 6 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 7

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

// Specular white
// Diffuse cyan
MATERIAL 4
RGB .15 .75 .75
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0

// Mirror
MATERIAL 5
RGB .98 .98 .98
SPECEX 0
SPECRGB .98 .98 .98
Expand All @@ -48,11 +58,31 @@ REFR 0
REFRIOR 0
EMITTANCE 0

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

// Diffuse yellow
MATERIAL 7
RGB .85 .85 .15
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0

// Camera
CAMERA
RES 800 800
FOVY 45
ITERATIONS 5000
ITERATIONS 2000
DEPTH 8
FILE cornell
EYE 0.0 5 10.5
Expand Down Expand Up @@ -108,10 +138,42 @@ TRANS 5 5 0
ROTAT 0 0 0
SCALE .01 10 10

// Sphere
// Diffuse Sphere
OBJECT 6
sphere
material 4
TRANS -1 4 -1
material 1
TRANS 2 5 -2
ROTAT 0 0 0
SCALE 3 3 3

// Glass Sphere
OBJECT 7
sphere
material 6
TRANS -2 3.5 0
ROTAT 0 0 0
SCALE 3 3 3

// Reflective Sphere
OBJECT 8
sphere
material 5
TRANS -3.25 7 -3
ROTAT 0 0 0
SCALE 3 3 3

// Left Cube
OBJECT 9
cube
material 4
TRANS -2 .825 0
ROTAT 0 20 0
SCALE 3.25 2 3.25

// Right Cube
OBJECT 10
cube
material 7
TRANS 2 1 -2
ROTAT 0 -20 0
SCALE 3.5 4 3.5
Loading