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
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)
* Yan Wu
* [LinknedIn](https://www.linkedin.com/in/yan-wu-a71270159/)
* Tested on: Windows 10, i7-8750H @ 2.20GHz 16GB, GTX 1060 6GB (Personal Laptop)

### (TODO: Your README)
### Project Description
In this project, I implemented a CUDA-based path tracer capable of rendering images. Since in this class we are concerned with working in GPU programming, performance, and the generation of actual beautiful images (and not with mundane programming tasks like I/O), this project includes base code for loading a scene description file, described below, and various other things that generally make up a framework for previewing and saving images.

*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.
### Features
* Basic Features:
- A shading kernel with BSDF evaluation for:
- Ideal Diffuse surfaces (using provided cosine-weighted scatter function, see below.) [PBRT 8.3].
- Perfectly specular-reflective (mirrored) surfaces (e.g. using glm::reflect).
- See notes on diffuse/specular in scatterRay and on imperfect specular below.
- Path continuation/termination using Stream Compaction
- Implemented a means of making rays/pathSegments/intersections contiguous in memory by material type
- Sort the rays/path segments so that rays/paths interacting with the same material are contiguous in memory
- A toggleable option to cache the first bounce intersections for re-use across all subsequent iterations.

* Extra Features:
- Refraction (e.g. glass/water) [PBRT 8.2] with Frensel effects using Schlick's approximation [PBRT 8.5].
- Physically-based depth-of-field (by jittering rays within an aperture) [PBRT 6.2.3].
- Antialiasing.
- More exciting features in the future...

### Result and comparison
* Original scene without anything: <br />
<img src="images/initial.gif" width = "50%"> <br />
* Without implementing Stream Compaction(So slow!): <br />
<img src="images/withoutCompaction.gif" width = "50%"> <br />
We can see that even those useless paths are taken into count. By using stream compaction we can get a way more efficient outcome.

* With fraction vs Without fraction:<br />
<img src="images/withoutRefract.png" width = "45%"> <img src="images/sorting slow.png" width = "45%"> <br />
More realistic with refraction implemented!
* With Anti-Aliasing vs Non-Anti-Aliasing:<br />
<img src="images/no_antialiasing.png" width = "45%"> <img src="images/antialiasing1608samp.png" width = "45%"> <br />
<img src="images/aliasCompare.PNG" width = "80%"> <br />
If we check carefully at the baseline of the walls, especially on the back wall, we could see that the anti-aliasing feature is working.
* With DOF(Depth of Field) vs No DOF:<br />
<img src="images/withoutDOF.png" width = "45%"> <img src="images/0.5DOF20.png" width = "45%"><br />
Depth of Field implemented great, we can totally see the difference as distance changes. The program with DOF only executed 433 loop so the right picture is a little too blurry.

### Bloopers
* Here are some interesting bugs I encountered when I was trying to implement schlick's approximation(left) and DOF(right).<br />
<img src="images/schlick wrong 2.png" width = "45%"> <img src="images/dof10samp364.png" width = "45%"><br />



Binary file added images/0.5DOF20.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 images/0.5dofsamp131.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 images/aliasCompare.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 images/antialiasing1608samp.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 images/antialiasing420samp.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 images/cache 3194sample.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 images/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 images/cornell.2018-10-02_23-37-45z.267samp.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 images/dof10samp364.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 images/dof16samp358.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 images/dof20samp598.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 images/initial.gif
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 images/no_antialiasing.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 images/schlick working.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 images/schlick wrong 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 images/schlick wrong 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 images/sorting slow.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 images/withoutCompaction.gif
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 images/withoutDOF.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 images/withoutRefract.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion scenes/cornell.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Emissive material (light)
// Emissive material (light)
MATERIAL 0
RGB 1 1 1
SPECEX 0
Expand Down
197 changes: 197 additions & 0 deletions scenes/cornell_new.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
// 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


// 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 -15
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 1 3 -2
ROTAT 0 0 0
SCALE 2 2 2

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

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

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

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

// Sphere
OBJECT 11
sphere
material 4
TRANS 1 3 2
ROTAT 0 0 0
SCALE 2 2 2

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

// Sphere
OBJECT 13
sphere
material 4
TRANS 1 3 -9
ROTAT 0 0 0
SCALE 2 2 2

// Sphere
OBJECT 14
sphere
material 4
TRANS 1 3 -12
ROTAT 0 0 0
SCALE 2 2 2

// Ceiling light
OBJECT 15
cube
material 0
TRANS 5 5 -5
ROTAT 0 0 0
SCALE .3 0.3 15

// Ceiling light
OBJECT 16
cube
material 0
TRANS -5 5 -5
ROTAT 0 0 0
SCALE .3 0.3 15
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ set(SOURCE_FILES

cuda_add_library(src
${SOURCE_FILES}
OPTIONS -arch=sm_20
OPTIONS -arch=sm_61
)
43 changes: 43 additions & 0 deletions src/interactions.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,47 @@ void scatterRay(
// TODO: implement this.
// A basic implementation of pure-diffuse shading will just call the
// calculateRandomDirectionInHemisphere defined above.
thrust::uniform_real_distribution<float> u01(0, 1);
float probability = u01(rng);
if (m.hasRefractive) {
float costheta = glm::dot(pathSegment.ray.direction, normal);
float n1 = costheta < 0 ? 1 : m.indexOfRefraction;
float n2 = costheta < 0 ? m.indexOfRefraction : 1;
float eta = n1 / n2;
float R0 = powf((n1 - n2) / (n1 + n2), 2);
float R_theta = R0 + (1 - R0)*powf(1 - glm::abs(costheta), 5);
if (probability > R_theta) {
pathSegment.ray.direction = glm::refract(pathSegment.ray.direction, normal, eta);
if(costheta >= 0) pathSegment.color *= m.color;
}
else {
pathSegment.ray.direction = glm::reflect(pathSegment.ray.direction, normal);
pathSegment.color *= m.specular.color;
}
}
else if (probability > m.hasReflective) {
pathSegment.color *= m.color;
pathSegment.ray.direction = calculateRandomDirectionInHemisphere(normal, rng);
}
else {
// specular reflection
pathSegment.color *= m.specular.color;
pathSegment.ray.direction = glm::reflect(pathSegment.ray.direction, normal);
}
pathSegment.ray.origin = intersect + 0.01f * pathSegment.ray.direction;
}

__host__ __device__
void scatterRay1(
PathSegment & pathSegment,
glm::vec3 intersect,
glm::vec3 normal,
const Material &m,
thrust::default_random_engine &rng) {
// TODO: implement this.
// A basic implementation of pure-diffuse shading will just call the
// calculateRandomDirectionInHemisphere defined above.
pathSegment.ray.direction = calculateRandomDirectionInHemisphere(normal, rng);
pathSegment.color *= m.color;
pathSegment.ray.origin = intersect + normal * 0.01f;
}
Loading