Skip to the content.

CUDA Ray Tracer

English 简体中文

CI Pages License: MIT CUDA C++ CMake

一个基于 CUDA/C++ 的光线追踪器,支持 Blinn-Phong 光照、蒙特卡洛路径追踪、BVH 加速,以及用于 Phong + 单采样 的主光线排序路径。

功能特性

环境要求

构建

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j$(nproc)

运行

# 渲染示例
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

# 光线排序只适用于 Phong + 单采样
build/bin/ray_tracer --scene demo --sort -w 640 -h 480 -s 1 -o sorted.ppm

命令行参数

参数 说明 默认值
-w / -h 图像宽度/高度 800 / 600
-s 每像素采样数 1
-d 最大光线深度,必须 > 0 5
-p 启用路径追踪 关闭
--scene 场景名(demo / cornell / random demo
--sort 启用光线排序,仅支持 Phong + 单采样 关闭
-o 输出 PPM 文件路径 output.ppm

测试

cd build
ctest --output-on-failure

测试二进制位于 build/bin/ 下。

CI 说明

当前 GitHub Actions 会验证:

由于 GitHub 托管 runner 不提供 CUDA 设备,GPU 测试不会在该 CI 中执行。请在有 CUDA GPU 的机器上构建后运行 ctest --output-on-failure

项目结构

├── include/            # 头文件(vec3、ray、camera、geometry、material、BVH 等)
├── src/                # 主入口和场景定义
├── tests/
│   ├── unit/           # 单元测试
│   └── property/       # 属性测试
├── .github/workflows/
├── CMakeLists.txt
└── README.md

说明

License

MIT License