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
8 changes: 1 addition & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,4 @@ target_link_libraries(${CMAKE_PROJECT_NAME}
${CORELIBS}
)

add_custom_command(
TARGET ${CMAKE_PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/shaders
${CMAKE_BINARY_DIR}/shaders
)

98 changes: 92 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,99 @@
CUDA Path Tracer
================

**University of Pennsylvania, CIS 565: GPU Programming and Architecture, Project 3**
**University of Pennsylvania, CIS 565: GPU Programming and Architecture, Project 2**

* (TODO) YOUR NAME HERE
* Tested on: (TODO) Windows 22, i7-2222 @ 2.22GHz 22GB, GTX 222 222MB (Moore 2222 Lab)
* Yu Sun
* [LinkedIn](https://www.linkedin.com/in/yusun3/)
* Tested on: Tested on: Windows 10 , i7-6700HQ CPU @ 2.60GHz × 8 , GeForce GTX 960M/PCIe/SSE2, 7.7GB Memory (Personal Laptop)

### (TODO: Your README)
## Introduction

*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.
In this project, a basic path tracer with static scene rendering and shading is implemented. The tracer can shade objects with
diffusive, specular and refractive surfaces with light source in the scene.

Below is a very simple scene demonstrating the effect.
![](img/scene.png)
![](img/closed.png)

The techniques used in order to make the shading process faster include caching the first bounces, sorting the materials by id, and
stream compaction. Caching can help because the first bounce of the rays would almost always be the same. Sorting the materials by id would help the
access pattern of the threads, and stream compaction essentially reduce the number of computation that needs to be done.

Additional features written include anti-aliasing, using depth of field and motion blur.

***Anti-aliasing***

Anti-aliasing is a very simple technique that you add some random gaussian noise when shooting the rays so the boundary looks more natural.

An example of scene with and without anti-aliasing effect is shown below, look how sharp the edge look on scene without anti-aliasing effect

Scene with anti-aliasing | Scene without anti-aliasing
:-------------------------:|:-------------------------:
![](img/white.png) | ![](img/alias.png)


***Depth of Field***

Depth of field can be achieved by specifying a camera model with varying focal length and lens size. It uses a technique that's called concentric disc sampling and
is explained in detail in the book Physically Based Rendering. The result is shown below:

Focal Length = 10 | Focal Length = 15
:-------------------------:|:-------------------------:
![](img/focal10.png) | ![](img/focal15.png)

LenSize = 0.2 | LenSize = 0.5
:-------------------------:|:-------------------------:
![](img/lensize.png) | ![](img/focal15.png)


***Motion Blur***

Motion blur can be achieved by sampling the objects in different locations while it moves. The movement speed will effect how the object is captured by the camera.

Speed = 1 | Speed = 2
:-------------------------:|:-------------------------:
![](img/speed1.png) | ![](img/speed2.png)



***Refraction***

Refraction effect can be achieved by using Snell's law. It helps the object looks more realistic with the effect of letting light through

Without refraction | With Refraction
:-------------------------:|:-------------------------:
![](img/no_refract.png) | ![](img/scene.png)


## Analysis

So I mention briefly that stream compaction can help reduce the amount of computation we have. Below is a more concreate analysis on the number of rays reduced after stream compaction. Notice the difference when the scene is closed and when it's open.

![](img/sc.png)

This makes sense as in closed scene the rays needs to bounce more before hitting a light source and terminating, while in open scene it can soon be terminated as it's shooting outside.

It can also be seen that in general the algorithm runs faster when it's in open scene.

![](img/time.png)

It is also true that using cache helps improving the speed as shown below.

However, when we need to go with randomrization in the scene creating anti-aliasing effect or motion blur. The technique cannot be used anymore.

On the other hand, we could still use sorting to help increase the speed. However, although in theory sorting can help increase the performance. In reality,
one needs to consider its overhead as sorting does come with a price.

Closed Scene | Open scene
:-------------------------:|:-------------------------:
![](img/sort_closed.png) | ![](img/sort_open.png)

In general, it's more helpful to use sorting in open scene as in closed scene, the rays are rarely terminating. Therefore, the gain of making the memory access continuous
may not be that much.

## References

* [PBRT] Physically Based Rendering, Second Edition: From Theory To Implementation. Pharr, Matt and Humphreys, Greg. 2010.
* Wikipedia

Binary file added img/alias.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/cache.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/closed.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-10-01_00-01-49z.195samp.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/focal10.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/focal15.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/lensize.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/no_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/purple.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/sc.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/scene.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/sort_closed.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/sort_open.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/speed1.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/speed2.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/time.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/white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions scenes/cornell.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ EMITTANCE 0

// Specular white
MATERIAL 4
RGB .98 .98 .98
RGB .98 0.5 .98
SPECEX 0
SPECRGB .98 .98 .98
SPECRGB .98 .5 .98
REFL 1
REFR 0
REFRIOR 0
Expand Down
171 changes: 171 additions & 0 deletions scenes/cornell_blur.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
// 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 0
REFRIOR 0
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
LENSIZE 0.5
FOCALLEN 15


// Ceiling light
OBJECT 0
cube
material 0
TRANS 0 10 0
ROTAT 0 0 0
SCALE 3 .3 3
SPEED 0

// Floor
OBJECT 1
cube
material 1
TRANS 0 0 0
ROTAT 0 0 0
SCALE 10 .01 10
SPEED 0

// Ceiling
OBJECT 2
cube
material 1
TRANS 0 10 0
ROTAT 0 0 90
SCALE .01 10 10
SPEED 0

// Back wall
OBJECT 3
cube
material 1
TRANS 0 5 -15
ROTAT 0 90 0
SCALE .01 10 10
SPEED 0

// Left wall
OBJECT 4
cube
material 2
TRANS -5 5 0
ROTAT 0 0 0
SCALE .01 10 10
SPEED 0

// Right wall
OBJECT 5
cube
material 3
TRANS 5 5 0
ROTAT 0 0 0
SCALE .01 10 10
SPEED 0

// Sphere
OBJECT 6
sphere
material 4
TRANS -1 5 -2
ROTAT 0 0 0
SCALE 2 2 2
SPEED 1.8

// Ceiling light
OBJECT 7
cube
material 0
TRANS 0 10 -10
ROTAT 0 0 0
SCALE 3 .3 3
SPEED 0

// Floor
OBJECT 8
cube
material 1
TRANS 0 0 -10
ROTAT 0 0 0
SCALE 10 .01 10
SPEED 0

// Ceiling
OBJECT 9
cube
material 1
TRANS 0 10 -10
ROTAT 0 0 90
SCALE .01 10 10
SPEED 0

// Left wall
OBJECT 10
cube
material 2
TRANS -5 5 -10
ROTAT 0 0 0
SCALE .01 10 10
SPEED 0

// Right wall
OBJECT 11
cube
material 3
TRANS 5 5 -10
ROTAT 0 0 0
SCALE .01 10 10
SPEED 0
Loading