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: Zheyuan Xie #18

Open
wants to merge 10 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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ set(headers
src/sceneStructs.h
src/preview.h
src/utilities.h
src/tiny_obj_loader.h
)

set(sources
Expand All @@ -84,6 +85,7 @@ set(sources
src/scene.cpp
src/preview.cpp
src/utilities.cpp
src/tiny_obj_loader.cc
)

list(SORT headers)
Expand Down
85 changes: 80 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,86 @@ 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)
* Zheyuan Xie
* Tested on: Windows 10 Pro, i7-7700HQ @ 2.80GHz, 16GB, GTX 1050 2GB (Dell XPS 15 9560)

### (TODO: Your README)
## Introduction
![path tracer demo](img/banner.png)

*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.
This is a CUDA-based path tracer capable of rendering globally-illuminated images very quickly.

## Features
### 1 Arbitrary Mesh Loading
The path tracer loads arbitrary mesh object from .obj files using [tinyObj](http://syoyo.github.io/tinyobjloader/). Loaded triangles and precomputed surface normals are stored in an addtional device buffer which can be quickly accessed.

| Bunny | Diamond | City |
|--|--|--|
|![](img/bunny_diffuse.png) | ![](img/diamond.png) | ![](img/city.png) |

### 2 Refraction with Frensel Effects
Refraction with Frensel effects using Schlick's approximation.

| Perfect Speculer | Transmissive | Diffussive |
|--|--|--|
|![perfect speculer](img/speculer.png) | ![refractive](img/transmissive.png) | ![pure diffusive](img/diffusive.png) |

### 3 Physically-Based Depth-of-Field
Physically-based depth-of-field is achieved by simulating camera lens. Instead of using the pinhole camera model, we apply the thin lens approximation model. [PBRT 6.2.3]

The images below shows three renderings of one scene. The camera is focused at the frontmost sphere. Larger lens radius results in a deeper depth of field.

| DOF OFF | DOF ON (LR=0.5) | DOF ON (LR=2.0) |
|--|--|--|
|![](img/dof_off.png) | ![](img/dof_lr05.png) | ![](img/dof_lr20.png) |

### 4 Stochastic Sampled Antialiasing
Anti-Aliasing is achieved by randomly jittering ray within the pixel and average the results of multiple rays.

| Antialiasing OFF | Antialiasing ON|
|--|--|
|![](img/aa_off.png) | ![](img/aa_on.png) |

### 5 Camera Motion Blur
Camera motion blur is achieved by randomly jittering rays along the direction of motion.

| Static Camera | Rightward Motion | Forward Motion |
|--|--|--|
|![](img/speculer.png) | ![](img/motion_blur_right.png) | ![](img/motion_blur_forward.png) |

## Optimization
The following optimization methods are implemented to reduce rendering time:
- **Stream Compaction:** Remove completed rays, reducing the number of threads to launch.
- **Cache First Iteraction:** Cache the first bounce intersections for re-use across all subsequent iterations.
- **Sort Materials:** Sort the rays/path segments so that rays/paths interacting with the same material are contiguous in memory before shading.
- **Bounding Volume Intersection Culling:** Reduce the number of rays that have to be checked against the entire mesh by first checking rays against a volume that completely bounds the mesh. This optimization does not apply to primitive shapes.

We compare rendering performance with different optimization methods enabled.
- NO = No Optimization
- CF = Cache First iteration only
- SC = Stream Compaction only
- SM = Sort Materials only
- IC = Bounding Volume Intersection Culling only
- SC+IC+CF = Three optimizations combined
- ALL = All Optimization

For a basic scene consists of a cornell box and four primitive shapes (spheres and boxes). Counterintuitively, the render time is minimized with no optimization. The probable cause is the kernel launch overhead for sorting and reduction.

![](img/perf_basic.png)

For a more complex scene consists of a cornell box and a Stanford bunny, optimizations reduce rendering time by almost 50%.

![](img/perf_bunny.png)

## Bloopers

![](img/blooper1.png)

![](img/blooper2.png)

![](img/blooper3.png)


## Reference
- Physically Based Rendering, Third Edition: From Theory To Implementation. Pharr, Matt and Humphreys, Greg.
- Project 3 Recitation - Hannah ([link](https://docs.google.com/presentation/d/1bFtutDe9POZDPiqD9npeOEOWh783xHy4xf2AdJt-pEI/edit?usp=sharing))
- Most Efficient AABB vs Ray Collision Algorithms. ([link](https://gamedev.stackexchange.com/questions/18436/most-efficient-aabb-vs-ray-collision-algorithms))
Binary file added img/aa_off.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/aa_on.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/banner.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/blooper1.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/blooper2.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/blooper3.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/bunny_diffuse.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/bunny_refract.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/city.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/diamond.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/diffusive.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/dof_lr05.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/dof_lr20.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/dof_off.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_forward.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_right.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/perf_basic.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/perf_bunny.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/speculer.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/transmissive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
142 changes: 142 additions & 0 deletions scenes/bunny.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// 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 left wall
MATERIAL 2
RGB .37 .30 .54
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0

// Diffuse right wall
MATERIAL 3
RGB .98 .46 .41
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 0
REFRIOR 0
EMITTANCE 0

// Refractive white
MATERIAL 5
RGB .98 .98 .98
SPECEX 0
SPECRGB .98 .98 .98
REFL 0
REFR 1
REFRIOR 1.33
EMITTANCE 0

// Bunny material
MATERIAL 6
RGB .98 .98 .98
SPECEX 0
SPECRGB .98 .98 .98
REFL 0
REFR 0
REFRIOR 2.4
EMITTANCE 0

// Camera
CAMERA
RES 800 800
FOVY 45
ITERATIONS 3000
DEPTH 8
FILE cornell
EYE 0 5 10.5
LOOKAT 0 5 0
UP 0 1 0
DOF 0
LENSR 2.0
FD 7.5
AA 0
MOTION 0 0 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

// Bunny
OBJECT 6
mesh
../scenes/bunny.obj
material 6
TRANS 0 -0.1 0
ROTAT 0 0 0
SCALE 4 4 4
Loading