Skip to content
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
63 changes: 58 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,64 @@ 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)
* Eric Chiu
* Tested on: Windows 10 Education, Intel(R) Xeon(R) CPU E5-1630 v4 @ 3.60GHz 32GB, NVIDIA GeForce GTX 1070 (SIGLAB)

### (TODO: Your README)

*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/procedural-shape-1.png)


## Description

This project implements a physically based pathtracer using CUDA programming and GPU hardware. Features include stream compaction, first bounce caching, material sorting, anti-aliasing, refraction with Frensel effects, and procedural shapes.

## Stream Compaction

Rendering without stream compaction was faster than rendering with stream compaction until the trace depth hit the 100s. This is probably because the time to perform stream compaction was more than the time it saved in the long run when the trace depth was under 100. When the trace depth was over 100, the time to perform stream compaction was marginal compared to the time it saved in the long run.


![](./img/stream-compaction.png)


## First Bounce Caching

First bounce caching depends on the number of intersections found in the first bounce. As the image resolution increases, the more likely intersections are computed in the first bounce. We can see here that caching the first bounce slightly boosts performance, but not a lot. This is probably because the first bounce is only a small percentage of the number of bounces the pathtracer has to perform.


![](./img/first-bounce-caching.png)


## Material Sorting

Sorting rays and path segments based on different materials surprisingly made the performance slower. The idea was to sort rays and path segments so that ones with the same material will be contiguous in memory. However, after further analysis, it seems like the time it takes to material sort outweights the amount of time it saves in later operations.


![](./img/material-sorting.png)


## Anti-Aliasing

Anti-aliasing can be achieved by offsetting the rays by a small amount when it is first shot out of the screen. The pixel will then be an average of the offset rays, creating a smooth effect. We can see the effect take place in the two images below, on the edge on the sphere.


![](./img/aliased.png)

![](./img/anti-aliased.png)


## Refraction

We used Frensel effects with Schlick's approximation to simulate glass and refractive material. In the image below, we see spheres with diffuse, refractive, and reflective materials. Caustics, light focused in one area, is one result of refraction.


![](./img/refraction.png)


## Procedural Shapes

Procedural shapes, specificially implicit surfaces, can be procedurally generated using signed distance functions. When a ray is shot, we can solve a distance function to determine whether the ray hit a implicit surface or not. If we do hit an implicit surface, we perform shading like for any other object. If we do not hit an implicit surface, we continue on with pathtracing. The two implicit surfaces implemented are shown below.


![](./img/procedural-shape-1.png)

![](./img/procedural-shape-2.png)
Binary file added img/aliased.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/anti-aliased.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.2018-09-30_20-32-37z.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.2018-09-30_20-44-55z.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/first-bounce-caching.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/material-sorting.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/procedural-shape-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/procedural-shape-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/refraction.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.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 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
REFL 0
REFR 0
REFRIOR 0
REFRIOR 1.52
EMITTANCE 0

// Camera
Expand Down Expand Up @@ -114,4 +114,4 @@ sphere
material 4
TRANS -1 4 -1
ROTAT 0 0 0
SCALE 3 3 3
SCALE 1.5 1.5 1.5
169 changes: 169 additions & 0 deletions scenes/cornell2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
// 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

// Glass
MATERIAL 4
RGB .98 .98 .98
SPECEX 0
SPECRGB .98 .98 .98
REFL 1
REFR 1
REFRIOR 1.52
EMITTANCE 0

// Mirror
MATERIAL 5
RGB .98 .98 .98
SPECEX 0
SPECRGB .98 .98 .98
REFL 1
REFR 0
REFRIOR 1.52
EMITTANCE 0

// Diffuse
MATERIAL 6
RGB .35 .35 .98
SPECEX 0
SPECRGB .98 .98 .98
REFL 0
REFR 0
REFRIOR 1.52
EMITTANCE 0

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


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

// Sphere
OBJECT 7
sphere
material 4
TRANS 0.5 1.75 2
ROTAT 0 0 0
SCALE 0.75 0.75 0.75

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

// Sphere
OBJECT 9
sphere
material 4
TRANS 2.5 6 -1
ROTAT 0 0 0
SCALE 3.5 3.5 3.5

// Sphere
OBJECT 10
sphere
material 6
TRANS 2.5 2 -1
ROTAT 0 0 0
SCALE 1.5 1.5 1.5
117 changes: 117 additions & 0 deletions scenes/csg1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// 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 1
REFR 1
REFRIOR 1.52
EMITTANCE 0

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


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

// CSG1
OBJECT 6
csg1
material 4
TRANS 0 3 0
ROTAT 0 0 0
SCALE 1 1 1
Loading