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
1,119 changes: 560 additions & 559 deletions .gitignore

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ set(GLM_ROOT_DIR "${CMAKE_SOURCE_DIR}/external")
find_package(GLM REQUIRED)
include_directories(${GLM_INCLUDE_DIRS})

# Define OIDN root directory (we point to your actual installed version)
set(OIDN_ROOT "C:/Libraries/oidn-2.3.3.x64.windows")
set(OpenImageDenoise_DIR "${OIDN_ROOT}/lib/cmake/OpenImageDenoise-2.3.3")

find_package(OpenImageDenoise REQUIRED)
if(NOT OpenImageDenoise_FOUND)
message(FATAL_ERROR "OpenImageDenoise not found. Please set OIDN_ROOT correctly.")
endif()
include_directories(${OpenImageDenoise_INCLUDE_DIRS})


set(headers
src/main.h
src/image.h
Expand All @@ -61,6 +72,8 @@ set(headers
src/sceneStructs.h
src/preview.h
src/utilities.h
src/thirdparty/tinyobj_loader/tiny_obj_loader.h
src/thirdparty/oidn-2.3.0.x64.windows/include/OpenImageDenoise/oidn.hpp
)

set(sources
Expand Down Expand Up @@ -123,8 +136,21 @@ endif()
target_link_libraries(${CMAKE_PROJECT_NAME}
${LIBRARIES}
cudadevrt
${OpenImageDenoise_LIBRARIES}
"${OIDN_ROOT}/lib/OpenImageDenoise.lib"
"${OIDN_ROOT}/lib/OpenImageDenoise_core.lib"
#"${OIDN_ROOT}/lib/OpenImageDenoise_device_cuda.lib"
#stream_compaction # TODO: uncomment if using your stream compaction
)

add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${OIDN_ROOT}/bin/OpenImageDenoise.dll"
"${OIDN_ROOT}/bin/OpenImageDenoise_core.dll"
"${OIDN_ROOT}/bin/OpenImageDenoise_device_cuda.dll"
$<TARGET_FILE_DIR:${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})
82 changes: 74 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,79 @@
CUDA Path Tracer
================
# CUDA Path Tracer

**University of Pennsylvania, CIS 565: GPU Programming and Architecture, Project 3**
**University of Pennsylvania, CIS 565: GPU Programming and Architecture, Project 3**
**Author:** Yi Liu

* (TODO) YOUR NAME HERE
* Tested on: (TODO) Windows 22, i7-2222 @ 2.22GHz 22GB, GTX 222 222MB (Moore 2222 Lab)
## Tested On
- **OS:** Windows 11 Home Version 24H2 (OS Build 26100.4061)
- **CPU:** Intel(R) Core(TM) i9-14900K @ 3.20GHz, 24 cores / 32 threads
- **RAM:** 64 GB
- **GPU:** NVIDIA GeForce RTX 4090, 24 GB VRAM
- **Environment:** Visual Studio 2022, CUDA 12.6, CMake 3.27

### (TODO: Your README)
---
## Rendered Results
![Scene1](img/food.png)
![Scene2](img/owl.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.
All the models featured in this path tracer were AI-generated using Meshy, which leverages advanced Image-to-3D and Text-to-3D generation with PBR texture support.

---

## Introduction

This CUDA-based path tracer implements a physically-based rendering system capable of rendering photorealistic images using global illumination. It supports BRDF shading models (diffuse, metallic, dielectric materials), OBJ mesh and texture loading, BVH acceleration, depth of field (DOF), environment lighting, and Intel's Open Image Denoise (OIDN).

---

## BRDF Shading

### Rough Specular Reflection (Glossy)

This render demonstrates rough specular reflection using a microfacet BRDF. Different surface roughness levels cause varying degrees of reflection blur.

![Rough Specular - Metallic](img/cornell_metallic.png)

### Refraction + Reflection (Glass)

This image demonstrates dielectric material behavior with Fresnel reflection and refraction simulated using Schlick's approximation.

![Refraction - Glass](img/cornell_dielectric.png)

---

## Visual Features

### Mesh Loading, Texture Mapping, and Environment Map Lighting

OBJ meshes are parsed using TinyObjLoader, with support for albedo and normal maps via CUDA texture memory. Lighting is provided by an HDR environment map.

![Textured Cake](img/headphones.png)
![Music Box](img/music_box.png)

### Denoising with Intel OIDN

The final image is denoised using Intel Open Image Denoise with support for auxiliary normal and albedo buffers. HDR output is enabled for improved fidelity.

| Raw | Denoised |
|-----|----------|
| ![](img/cornell_bunny_noise.png) | ![](img/cornell_bunny.png) |

---

## Performance Analysis

### Material Sorting

Sorting path segments by material can reduce warp divergence, improving coherence during shading. However, it also introduces sorting overhead.

![Material Sorting FPS](img/material_sorting_analysis.png)

### BVH Acceleration (Bounding Volume Hierarchy)

BVH traversal significantly reduces ray-scene intersection cost. This implementation supports two BVH construction modes:
- **Midpoint Split**: A fast, balanced partitioning approach.
- **Surface Area Heuristic (SAH)**: A cost-optimized method that improves performance in complex geometry by minimizing expected intersection tests.

This flexibility allows users to choose between construction speed and traversal performance based on scene complexity.

![BVH FPS](img/bvh_analysis.png)
Binary file added img/bvh_analysis.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/cake.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/cornell.2025-06-17_10-42-16z.14samp.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/cornell.2025-06-17_10-42-16z.7samp.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/cornell.2025-06-17_11-37-48z.79samp.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/cornell.2025-06-17_11-38-28z.86samp.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/cornell.2025-06-17_11-47-55z.28samp.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/cornell.2025-06-17_11-47-55z.34samp.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/cornell.2025-06-17_11-47-55z.37samp.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/cornell.2025-06-17_11-47-55z.57samp.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/cornell.2025-06-17_15-43-32z.61samp.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/cornell.2025-06-17_18-05-54z.29samp.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/cornell.2025-06-17_18-15-20z.116samp.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/cornell.2025-06-18_19-16-10z.32samp.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/cornell.2025-06-18_22-18-29z.10samp.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/cornell.2025-06-19_17-15-58z.55samp.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/cornell.2025-06-19_22-09-11z.14samp.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/cornell.2025-06-19_22-09-11z.23samp.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/cornell.2025-06-19_22-10-03z.28samp.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/cornell.2025-06-19_22-10-29z.41samp.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/cornell.2025-07-29_02-16-40z.1000samp.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/cornell.2025-07-31_23-47-37z.1000samp.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/cornell_bunny.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/cornell_bunny_noise.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/cornell_dielectric.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/cornell_metallic.png
Binary file added img/food.png
Binary file added img/headphones.png
Binary file added img/materialSort_bug.png
Binary file added img/material_sorting_analysis.png
Binary file added img/music_box.png
Binary file added img/owl.png
134 changes: 77 additions & 57 deletions scenes/cornell.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,51 @@
{
"Materials":
{
"light":
{
"TYPE":"Emitting",
"RGB":[1.0, 1.0, 1.0],
"EMITTANCE":5.0
},
"diffuse_white":
{
"TYPE":"Diffuse",
"RGB":[0.98, 0.98, 0.98]
},
"diffuse_red":
{
"TYPE":"Diffuse",
"RGB":[0.85, 0.35, 0.35]
},
"diffuse_green":
{
"TYPE":"Diffuse",
"RGB":[0.35, 0.85, 0.35]
},
"specular_white":
{
"TYPE":"Specular",
"RGB":[0.98, 0.98, 0.98],
"ROUGHNESS":0.0
}
"Materials": {
"light": {
"TYPE": "Emissive",
"RGB": [ 1.0, 1.0, 1.0 ],
"EMITTANCE": 5.0
},
"diffuse_white": {
"TYPE": "Diffuse",
"RGB": [ 0.98, 0.98, 0.98 ]
},
"diffuse_red": {
"TYPE": "Diffuse",
"RGB": [ 0.85, 0.35, 0.35 ]
},
"Camera":
{
"RES":[800,800],
"FOVY":45.0,
"ITERATIONS":5000,
"DEPTH":8,
"FILE":"cornell",
"EYE":[0.0,5.0,10.5],
"LOOKAT":[0.0,5.0,0.0],
"UP":[0.0,1.0,0.0]
"diffuse_green": {
"TYPE": "Diffuse",
"RGB": [ 0.35, 0.85, 0.35 ]
},
"gold": {
"TYPE": "Metallic",
"RGB": [ 1.0, 0.782, 0.344 ],
"ROUGHNESS": 0.0
},
"glass": {
"TYPE": "Dielectric",
"RGB": [ 1.0, 1.0, 1.0 ],
"IOR": 1.55
},
"glass_yellow": {
"TYPE": "Dielectric",
"RGB": [ 1.0, 1.0, 1.0 ],
"IOR": 1.55
}

},
"Camera": {
"RES": [ 1080, 1080 ],
"FOVY": 45.0,
"ITERATIONS": 500,
"DEPTH": 8,
"FILE": "cornell",
"EYE": [ 0.0, 5.0, 10.5 ],
"LOOKAT": [ 0.0, 5.0, 0.0 ],
"UP": [ 0.0, 1.0, 0.0 ],
"LENS_RADIUS": 0.1,
"FOCAL_DISTANCE": 7.0
},
"Objects":
[
{
Expand All @@ -49,20 +55,20 @@
"ROTAT":[0.0,0.0,0.0],
"SCALE":[3.0,0.3,3.0]
},
{
"TYPE":"cube",
"MATERIAL":"diffuse_white",
"TRANS":[0.0,0.0,0.0],
"ROTAT":[0.0,0.0,0.0],
"SCALE":[10.0,0.01,10.0]
},
{
"TYPE":"cube",
"MATERIAL":"diffuse_white",
"TRANS":[0.0,10.0,0.0],
"ROTAT":[0.0,0.0,90.0],
"SCALE":[0.01,10.0,10.0]
},
{
"TYPE": "cube",
"MATERIAL": "diffuse_white",
"TRANS": [ 0.0, 0.0, 0.0 ],
"ROTAT": [ 0.0, 0.0, 0.0 ],
"SCALE": [ 10.0, 0.01, 10.0 ]
},
{
"TYPE": "cube",
"MATERIAL": "diffuse_white",
"TRANS": [ 0.0, 10.0, 0.0 ],
"ROTAT": [ 0.0, 0.0, 90.0 ],
"SCALE": [ 0.01, 10.0, 10.0 ]
},
{
"TYPE":"cube",
"MATERIAL":"diffuse_white",
Expand All @@ -84,12 +90,26 @@
"ROTAT":[0.0,0.0,0.0],
"SCALE":[0.01,10.0,10.0]
},
{
"TYPE":"cube",
"MATERIAL":"gold",
"TRANS":[0.0, 3.0, 0.0],
"ROTAT":[0.0, 30.0, 0.0],
"SCALE":[2, 2, 2]
},
{
"TYPE":"sphere",
"MATERIAL":"specular_white",
"TRANS":[-1.0,4.0,-1.0],
"MATERIAL":"glass",
"TRANS":[-2.0,6.5,-2],
"ROTAT":[0.0,0.0,0.0],
"SCALE":[3.0,3.0,3.0]
}
"SCALE":[3, 3, 3]
},
{
"TYPE": "sphere",
"MATERIAL": "diffuse_white",
"TRANS": [ 3.0, 1.0, 3.0 ],
"ROTAT": [ 0.0, 40.0, 0.0 ],
"SCALE": [ 3, 3, 3 ]
}
]
}
91 changes: 91 additions & 0 deletions scenes/cornell_bunny.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"Materials": {
"light": {
"TYPE": "Emissive",
"RGB": [ 1.0, 1.0, 1.0 ],
"EMITTANCE": 5.0
},
"diffuse_white": {
"TYPE": "Diffuse",
"RGB": [ 0.98, 0.98, 0.98 ]
},
"diffuse_red": {
"TYPE": "Diffuse",
"RGB": [ 0.85, 0.35, 0.35 ]
},
"diffuse_green": {
"TYPE": "Diffuse",
"RGB": [ 0.35, 0.85, 0.35 ]
},
"dielectric_white": {
"TYPE": "Dielectric",
"RGB": [ 0.6, 0.6, 0.98 ],
"ROUGHNESS": 0.5,
"IOR": 1.55
}
},
"Camera": {
"RES": [ 800, 800 ],
"FOVY": 45.0,
"ITERATIONS": 5000,
"DEPTH": 8,
"FILE": "cornell",
"EYE": [ 0.0, 5.0, 10.5 ],
"LOOKAT": [ 0.0, 5.0, 0.0 ],
"UP": [ 0.0, 1.0, 0.0 ],
"LENS_RADIUS": 0.05,
"FOCAL_DISTANCE": 4.0
},
"Objects": [
{
"TYPE": "cube",
"MATERIAL": "light",
"TRANS": [ 0.0, 10.0, 0.0 ],
"ROTAT": [ 0.0, 0.0, 0.0 ],
"SCALE": [ 3.0, 0.3, 3.0 ]
},
{
"TYPE": "cube",
"MATERIAL": "diffuse_white",
"TRANS": [ 0.0, 0.0, 0.0 ],
"ROTAT": [ 0.0, 0.0, 0.0 ],
"SCALE": [ 10.0, 0.01, 10.0 ]
},
{
"TYPE": "cube",
"MATERIAL": "diffuse_white",
"TRANS": [ 0.0, 10.0, 0.0 ],
"ROTAT": [ 0.0, 0.0, 90.0 ],
"SCALE": [ 0.01, 10.0, 10.0 ]
},
{
"TYPE": "cube",
"MATERIAL": "diffuse_white",
"TRANS": [ 0.0, 5.0, -5.0 ],
"ROTAT": [ 0.0, 90.0, 0.0 ],
"SCALE": [ 0.01, 10.0, 10.0 ]
},
{
"TYPE": "cube",
"MATERIAL": "diffuse_red",
"TRANS": [ -5.0, 5.0, 0.0 ],
"ROTAT": [ 0.0, 0.0, 0.0 ],
"SCALE": [ 0.01, 10.0, 10.0 ]
},
{
"TYPE": "cube",
"MATERIAL": "diffuse_green",
"TRANS": [ 5.0, 5.0, 0.0 ],
"ROTAT": [ 0.0, 0.0, 0.0 ],
"SCALE": [ 0.01, 10.0, 10.0 ]
},
{
"TYPE": "mesh",
"MATERIAL": "dielectric_white",
"FILEPATH": "../scenes/mesh/bunny.obj",
"TRANS": [ 1.0, 1.0, 0.5 ],
"ROTAT": [ 0.0, 0.0, 0.0 ],
"SCALE": [ 1.5, 1.5, 1.5 ]
}
]
}
Loading