Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
ff51cb4
naivePT
JinxiangW Sep 21, 2024
5cf1fff
cameraAA, but behaves not as expected
JinxiangW Sep 21, 2024
0e4ca60
illegal memory access to question about
JinxiangW Sep 22, 2024
8943b6f
load a cube
JinxiangW Sep 22, 2024
4273980
add normal display for debugging
JinxiangW Sep 22, 2024
272a344
fixed bugs that corner is lighten up
JinxiangW Sep 22, 2024
c370585
postprocessing pipeline and ACES tone mapping
JinxiangW Sep 24, 2024
6743fa9
working on environmental mapping, tex2D not working for some reason
JinxiangW Sep 25, 2024
3d72dd6
fixed environmental map
JinxiangW Sep 26, 2024
1111ed9
reorranging data structures, temp update
JinxiangW Sep 26, 2024
d04525d
reorranged some data, change intersection calculation from glm::rayTr…
JinxiangW Sep 26, 2024
6b7818c
BVH-SAH partition
JinxiangW Sep 27, 2024
1c1a631
add HLBVH
JinxiangW Sep 28, 2024
0e9750b
complete bvh
JinxiangW Sep 28, 2024
3feaec0
runnable bvh, but very slow
JinxiangW Sep 29, 2024
912ef40
modified loadJson()
JinxiangW Sep 30, 2024
57b4958
delete codes that caused unfreed memory, BVH behaves goood
JinxiangW Sep 30, 2024
a85c578
minor update
JinxiangW Sep 30, 2024
ef94634
minor update, implementing mis
JinxiangW Sep 30, 2024
89b7882
re arrange material loading method
JinxiangW Sep 30, 2024
d9c9709
BVH visualizer
JinxiangW Oct 1, 2024
92a8f7c
minor update
JinxiangW Oct 2, 2024
9106e51
fixed BVH, intersect 2M triangle dragon very fast
JinxiangW Oct 3, 2024
8c67714
minor update
JinxiangW Oct 3, 2024
9411b66
disney_bsdf: fdiffuse_baseColor
JinxiangW Oct 4, 2024
6c7dde3
direct lighting
JinxiangW Oct 5, 2024
3b529e0
MIS
JinxiangW Oct 6, 2024
ff7d811
minor update
JinxiangW Oct 7, 2024
22466f9
btdf
JinxiangW Oct 7, 2024
9a75113
add oidn
JinxiangW Oct 8, 2024
9d973f6
workable denoiser
JinxiangW Oct 9, 2024
da47e83
add cover
JinxiangW Oct 9, 2024
1a954d0
minor update
JinxiangW Oct 10, 2024
5b8d361
minor update
JinxiangW Oct 10, 2024
ed40538
update readme
JinxiangW Oct 10, 2024
443a9a3
update Readme
JinxiangW Oct 10, 2024
897d481
Update README.md
JinxiangW Oct 10, 2024
982c282
update readme
JinxiangW Oct 11, 2024
215d158
Update README.md
JinxiangW Oct 11, 2024
2544d05
Update README.md
JinxiangW Oct 11, 2024
9e0dd3d
Update README.md
JinxiangW Oct 11, 2024
6d714c1
add part of objs
JinxiangW Nov 4, 2024
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
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*.vcxproj
*.xcodeproj
build

*/hdri
# Created by https://www.gitignore.io/api/linux,osx,sublimetext,windows,jetbrains,vim,emacs,cmake,c++,cuda,visualstudio,webstorm,eclipse,xcode

### Linux ###
Expand All @@ -23,7 +23,8 @@ build
.LSOverride

# Icon must end with two \r
Icon
Icon


# Thumbnails
._*
Expand Down
37 changes: 36 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ else(UNIX)

add_definitions(${GLEW_DEFINITIONS})
include_directories(${GLEW_INCLUDE_DIR} ${GLFW_INCLUDE_DIR})
set(LIBRARIES ${GLEW_LIBRARY} ${GLFW_LIBRARY} ${OPENGL_LIBRARY})

set(OIDN_ROOT_DIR ${EXTERNAL}/oidn)
include_directories("${OIDN_ROOT_DIR}/include")
link_directories("${OIDN_ROOT_DIR}/lib")

set(LIBRARIES ${GLEW_LIBRARY} ${GLFW_LIBRARY} ${OPENGL_LIBRARY} OpenImageDenoise)
endif(UNIX)

set(GLM_ROOT_DIR "${CMAKE_SOURCE_DIR}/external")
Expand All @@ -61,6 +66,15 @@ set(headers
src/sceneStructs.h
src/preview.h
src/utilities.h
src/tiny_obj_loader.h
src/PTDirectives.h
src/bvh.h
src/texture.h
src/memoryArena.h
src/cudaUtilities.h
src/light.h
src/pbr.h
src/disneybsdf.h
)

set(sources
Expand All @@ -74,6 +88,10 @@ set(sources
src/scene.cpp
src/preview.cpp
src/utilities.cpp
src/tiny_obj_loader.cpp
src/bvh.cu
src/texture.cu
src/cudaUtilities.cu
)

set(imgui_headers
Expand Down Expand Up @@ -128,3 +146,20 @@ target_link_libraries(${CMAKE_PROJECT_NAME}
target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE "$<$<AND:$<CONFIG:Debug,RelWithDebInfo>,$<COMPILE_LANGUAGE:CUDA>>:-G;-src-in-ptx>")
target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE "$<$<AND:$<CONFIG:Release>,$<COMPILE_LANGUAGE:CUDA>>:-lineinfo;-src-in-ptx>")
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${CMAKE_PROJECT_NAME})


# add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy_if_different
# "${CMAKE_SOURCE_DIR}/external/oidn/bin/OpenImageDenoise.dll"
# $<TARGET_FILE_DIR:${CMAKE_PROJECT_NAME}>
# COMMAND ${CMAKE_COMMAND} -E copy_if_different
# "${CMAKE_SOURCE_DIR}/external/oidn/bin/OpenImageDenoise_core.dll"
# $<TARGET_FILE_DIR:${CMAKE_PROJECT_NAME}>)

file(GLOB OIDN_DLLS "${PROJECT_SOURCE_DIR}/external/oidn/bin/*.dll")
foreach(DLL ${OIDN_DLLS})
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"${DLL}"
"$<TARGET_FILE_DIR:${CMAKE_PROJECT_NAME}>")
endforeach()
159 changes: 152 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,158 @@
CUDA Path Tracer
================
# 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)
- Jinxiang Wang
- Tested on: Windows 11, AMD Ryzen 9 8945HS w/ Radeon 780M Graphics 4.00 GHz 32GB, RTX 4070 Laptop 8 GB

### (TODO: Your README)
## Results Preview:

*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.
![](results/Cover/CoverDenoisedMIS.png)

<p align="center">A large mineway castle shaded with one Disney BRDF material (6,490,766 triangles, 300 spp, 6.1 fps)</p>

![](results/RefractDragon.png)

<p align="center">A stanford dragon shaded with refract material</p>

## Features Implemented:

1. Bounding Volume Hierarchy (HLBVH)
2. Disney DRDF model (not fully correct in some cases)
3. GUI for dynamic material modification
4. Muiti-Importance Sampling
5. ACES Tone Mapping
6. TinyObj mesh loading
7. Environment Map
8. Stocastic Sampled Anti-Aliasing

# Bounding Volume Hierarchy

The base code shoots rays out from the camera and compute intersections with all objects in the scene.

This works fine when we can implicitly define intersecting method for each geometry (just like SDF). But after mesh loading feature is implemented, the way of light-scene intersection is changed from calculating
intersection with implicit geometries to calculating it with all triangles!

This gives an extremely low performance when model with many faces is loaded:

| < 200 faces (~60 fps) | ~6000 faces (< 10 fps) |
| -------------------------------- | ------------------------------- |
| ![](results/BVH/simplescene.png) | ![](results/BVH/marioScene.png) |

To effectively reduce the amout of intersection computation, we could use BVH, Bounding Volume Hierarchy, which construct
a tree-like structure to store scene primitives.

The efficiency of BVH depends on how we build the tree. There are many ways to segment triangls, for this project, I used HLBVH, which is a combination of Surface Area Heuristic (SAH) and morton code based Linear BVH. For more reference, check [PBRT 4.3 Bounding Volume Hierarchy](https://pbr-book.org/3ed-2018/Primitives_and_Intersection_Acceleration/Bounding_Volume_Hierarchies).

And this gives a very good speed up

| Before BVH (< 10 fps) | After BVH (~30 fps) |
| ------------------------------- | ----------------------------- |
| ![](results/BVH/marioScene.png) | ![](results/BVH/AfterBVH.png) |

We can go even further with a stanford dragon (2,349,078 triangles)

| Dragon ( 15 fps) |
| --------------------------- |
| ![](results/BVH/Dragon.png) |

Visualizer:

| Wahoo | Dragon | Mineway Castle |
| ------------------------ | ------------------------------ | ----------------------------- |
| 5117 triangles | 2,349,078 triangles | 6,490,766 triangles |
| ![](results/BVH/BVH.png) | ![](results/BVH/DragonBVH.png) | ![](results/BVH/CoverBVH.png) |

# Disney BRDF Model

This is a robust and art-oriented material model that allows for interpolation between different types of material based on pbr parameters. The model implemented in this project referenced SIGGRAPH 2012 [Physically Based Shading at Disney](https://media.disneyanimation.com/uploads/production/publication_asset/48/asset/s2012_pbs_disney_brdf_notes_v3.pdf) by Disney and their public repo [brdf](https://github.com/wdas/brdf/tree/main)
![](results/DisneyBRDF/presentation.png)

The input parameters are given by:

color baseColor .82 .67 .16
float metallic 0 1 0
float subsurface 0 1 0
float specular 0 1 .5
float roughness 0 1 .5
float specularTint 0 1 0
float anisotropic 0 1 0
float sheen 0 1 0
float sheenTint 0 1 .5
float clearcoat 0 1 0
float clearcoatGloss 0 1 1

| Input Format
| ------------------------------------- |
| ![](results/DisneyBRDF/jsonInput.png) |

GUI allowing for dynamically changing parameters:

| GUI |
| ------------------------------- |
| ![](results/DisneyBRDF/GUI.png) |

A brief demo illustrates the usage:

https://github.com/user-attachments/assets/62e0fcce-20bc-49f6-b9c6-eea6904767dc

# Direct Lighting & Multi-Importance Sampling

Consider the following 2 scenarios:

1. When light is very small in size
2. When we want to implement point light/directional light/spot light

When light is small in size, it is less likely for a diffused BRDF to gather meaningful light contribution.
Therefore, each time when a ray hits a surface, we can consider sampling radiance directly from a light in the scene.
This way of calculating radiance contribution is called direct lighting.

The direct radiance from different sample point:

| Direct Lighting Radiance | Accumulative Color (depth = 1) |
| ------------------------------- | ------------------------------- |
| ![](results/MIS/DIRadiance.png) | ![](results/MIS/accumColor.png) |

But direct lighting behaves poorly when sampling from a large area light.

Veach Scene:

| BSDF Lighting | Direct Lighting | MIS Lighting |
| ---------------------------- | -------------------------- | ----------------------------- |
| ![](results/MIS/MISBSDF.png) | ![](results/MIS/MISDI.png) | ![](results/MIS/MISVeach.png) |

So a good practice might be to combine the two method, which is the main idea of Multi-Importance Sampling. To ensure energy-conserving contribution, we use Power Heuristic to calculate the appropriate weight for the directional light radiance.

Also by having an additional directional light contribution, we can acchieve a faster convergence. In order to make a correct contribution to our final color. At each bounce, multiply the sampled radiance with corresponding throughput (radiance `*` accumThroughput `*` BSDF(wo, wdirect)).

Some results:

| MIS On | MIS Off |
| -------------------------- | --------------------------- |
| ![](results/MIS/MISOn.png) | ![](results/MIS/MISOff.png) |

### Tone Mapping

---

Applying ACES Tone Mapping

| ACES Off | ACES On |
| ----------------------------- | ---------------------------- |
| ![](results/ACES/ACESOff.png) | ![](results/ACES/ACESOn.png) |

### Stocastic AA

---

| AA Off | AA On |
| -------------------------- | ------------------------ |
| ![](results//beforeAA.png) | ![](results/afterAA.png) |

### Denoiser (Intel® Open Image Denoise)

---

| Denoiser Off | Denoiser On |
| ------------------------------------- | --------------------------------------- |
| ![](results/Cover/CoverNoDenoise.png) | ![](results/Cover/CoverDenoisedMIS.png) |
Loading