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
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ set(headers
src/intersections.h
src/glslUtility.hpp
src/pathtrace.h
src/env.h
src/scene.h
src/sceneStructs.h
src/utilities.h
src/bvh.hpp
src/texture.h
)

set(sources
Expand All @@ -69,6 +72,10 @@ set(sources
src/interactions.cu
src/scene.cpp
src/utilities.cpp
src/env.cpp
src/env_device.cu
src/bvh.cpp
src/texture.cpp
)

set(imgui_headers
Expand Down
132 changes: 127 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,133 @@ 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)
* Harry Guan
* Tested on: Windows 11, Intel i7-14700 @ 2.10GHz 32GB, NVIDIA T1000 4GB (Moore 100B virtual labs)
* 4 Late days used

### (TODO: Your README)
### Project Overview

*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.
This project implements a GPU-accelerated Monte Carlo path tracer using CUDA, capable of rendering images with global illumination, material properties, and texture mapping. The path tracer supports various geometry types including spheres, cubes, and complex OBJ meshes with multi material support.

|![](img/woody.png)|

#### Technical Implementation

The path tracer is built on a modular architecture:

- **`pathtrace.cu`**: Core path tracing kernels and scene setup
- **`intersections.cu`**: Ray-primitive intersection tests
- **`interactions.cu`**: Material scattering and BSDF evaluation
- **`scene.cpp`**: Scene loading and OBJ parsing with texture support
- **`texture.cpp`**: Image loading and CUDA texture management
- **`bvh.cpp`**: Bounding Volume Hierarchy construction and traversal


### Scene File Format

The path tracer uses JSON format for scene description. Here's the structure:

```json
{
"Materials": {
"diffuse_material": {
"TYPE": "Diffuse",
"RGB": [R, G, B]
},
"emissive_material": {
"TYPE": "Emitting",
"RGB": [R, G, B],
"EMITTANCE": value
},
"specular_material": {
"TYPE": "Specular",
"RGB": [R, G, B]
},
"refractive_material": {
"TYPE": "Refractive",
"RGB": [R, G, B],
"IOR": 1.5
},
"textured_material": {
"TYPE": "Diffuse",
"RGB": [R, G, B],
"TEXTURE": "path/to/texture.png"
}
},
"Camera": {
"RES": [width, height],
"FOVY": field_of_view_degrees,
"ITERATIONS": max_samples_per_pixel,
"DEPTH": max_bounce_depth,
"FILE": output_filename,
"EYE": [x, y, z],
"LOOKAT": [x, y, z],
"UP": [x, y, z]
},
"EnvironmentHDR": "path/to/environment.hdr",
"Objects": [
{
"TYPE": "sphere" or "cube" or "mesh",
"FILE": "path/to/model.obj", // only for mesh type
"TRANS": [x, y, z], // translation
"ROTAT": [x, y, z], // rotation in degrees
"SCALE": [x, y, z], // scale factors
}
]
}
```

### Implementation Features

## Refraction

Refraction simulates light bending at material interfaces using Snell's law and Fresnel equations, creating realistic glass and transparent materials. The implementation handles both entering and exiting material interfaces with proper index of refraction ratios, with Fresnel reflection increases at grazing angles to produce authentic glass appearance with energy conserving light transport.


|![](img/brdf.png)|![](img/reflection.png)|
|:-:|:-:|
|Diffuse Sphere|Specular Sphere|

## Physically-based Depth of field

Physically-based depth-of-field simulates camera focus by jittering rays within an aperture, creating sharp focus on the focal plane and blur for objects outside it. A larger aperture increases the blur, mimicking real-world optics.

|![](img/no_lens.png)|![](img/dof.png)|
|:-:|:-:|

## OBJ Support + Texture Mapping

OBJ loading enables complex models with multiple textures and materials by parsing MTL files and assigning per-triangle material IDs. The implementation automatically loads textures, handles UV coordinate mapping with V-flip correction, and creates materials with proper sRGB to linear conversion during texture loading for physically accurate rendering.

Texture mapping utilizes bilinear filtering through texture objects. The system supports diffuse texture mapping with efficient GPU memory management for high-resolution textures.

![](img/sora.png)

## Environment HDR Lighting

HDR environment mapping provides realistic outdoor lighting by sampling high dynamic range images when rays miss scene geometry. The implementation uses spherical mapping to convert ray directions to UV coordinates and samples the HDR texture, creating natural lighting with proper energy distribution for realistic sky illumination.

![](img/env_map.png)

## Stochastic Antialiasing

Stochastic antialiasing jitters camera rays within each pixel across multiple iterations to produce smooth anti-aliased edges. This removes jagged artifacts and creates realistic edges in the final render.

|![](img/no%20alias.png)|![](img/alias.png)|
|:-:|:-:|
|No Antialiasing|With Antialiasing|


## BVH Acceleration

Bounding Volume Hierarchy acceleration structure optimizes ray-mesh intersections by organizing geometry into hierarchical bounding boxes. The implementation reduces intersection complexity from O(n) to O(log n) for complex meshes, dramatically improving rendering performance for detailed 3D models. Performance wise, a 100k triangle mesh wasn't able to be simulated, but otherwise with BVH on, the 80k triangle was able to be simulated with 0.3 fps

## Russian Roulette Path Termination

Russian Roulette efficiently terminates low-contribution light paths to focus computational resources on high-impact rays. The implementation uses probabilistic termination based on path color intensity, maintaining unbiased rendering while significantly reducing computation time for deep bounces. Performance wise, scenes with 8 bounces and Russian Roulette enabled achieved 1.5x faster rendering compared to scenes without Russian Roulette, while maintaining the same visual quality.


## Bloopers

![](img/blooper1.png)

Loading