English | 简体中文
A CUDA/C++ ray tracer with Blinn-Phong shading, Monte Carlo path tracing, BVH acceleration, and an optional primary-ray sorting path for Phong single-sample renders.
- Blinn-Phong Shading — Ambient, diffuse, specular lighting with multi-light support
- Path Tracing — Monte Carlo global illumination with Russian roulette termination
- BVH Acceleration — Bounding Volume Hierarchy for faster sphere intersection queries
- Ray Sorting — Group primary rays by hit object ID in Phong single-sample mode
- Tone Mapping — Reinhard output path, plus an ACES helper available in code/tests
- Multiple Scenes — Demo, Cornell Box, and random sphere scenes
- Tests — Unit and property tests for math, scene construction, sorting, and helper logic
- CUDA Toolkit 11.0+
- CMake 3.18+
- C++17
- NVIDIA GPU with Compute Capability 7.5+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j$(nproc)# Render scenes
build/bin/ray_tracer -w 800 -h 600 -s 1 --scene demo -o output.ppm
build/bin/ray_tracer -w 640 -h 480 -s 16 -d 5 -p --scene cornell -o cornell.ppm
# Ray sorting only applies to Phong + single sample
build/bin/ray_tracer --scene demo --sort -w 640 -h 480 -s 1 -o sorted.ppm| Flag | Description | Default |
|---|---|---|
-w / -h |
Image width/height | 800 / 600 |
-s |
Samples per pixel | 1 |
-d |
Max ray depth, must be > 0 | 5 |
-p |
Enable path tracing | Off |
--scene |
Scene name (demo / cornell / random) |
demo |
--sort |
Enable ray sorting for Phong + single sample only | Off |
-o |
Output PPM file | output.ppm |
cd build
ctest --output-on-failureDirect test binaries are emitted under build/bin/.
GitHub Actions currently verifies:
- configure/build
- formatting via the repository
.clang-format
GPU-backed tests are not run on GitHub-hosted runners because they do not expose CUDA devices. Run ctest --output-on-failure on a CUDA-capable machine after building.
├── include/ # Headers (vec3, ray, camera, geometry, material, BVH, ...)
├── src/ # Main entry + scene definitions
├── tests/
│ ├── unit/ # Unit tests
│ └── property/ # Property tests
├── .github/workflows/
├── CMakeLists.txt
└── README.md
- The path tracer no longer treats ordinary material ambient terms as emission.
- Scene factory helpers reset the builder/output vectors on each call, so reusing a
SceneBuilderis safe. Rendererreports render time separately from optional sort-analysis time.
MIT License