An interactive path tracing sample on Windows using CUDA–OpenGL interop (PBO). It supports:
-
CUDA device path tracing (multi-bounce, GGX specular, cosine / uniform hemisphere sampling, Russian Roulette)
-
Unified scene triangle consolidation and single BVH acceleration structure
-
Direct / Indirect / MIS (Multiple Importance Sampling) lighting modes
-
Runtime ImGui controls (samples per pixel, max depth, lighting mode, importance sampling, Russian Roulette)
-
Procedural scattering of many OBJ models (example: 100 randomized dragons with random color + emission probability)
-
GPU accumulation buffer (progressive refinement / noise reduction)
- Application init: Window → OpenGL → ImGui → GPU PBO → Scene (scatter models)
- Scene collects triangles from all
Modelobjects, builds a single BVH, gathers materials & light triangle indices. - Render loop:
- Detect camera/scene dirty → reset accumulation → rebuild + upload
- CUDA kernel performs per-pixel multi-sample path tracing (Spp)
- Kernel writes to registered PBO; OpenGL updates screen texture
- ImGui overlays control panel
- BRDF:
- Diffuse: Lambert (albedo / π)
- Metallic: GGX microfacet + Smith geometry term + Fresnel Schlick
- Importance Sampling: optional cosine-weighted hemisphere for diffuse
- MIS: combines light sampling and BSDF sampling using power heuristic
- Light handling: all emissive model triangles become light sampling set (area sampling)
- Russian Roulette: after threshold depth, terminate based on max throughput component, energy-conserving
- Accumulation:
accumulated_radiance[pixel] = mix(previous, current, 1/(frame+1))
- RapidOBJ parses arbitrary polygon faces → triangulated by fan method
- Each
Modelcan receive randomizedMaterial+emissionon CPU; emission stored inMaterialGpuduring upload - Emissive test:
glm::dot(emission, emission) > 0marks triangle as light
- Samples Per Pixel (Spp)
- Max Path Depth
- Lighting Mode: Direct / Indirect / MIS
- Diffuse Importance Sampling toggle
- Russian Roulette toggle + start depth
- Camera: FOV / position / yaw / pitch / movement
- Per-model editing: position, rotation, scale, Albedo, Metallic, Emission, dynamic OBJ loading
- Visual Studio 2022 (MSVC x64 toolchain)
- CUDA Toolkit 12.x (compatible with VS)
- CMake >= 3.18
mkdir build
cd build
cmake .. -G "Visual Studio 17 2022" -A x64
cmake --build . --config ReleaseRun after build (inside build/Release/):
./raytracer.exe- Keyboard: W/A/S/D move, Arrow keys rotate, Space up, Shift down, ESC exit
- Any change to camera or scene resets accumulation (re-converge)
- Higher Spp → slower but cleaner; lower Spp → faster but noisier
- CUDA kernel entry:
kernel_path_tracer_impl(inpath_tracer.cu) - Ray tracing loop:
traceRay - Direct lighting sample:
sampleDirectLightingContribution - BVH intersection:
intersectScene+shadowIntersectScene - Importance sampling & GGX:
sampleGGX,cosineSampleHemisphere(inpt_utils.cu) - Scene rebuild/upload:
Scene::buildAndUploadScene
- Texture support (UV + sampler)
- Refraction / transparent dielectric materials
- Advanced MIS (many-light + BSDF hybrid strategies)
- Environment map / HDR sky sampling
- GPU-side BVH building / dynamic updates
- Denoising integration: OIDN / OptiX
- GLFW (Zlib)
- GLM (MIT)
- ImGui (MIT)
- rapidobj (MIT)
- glad (MIT)

