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: Zhangkaiwen Chu #24

Open
wants to merge 10 commits into
base: main
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
155 changes: 155 additions & 0 deletions .ipynb_checkpoints/Untitled-checkpoint.ipynb

Large diffs are not rendered by default.

Binary file added 1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
101 changes: 96 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,102 @@ 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)
* Zhangkaiwen Chu
* [LinkedIn](https://www.linkedin.com/in/zhangkaiwen-chu-b53060225/)
* Tested on: Windows 10, R7-5800H @ 3.20GHz 16GB, RTX 3070 Laptop GPU 16310MB (Personal Laptop)

### (TODO: Your README)
This project implement a CUDA-based path tracer.
![](img/result.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.
## Core Features
* A shading kernel with BSDF evaluation for ideal diffuse surfaces and non perfect specular-reflective surfaces.

Perfect reflection
![](img/perfect.png)

Non perfect reflection
![](img/nonperfect.png)


* Path termination using stream compaction.

I implemented this function by directly using thrust::partition for best performance.

* Sort the rays by material type.

I implemented this function by directly using thrust::sort_by_key.However, it actually lower the performance.

* Cache first bounce intersections to speed up.


## Visual Improvements
* Refraction.

Refraction is implemented based on the approximated fresnel equations in this [note](http://psgraphics.blogspot.com/2020/03/fresnel-equations-schlick-approximation.html).

![](img/refraction.png)

Upper left is a blue sphere with refractive index = 2.0, and middle right is a white sphere with refractive index = 1.5.


* Stochastic Sampled Antialiasing.

Stochastic sampled antialiasing is implemented according to this [note](http://paulbourke.net/miscellaneous/raytracing/).

Mirror room without antialiasing

![](img/mirror_box_origin.png)

Mirror room with antialiasing

![](img/mirror_box_anti.png)

The effect of antialiasing is very obvious. The image generated with antialiasing have far more details. And since there is only perfect reflection, the image do not change after the first iteration without using antialiasing.

* Physically-based depth-of-field.

Physically-based depth-of-field is implemented according to PBRT 6.2.3.

This picture is generated with focal length = 10.5 and lens size = 1.0. The sphere in the middle lays on the focus plane. The bottom-left sphere is a perfect reflective sphere moving from back to front.

![](img/dof%2Bmotion.png)


* Motion blur.

Motion blur is done by modifying the transformation matrix of a geometric object at each itreration. Only linear translation is implemented. Further work can include angular movements and complex trajectories.

The bottom sphere in this image is a reflective sphere moving from left to right.
![](img/motion.png)

## Performance Improvements
* Re-startable Path tracing.

I overwrite the command 'esc' to be exiting the rendering process and saving intermediate states, and add a command 'l' to load intermediate states. Saving the iteration number, camera settings and rendering->stats.image is enough for restarting the rendering. I save the intermediate states as a .txt file with each line a float number.

## ANALYSIS

* Sort by material

![](img/1.png)

Sorting is expected to increase the frame rate, since the threads in a ward is expected to excuete the same code, which will lower branch divergent. However, the rendering speed is actually lowered. Probabily because the sorting consumes too much time.

* Stream Compaction

![](img/2.png)

Stream compaction can compact the path nearly exponentially, both in the case of open environment and closed environment. This is as expected, since the probability that a random ray escape the scene (hit blank or light) is a constant. Although, the probability of a continual ray escape is dependent to the previous run, the randomness of diffuse and reflection makes the dependence weak.


* Caching

Closed scene
![](img/3.png)

Open scene
![](img/4.png)


Caching the first intersection makes the time elapsed per iteration lowered by a constant number, which is the time needed for calculating the first intersections and generating the rays.

155 changes: 155 additions & 0 deletions Untitled.ipynb

Large diffs are not rendered by default.

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/4.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+motion.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/mirror_box_anti.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/mirror_box_origin.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.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/nonperfect.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/perfect.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/result.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/visual.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 58 additions & 3 deletions scenes/cornell.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


// Emissive material (light)
MATERIAL 0
RGB 1 1 1
Expand Down Expand Up @@ -47,17 +49,43 @@ REFL 1
REFR 0
REFRIOR 0
EMITTANCE 0
SHINE 50


// Refracctive white
MATERIAL 5
RGB .98 .98 .98
SPECEX 0
SPECRGB .98 .98 .98
REFL 1
REFR 1
REFRIOR 1.5
EMITTANCE 0
SHINE 50

// Refracctive white
MATERIAL 6
RGB .98 .5 .98
SPECEX 0
SPECRGB .98 .5 .98
REFL 1
REFR 1
REFRIOR 2
EMITTANCE 0
SHINE 50

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


// Ceiling light
Expand Down Expand Up @@ -112,6 +140,33 @@ SCALE .01 10 10
OBJECT 6
sphere
material 4
TRANS -1 4 -1
TRANS 0 3 0
ROTAT 0 0 0
SCALE 2 2 2

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


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


// Sphere
OBJECT 9
sphere
material 4
TRANS -2 3 -2
ROTAT 0 0 0
SCALE 3 3 3
SCALE 2 2 2
END 2 3 -2
186 changes: 186 additions & 0 deletions scenes/cornell2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
// 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 0
REFR 0
REFRIOR 0
EMITTANCE 0
SHINE 100

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

// Reflective white
MATERIAL 6
RGB .9 .9 .9
SPECEX 0
SPECRGB .9 .9 .9
REFL 1
REFR 0
REFRIOR 2
EMITTANCE 0
SHINE 100

// Camera
CAMERA
RES 600 600
FOVY 45
ITERATIONS 5000
DEPTH 8
FILE cornell
EYE 0.0 5 4
LOOKAT 0 5 0
UP 0 1 0
RADIUS 0.5
FOCAL 10


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

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

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

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

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

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


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





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

// Sphere
OBJECT 8
sphere
material 6
TRANS -1 6 -2
ROTAT 0 0 0
SCALE 1 1 1

// Sphere
OBJECT 9
sphere
material 6
TRANS 1 6 -2
ROTAT 0 0 0
SCALE 1 1 1


// Sphere
OBJECT 10
sphere
material 6
TRANS 1 4 -2
ROTAT 0 0 0
SCALE 1 1 1






Loading