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: HANTING XU #12

Open
wants to merge 4 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
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ set(headers
src/preview.h
src/utilities.h
src/ImGui/imconfig.h
src/tiny_obj_loader.h
src/BVH.h

src/ImGui/imgui.h
src/ImGui/imconfig.h
Expand Down Expand Up @@ -111,11 +113,20 @@ list(SORT sources)
source_group(Headers FILES ${headers})
source_group(Sources FILES ${sources})

#add_subdirectory(src/ImGui)

set(TINYGLTF_HEADER_ONLY ON CACHE INTERNAL "" FORCE)
set(TINYGLTF_INSTALL OFF CACHE INTERNAL "" FORCE)
add_subdirectory(src/tinygltf)
#add_subdirectory(stream_compaction) # TODO: uncomment if using your stream compaction
#set(TINYGLTF_HEADER_ONLY ON CACHE INTERNAL "" FORCE)
#set(TINYGLTF_INSTALL OFF CACHE INTERNAL "" FORCE)


cuda_add_executable(${CMAKE_PROJECT_NAME} ${sources} ${headers})
target_link_libraries(${CMAKE_PROJECT_NAME}
${LIBRARIES}
#tinygltf
#stream_compaction # TODO: uncomment if using your stream compaction
)

#add_subdirectory(tinygltf)
56 changes: 51 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,57 @@ 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)
* Hanting Xu
* [GitHub](https://github.com/HantingXu), [LinkedIn](www.linkedin.com/in/hanting-xu-25615b28b).
* Tested on: (Personal Computer) Windows 11, i7-12700H @ 2.70GHz 32GB, GeForce RTX 3070 Ti Laptop GPU

### (TODO: Your README)
* Show Case:
![Show Case 0](img/little_prince.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.
## Path Tracing

### Handling Different Materials
* Emissive, diffuse, specular and refractive objects are all handled. For future work, more parameters should be introduced to control the roughness of the objects. This could be implemented by setting different probability for the direction of reflection lights.

### Mesh Loading & Texture Mapping
* Third Party Reference:
For obj file loading, the [sample code](https://github.com/tinyobjloader/tinyobjloader) for tinyOBJ is used in this project. And for gltf mesh loading, the [code](https://github.com/syoyo/tinygltf) in tinyGLTF is used for loading gltf meshes. Also, simple texture mapping is supported, but just for base color. The program gives no support for the normal mapping or roughness mapping. If a object is not given a valid texture, the program would generate a procedural texture for it automatically. Note : All the textures and objects address that are wished to be added into the scene should be entered as the full path in the scene file.

### Antialiasing
* The implementation for antialiasing is quite simple, which is just randomly slightly shift the ray direction of each pixel at the start of every iteration.

### Depth Of Field
* Depth of field simulate the defocusing effects that of lens. This effect is simulated by putting disk at a depth in front of our image plane and adjusting the light direction to create a effect of blur. For more information, please refer to the [book](https://raytracing.github.io/books/RayTracingInOneWeekend.html).

### Gaussian and SVGF Denoising
* Gaussian Denoise: It is a really primitive filter. Basically blurs everything. You can change the blurring radius as you want.

* SVGF: Different from gaussion which simply deals with the obtained image, SVGF allows us to maintain the boundary of each objects by taking the surface normal, albedo, depth and object index into consideration.

### BVH Tree Building and Traversal On GPU
* BVH Tree construction: The construction of the tree is on GPU side. It is a simple implementation of this [article](https://developer.nvidia.com/blog/thinking-parallel-part-iii-tree-construction-gpu/) from Nvdia. This can be devided into the steps following: Building Morton Codes, Sorting Morton Codes, Splitting BVH Nodes and Building Bounding Boxes. My code basically follows every steps in the article. For Splitting Node, I refers to this [paper](https://developer.nvidia.com/blog/parallelforall/wp-content/uploads/2012/11/karras2012hpg_paper.pdf). The only difference from my implementation and the article is that, I didn't use the atomic operation for building bounding boxes in the last step, but just naively update each level iteratively. Future work could be done to support atomic operation, which should speedup the performance.

* BVH Tree traversal: For BVH tree traversal, my implementation is based on this [article](https://developer.nvidia.com/blog/thinking-parallel-part-ii-tree-traversal-gpu/), which avoids the recursive traversal by maintaining a stack for the nodes that should be traversed later.

### Performance Analysis
* According to my observation, antialiasing, DoF effect, denoising don't have a significant effect on the performance, especially when the triangle count becomes large.

* Material Sorting: In my original thought, sorting light paths according to their material before shading should increase the performance. However, according to data gather, it may not be true. The performance without sorting seems to be better than that of the sorted ones under different triangle numbers in the scene. Sorting overheads might accounts for this or I just implemented it wrong?

![Show Case 2](img/Material_Sorting.png)

* BVH: Using BVH traversal to find the intersection have a huge boost on the performance, especially when the faces numbers increased. The graph below demonstrates its influence.

![Show Case 3](img/Material_Sorting.png)


### Discoveries
* Before I put all the vertices, normal and uv data all into the Triangle Struct, I used to store them into seperate device arrays. Even though it looks messier, which is a main reason I packed them together, its performance is actually better than the current version. This is probably because this way of reading data more efficient.

### Show Case

* ![Show Case 4](img/blur.png)
* ![Show Case 4](img/material.png)
* ![Show Case 4](img/crocodile.png)
* ![Show Case 4](img/SVGF.png)
* ![Show Case 4](img/little_duck.png)
Binary file added img/BVH.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/Material_Sorting.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/SVGF.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/blur.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/crocodile.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/gaussian.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/little_duck.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/little_prince.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/material.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 88 additions & 7 deletions scenes/cornell.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 5
EMITTANCE 25

// Diffuse white
MATERIAL 1
Expand All @@ -30,7 +30,7 @@ EMITTANCE 0

// Diffuse green
MATERIAL 3
RGB .35 .85 .35
RGB .35 .35 .85
SPECEX 0
SPECRGB 0 0 0
REFL 0
Expand All @@ -48,6 +48,16 @@ REFR 0
REFRIOR 0
EMITTANCE 0

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

// Camera
CAMERA
RES 800 800
Expand All @@ -64,6 +74,7 @@ UP 0 1 0
OBJECT 0
cube
material 0
texture -1
TRANS 0 10 0
ROTAT 0 0 0
SCALE 3 .3 3
Expand All @@ -72,6 +83,7 @@ SCALE 3 .3 3
OBJECT 1
cube
material 1
texture -1
TRANS 0 0 0
ROTAT 0 0 0
SCALE 10 .01 10
Expand All @@ -80,6 +92,7 @@ SCALE 10 .01 10
OBJECT 2
cube
material 1
texture -1
TRANS 0 10 0
ROTAT 0 0 90
SCALE .01 10 10
Expand All @@ -88,6 +101,7 @@ SCALE .01 10 10
OBJECT 3
cube
material 1
texture -1
TRANS 0 5 -5
ROTAT 0 90 0
SCALE .01 10 10
Expand All @@ -96,6 +110,7 @@ SCALE .01 10 10
OBJECT 4
cube
material 2
texture -1
TRANS -5 5 0
ROTAT 0 0 0
SCALE .01 10 10
Expand All @@ -104,14 +119,80 @@ SCALE .01 10 10
OBJECT 5
cube
material 3
texture -1
TRANS 5 5 0
ROTAT 0 0 0
SCALE .01 10 10

// Sphere

// Mesh cube
OBJECT 6
sphere
material 4
TRANS -1 4 -1
ROTAT 0 0 0
mesh
material 1
texture 0
TRANS 0 3 0
ROTAT 0 45 0
SCALE 5 5 5
LINK C:/Users/2000/Downloads/deino/scene.gltf

// Mesh cube
OBJECT 7
mesh
material 1
texture 1
TRANS 4 4 4
ROTAT 0 45 0
SCALE 3 3 3
LINK C:/Users/2000/Downloads/pokemon_137_-_porygon/scene.gltf
//C:/Users/2000/Downloads/stanford_dragon_pbr/scene.gltf
//C:/Users/2000/Downloads/stanford_bunny_pbr/scene.gltf
//C:/Users/2000/Downloads/stanford_dragon_vrip_res_3/scene.gltf
//C:/Users/2000/Downloads/stanford_bunny_pbr/scene.gltf
//C:/Users/2000/Downloads/glTF-Sample-Models-2.0-Duck/glTF/Duck.gltf
//C:/Users/2000/Downloads/deino/scene.gltf
//C:/Users/2000/Downloads/pokemon_137_-_porygon/scene.gltf
//C:/Users/2000/Downloads/deino/scene.gltf
//C:/Users/2000/Downloads/pokemon_137_-_porygon/scene.gltf
//C:/Users/2000/Downloads/deino/scene.gltf
//C:/Users/2000/Downloads/pokemon_137_-_porygon/scene.gltf
//C:/Users/2000/Downloads/deino/scene.glt
//C:/Users/2000/Downloads/trapezo-rhombic_dodecahedron/scene.gltf
//C:/Users/2000/Downloads/low-poly-fox/source/LowPolyAnimal.obj
//C:/Users/2000/Downloads/deino/scene.gltf
//C:/Users/2000/Downloads/low-poly-fox/source/LowPolyAnimal.obj
//C:/Users/2000/Downloads/glTF-Sample-Models-2.0-Duck/glTF/Duck.gltf
//C:/Users/2000/Downloads/minecraft-kirby/source/model.gltf
//C:/Users/2000/Downloads/mimikyu/scene.gltf
//C:/Users/2000/Downloads/minecraft-grass-block/source/Minecraft_Grass_Block_OBJ/Grass_Block.obj
//C:/Users/2000/Downloads/mimikyu/scene.gltf
//C:/Users/2000/Downloads/crystal1/scene.gltf
//C:/Users/2000/Downloads/low-poly_head/scene.gltf
//C:/Users/2000/Downloads/pokemon_137_-_porygon/scene.gltf


TEXTURE 0
LINK C:/Users/2000/Downloads/deino/textures/body_mat_baseColor.png

TEXTURE 1
LINK C:/Users/2000/Downloads/mimikyu/textures/body_baseColor.png
//C:/Users/2000/Downloads/stanford_dragon_vrip_res_3/jade.png
//C:/Users/2000/Downloads/stanford_bunny_pbr/textures/DefaultMaterial_baseColor.png
//C:/Users/2000/Downloads/deino/textures/body_mat_baseColor.png
//C:/Users/2000/Downloads/low-poly-fox/textures/TextureDiff3.png
//C:/Users/2000/Downloads/deino/textures/body_mat_baseColor.png
//C:/Users/2000/Downloads/trapezo-rhombic_dodecahedron/textures/Material1_baseColor.png
//C:/Users/2000/Downloads/deino/textures/body_mat_baseColor.png
//C:/Users/2000/Downloads/low-poly-fox/textures/TextureDiff3.png
//C:/Users/2000/Downloads/deino/textures/body_mat_baseColor.png
//C:/Users/2000/Downloads/low-poly-fox/textures/TextureDiff3.png
//C:/Users/2000/Downloads/glTF-Sample-Models-2.0-Duck/glTF/DuckCM.png
//C:/Users/2000/Downloads/minecraft-kirby/textures/gltf_embedded_0.png
//C:/Users/2000/Downloads/minecraft-grass-block/source/Minecraft_Grass_Block_OBJ/Grass_Block_TEX.png
//C:/Users/2000/Downloads/mimikyu/textures/body_baseColor.png
// Sphere
//OBJECT 6
//sphere
//material 1
//TRANS -1 4 -1
//ROTAT 0 0 0
//SCALE 3 3 3
60 changes: 60 additions & 0 deletions scenes/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Emissive material (light)
MATERIAL 0
RGB 1 1 1
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 5

// Diffuse red
MATERIAL 1
RGB 1 1 1
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0

// Camera
CAMERA
RES 800 800
FOVY 70
ITERATIONS 5000
DEPTH 8
FILE sphere
EYE 0.0 5.0 10.5
LOOKAT 0 5 0
UP 0 1 0

// Ceiling light
OBJECT 0
cube
material 0
TRANS 0 15.0 0
ROTAT 0 0 0
SCALE 4 .4 4

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

// Sphere
OBJECT 2
mesh
material 1
TRANS 0.0 -1.0 0.0
ROTAT 0 90 0
SCALE 5 5 5
LINK C:/Users/2000/Downloads/pokemon_137_-_porygon/scene.gltf
//LINK C:/Users/2000/Downloads/pokemon_137_-_porygon/scene.gltf
//LINK C:/Users/2000/Downloads/pixeled_eagle/scene.gltf
//LINK C:/Users/2000/Downloads/pokemon_137_-_porygon/scene.gltf
//LINK C:/Users/2000/Downloads/Fox/Fox.gltf
//LINK C:/Users/2000/Downloads/glTF-Sample-Models-2.0-Cube/glTF/Cube.gltf
Loading