Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
083938a
Added Materials for interaction
codeplay9800 Sep 28, 2021
e86b928
Added StreamCompactionFiles
codeplay9800 Sep 28, 2021
e1a5c4f
Updated Compaction
codeplay9800 Sep 29, 2021
5fd2ebc
Updated Path Trace to Fix compaction
codeplay9800 Sep 29, 2021
ddee860
Fixed Compaction
codeplay9800 Sep 29, 2021
a157cae
Added Kernel for Thrustsort by key
codeplay9800 Sep 29, 2021
67143cf
pathtrace updated
codeplay9800 Sep 29, 2021
bd79751
UPdate Shading Code
codeplay9800 Sep 30, 2021
5e01699
Updated PAth trace
codeplay9800 Sep 30, 2021
563b09b
thrust Sort Implemented
codeplay9800 Sep 30, 2021
99a74b1
cache updated
codeplay9800 Sep 30, 2021
722ee36
Part1Complete
codeplay9800 Sep 30, 2021
a656e0e
Refraction Code
codeplay9800 Sep 30, 2021
9e0d052
Refection Working
codeplay9800 Sep 30, 2021
42cb9d3
Push
codeplay9800 Sep 30, 2021
bb22e11
AntiAliasing Implemented
codeplay9800 Oct 1, 2021
89095d7
Added tiny obj Loader to scene
codeplay9800 Oct 1, 2021
33996c3
obj loader Added
codeplay9800 Oct 1, 2021
616391f
Mesh Loading Added
codeplay9800 Oct 1, 2021
005ccf9
Midway
codeplay9800 Oct 2, 2021
df72d70
Push
codeplay9800 Oct 2, 2021
400e1ff
Refraction Fixed
codeplay9800 Oct 3, 2021
c6fd105
Mesh Working
codeplay9800 Oct 3, 2021
9e6bd73
Fixed Normals
codeplay9800 Oct 3, 2021
60022df
Update To cube
codeplay9800 Oct 3, 2021
d6a8eed
dof half way
codeplay9800 Oct 3, 2021
66d2b45
Update
codeplay9800 Oct 3, 2021
a0170be
Added Depth Of Field
codeplay9800 Oct 3, 2021
9d3424f
Added BSDF FUnction
codeplay9800 Oct 3, 2021
b9a2b3a
Created Text Docs
codeplay9800 Oct 4, 2021
eb71980
Update Hermite
codeplay9800 Oct 4, 2021
ea90af3
Fixed Mesh Calculation
codeplay9800 Oct 4, 2021
e4e5ab9
Depth Of Field Fixed
codeplay9800 Oct 5, 2021
5a6f787
Mesh Fixed
codeplay9800 Oct 5, 2021
336a108
BVH Class Added
codeplay9800 Oct 5, 2021
620b9fe
BVH Updated
codeplay9800 Oct 5, 2021
e4b381e
BVH COde Working
codeplay9800 Oct 5, 2021
659a24c
Update BVH
codeplay9800 Oct 6, 2021
f325dd1
BVH Fixed
codeplay9800 Oct 6, 2021
f5600d2
Finish BVH
codeplay9800 Oct 6, 2021
202757d
L Systems added
codeplay9800 Oct 7, 2021
e7076e0
LSystemWorking
codeplay9800 Oct 7, 2021
1ab1238
LSystem COmplete
codeplay9800 Oct 7, 2021
57f0895
Procedural Texture Working
codeplay9800 Oct 8, 2021
cc1a76e
Noise 2nd Added
codeplay9800 Oct 8, 2021
1ecbd30
Added check for proc texture
codeplay9800 Oct 8, 2021
bf2a51b
Sub Surface Working
codeplay9800 Oct 9, 2021
0d1ebe9
depth of field fixed
codeplay9800 Oct 9, 2021
13ce935
reverted dof
codeplay9800 Oct 9, 2021
f62d361
Updated Cmake
codeplay9800 Oct 9, 2021
2e01e50
L SYstems Added
codeplay9800 Oct 9, 2021
1cfb9cc
Clean Code
codeplay9800 Oct 9, 2021
473506f
Refactor Code
codeplay9800 Oct 9, 2021
2693fd1
Updated
codeplay9800 Oct 9, 2021
4d8d936
Readme Updated
codeplay9800 Oct 9, 2021
bd6f508
Update Bunny
codeplay9800 Oct 9, 2021
ac7c44f
Update Code
codeplay9800 Oct 9, 2021
a0dee41
Update Readme
codeplay9800 Oct 9, 2021
1c8a5c2
Update Readme
codeplay9800 Oct 9, 2021
bb8815b
Added Images Readme Upated
codeplay9800 Oct 11, 2021
dc91311
Udpated
codeplay9800 Oct 11, 2021
ba733e9
Updated Readme
codeplay9800 Oct 11, 2021
a679994
Readme
codeplay9800 Oct 11, 2021
fa8ee36
updateReadme
codeplay9800 Oct 11, 2021
fe4029c
Update Readme
codeplay9800 Oct 11, 2021
be0a881
Update readme
codeplay9800 Oct 11, 2021
ca5cdf9
Readme Update
codeplay9800 Oct 11, 2021
0d8cd43
Update Readme
codeplay9800 Oct 11, 2021
b86bdab
Readme Update
codeplay9800 Oct 11, 2021
740e2f9
Update Bloopers
codeplay9800 Oct 11, 2021
0745b8f
Update Readme
codeplay9800 Oct 11, 2021
2ed428b
Update Readme
codeplay9800 Oct 11, 2021
cb99805
Update Readme
codeplay9800 Oct 11, 2021
7a3f079
Update Readme
codeplay9800 Oct 11, 2021
11b8a7e
Update Readme
codeplay9800 Oct 11, 2021
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
21 changes: 19 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ set(headers
src/sceneStructs.h
src/preview.h
src/utilities.h
src/MeshLoading/tiny_obj_loader.h
src/MeshLoading/polygon.h
src/MeshLoading/BVH.h
src/LSystem/lsystem.h
src/LSystem/postcondition.h
src/LSystem/rule.h
src/LSystem/symbol.h
src/LSystem/turtle.h
src/ProceduralTextures.h
)

set(sources
Expand All @@ -84,6 +93,14 @@ set(sources
src/scene.cpp
src/preview.cpp
src/utilities.cpp
src/MeshLoading/tiny_obj_loader.cc
src/MeshLoading/polygon.cpp
src/MeshLoading/BVH.cpp
src/LSystem/lsystem.cpp
src/LSystem/postcondition.cpp
src/LSystem/rule.cpp
src/LSystem/symbol.cpp
src/LSystem/turtle.cpp
)

list(SORT headers)
Expand All @@ -92,10 +109,10 @@ list(SORT sources)
source_group(Headers FILES ${headers})
source_group(Sources FILES ${sources})

#add_subdirectory(stream_compaction) # TODO: uncomment if using your stream compaction
add_subdirectory(stream_compaction) # TODO: uncomment if using your stream compaction

cuda_add_executable(${CMAKE_PROJECT_NAME} ${sources} ${headers})
target_link_libraries(${CMAKE_PROJECT_NAME}
${LIBRARIES}
#stream_compaction # TODO: uncomment if using your stream compaction
stream_compaction # TODO: uncomment if using your stream compaction
)
126 changes: 121 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,127 @@ 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)
* Shubham Sharma
* [LinkedIn](www.linkedin.com/in/codeshubham), [personal website](https://shubhvr.com/).
* Tested on: Windows 10, i7-9750H @ 2.26GHz, 16GB, GTX 1660ti 6GB (Personal Computer).
*GPU Compute Capability: 7.5

### (TODO: Your README)
![Performance Analysis](img/Mesh/xyzdragon.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.
## Project Description

Path tracing is a computer graphics Monte Carlo method of rendering images of three-dimensional scenes such that the global illumination is faithful to reality.

### Features
- Shading Kernel with BSDF Evaluation
- Uniform diffuse
- Perfect specular reflective (mirror)
- specular refractive (Fresnel dielectric)
- Path Continuation/Termination with Stream Compaction
- Toggleable Sorting of ray Paths by material type
- Toggleable first bounce intersection cache to be used by subsequent iterations
- Anti-aliasing rays with sub-pixel samples
- Arbitrary OBJ Mesh Loading with toggleable 7 Plane Bounding Volume intersection culling
- Camera depth of field
- Procedural Structure
- Procedural texture
- Subsurface Scattering (In Progress)

### Materials
Material shading is split into different BSDF evaluation functions based on material type. This project supported materials include **diffuse**, **reflective** and **refractive** (fresnel dielectric). Diffuse material scattering is computed by using cosine-weighted samples within a hemisphere. Reflective materials reflect the light ray about the surface nornmal and refractive materials refracts the ray through the material according to Snell's law of refraction and with added fresnel computation for better real life depiction.
Here's an image consisting of the three materials
- Left: **Diffuse**
- Middle: **Refractive** (Fresnel and Schlick)
- Right: **Reflective (Perfect Specular)**


![Performance Analysis](img/Basic/Material.png)

Below, a compound reflective and refractive impact is executed through a Fresnel fabric, which reflects light beams that are more digression to its surface. This makes a light rays passing through the object refracted, whereas rays brushing the sides of the fabric are reflected. Rather than specifically calculating the Fresnel component, I assess it utilizing Schlick's approximation.
Here's an image consisting of the three refractive materials.
- Left: Refractive index: 1.2
- Middle: Refractive index: 2.5
- Right : Probabilistic Reflective and Refractive Material: Refractive index: 1.2

![Performance Analysis](img/Basic/Refractive.png)

### Depth Of Field
The scene camera can be set to enable Depth of Field effect which utilises focal distance and lens radius parameters to change the depth of this effect. Geometries located at the focal distance within the lens radius stay in focus while other geometry around the scene will be distorted.

- **Focal Distance: 10**
![Performance Analysis](img/DOF/focal10.png)

- **Focal Distance: 20**
![Performance Analysis](img/DOF/focal20.png)

### Stochastic Anti-Aliasing
Utilizing anti-aliasing for subpixel sampling brings in smoother geometry edges within the render. It is vital to note that anti-aliasing and first bounce cache don't work together, since the pixel tests will vary per iteration, and ached first bounces from the first iteration won't match the generated ray direction in further iterations. I added the flag for Cache Bounce which toggles off anti-aliasing and setting cache off in turn enables anti-aliasing,

- **With Anti-Aliasing**
![Performance Analysis](img/AntiAliasing/aa.png)

- **Without Anti-Aliasing**
![Performance Analysis](img/AntiAliasing/waa.png)

### OBJ Loading
In order to bring the mesh data into C++, I used the tinyobj library. I build the polygon mesh using the position and normal data of the triangles triangles from the imported data to create the mesh triangles and store triangle information per arbitrary mesh.

7 planar Bounding volume intersection culling as proposed by Kay and Kajiya in accelerated structeres, is applied at the ray-geometry intersection test to 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 feature is implemented as toggleable for performance analysis purposes. Pressing the 'B' key while running the GPU renderer will enable this feature.

In order to smoothen the triangles on round meshes, the intersection normal is computed from the barycentric interpolation of the 3 normals from the triangle vertices.

- **Lucy**
![Performance Analysis](img/Mesh/Lucy.png)

- **Wahoo**
![Performance Analysis](img/Mesh/wahoo.png)

### Procedural Structures
I have used L System grammar which generates complex patterns for procedural data. An L-system consists of an alphabet of symbols that can be used to make strings, It consist of an axiom: initial configuration, a collection of production rules that expand each symbol into some larger string of symbols and a mechanism for translating the generated strings into geometric structures.

![Performance Analysis](img/ProceduralShapes/1.png)

![Performance Analysis](img/ProceduralShapes/tree.png)

### Procedural Textures
I have used a simple sinusoidal and cosine functions as well combination of different noise functions like Perlin, FBM and Worley to generate procedural textures. A spherical bi linear function which transforms positional coordinates to UV coordinates is used in turn with noise functions to apply these textures accross wide variety of mesh data.

![Performance Analysis](img/ProceduralTexture/1.png)

# Performance Analysis

## Optimisations

### Stream Compaction

Stream compaction generally progress the execution by terminating the rays in case they are futile. Less threads will be made and the execution quickened. The first-bounce cache moreover moves forward 13% execution by caching the primary crossing point of the beam. In expansion, the work puts the active rays closer together in memory, which ought to make getting to faster global memory access rates since they gets to will be continguous, rather than random. Underneath Values of remaining rays in Open and Closed Cornell Box shown in the chart.

![Performance Analysis](img/Compaction.PNG)

### Material Sorting
In my case the material sorting slows down the execution time of program. I believe this can be attributed to less number of materials in my scene to begin with. The method in theory would sort the rays with similar material object intersections closer as they will have about the same lifetime. Since the scene doesn't have many materials the probablity of rays with same material behaviour being contiguous in memory is already high and sorting them only adds an overhead in this case. If the scene has a large number of materials then i believe the execution times will increase with Material Sorting.

### Caching First Bounce
Since the first bounce intersections stays the same if the camera doesn't change, A cache can be implemented to save the intersection of the first bounce in the first iteration and the results can be directly used in later iterations. Since for antialiasing each iteration first bounce is different caching cant be done.
I have recorded an average of the exection time of my program for 3000 iterations below, with and without caching the first bounce. From the data we can depict an improvement of of 90ms in execution times.

| Without Cache | With Cache |
|---|---|
| 2min 4.03s | 2min 3.08s |

### Volume Intersection Culling
I used 3 arbitrary mesh examples to analyze the peformance benefits of enabling volume intersection culling for complex meshes. The table below shows the mesh examples used for this analysis and how many triangles they contain.

| Cube | Lucy | XYZ Dragon |
|---|---|---|
| 12 | 19998 | 50000 |


![Performance Analysis](img/VolumeIntersectionCulling.png)

Using volume intersection culling for simpler arbitrary meshes with low triangle count such as cube doesn't provide a significant performance improvement. However as the triangle count increases we can see significant improvement which can be attributed to number of triangles to check if bounding volume is hit. Each ray only performs 7 intersection check with 7 sided polygon volume heirarchy as compared to 50000 intersection checks with triangles for XYZ dragon. With BVH we save about 7 seconds in just 10 iterations.

### Bloopers
![Performance Analysis](img/Bloopers/1.png)
![Performance Analysis](img/Bloopers/2.png)
![Performance Analysis](img/Bloopers/3.png)
Binary file added img/AntiAliasing/aa.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/AntiAliasing/waa.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/Basic/Material.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/Basic/Refractive.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/Bloopers/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/Bloopers/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/Bloopers/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/Compaction.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/cornell.2021-10-10_16-41-25z.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/DOF/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/DOF/focal20.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/Mesh/Lucy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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/Mesh/wahoo.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/Mesh/xyzdragon.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/ProceduralShapes/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/ProceduralShapes/tree.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/ProceduralTexture/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/VolumeIntersectionCulling.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
145 changes: 145 additions & 0 deletions scenes/Cube.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// Emissive material (light)
MATERIAL 0
RGB 1 1 1
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 5
usingProcTex 0
isSubSurface 0

// Emissive material
MATERIAL 1
RGB 0.339 0.1 0.5552
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 5
usingProcTex 0
isSubSurface 0

// Emissive material
MATERIAL 2
RGB 0.6 0.25 0
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 5
usingProcTex 0
isSubSurface 0

// Emissive material
MATERIAL 3
RGB 0.002 0.438 0.559
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 5
usingProcTex 0
isSubSurface 0

// Diffuse white
MATERIAL 4
RGB .98 .98 .98
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0
usingProcTex 0
isSubSurface 0

// Reflective white
MATERIAL 4
RGB .98 .98 .98
SPECEX 0
SPECRGB 0 0 0
REFL 1
REFR 0
REFRIOR 0
EMITTANCE 0
isSubSurface 0

// Emissive material
MATERIAL 5
RGB 0.9 0 0
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 5
usingProcTex 0
isSubSurface 0

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

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

// Right light2
OBJECT 1
cube
material 2
TRANS 10 0 0
ROTAT 0 0 -90
SCALE 10 .3 10


// Left light3
OBJECT 2
cube
material 3
TRANS -10 0 0
ROTAT 0 0 -90
SCALE 10 .3 10


// Back light3
OBJECT 3
cube
material 0
TRANS 0 0 -10
ROTAT 90 0 0
SCALE 10 .3 10


// Wahoo
OBJECT 4
obj
material 4
TRANS 0 3 0
ROTAT 0 0 0
SCALE 1 1 1

// Floor
OBJECT 5
cube
material 4
TRANS 0 -5 0
ROTAT 0 0 0
SCALE 10 .01 10

Loading