一个路径追踪小程序,利用了 CPU 多线程或 CUDA 加速计算。项目最初参考了《GAMES101: 现代计算机图形学入门》的作业7,有大幅度的调整。学习笔记保存于知乎专栏。
A RayTracer, accelerated by C++ multithreading or CUDA.
- CPU : AMD Ryzen 7 6800H with Radeon Graphics
- GPU : NVIDIA GeForce RTX 3060 Laptop GPU
- Config : cornell-box
CPU | CUDA | |
---|---|---|
耗时 | 1 min 49 sec 330 ms | 55 sec 58 ms |
绘制结果 | ![]() |
![]() |
- 基于路径追踪(path tracing)算法迭代求解绘制方程定积分,包括:
- 使用蒙特卡罗方法(Monte Carlo method)计算辐射亮度(radiance)的数学期望;
- 重要性抽样(importance sampling),给定光线入射方向和表面法线方向,根据 BSDF 对光线出射方向进行重要性抽样;
- 多重重要性抽样(multiple importance sampling):
- 按发光物体表面积直接采样光源;
- 按 BSDF 采样光源;
- 俄罗斯轮盘赌(Russian roulette)控制路径追踪深度;
-
朗伯模型(Lambert's model)定义的平滑漫反射(smooth diffuse)材质;
-
Oren–Nayar 反射模型(Oren–Nayar reflectance model)定义的粗糙漫反射(rough diffuse)材质;
-
微表面模型(microfacet model)定义的电介质(dielectric)材质,模仿 mitsuba 相应的材质;
-
微表面模型(microfacet model)定义的导体(conductor)材质,模仿 mitsuba 相应的材质;
-
使用 Kulla 和 Conty 提出的方法,尝试补上微表面模型没有建模的,微表面之间的多重散射;
-
环境映射(environment mapping)
-
凹凸映射(bump mapping)
Following features are available only in archived project.
-
各向同性相函数(Isotropic Phase Function)描述的参与介质,模仿 mitsuba 相应的材质;
-
亨尼-格林斯坦相函数(Henyey-Greenstein Phase Function)描述的参与介质,模仿 mitsuba 相应的材质;
项目使用 vcpkg 进行 C++ 库管理。
necessary :
if enable real-time viewer:
ENABLE_CUDA
: Specifies whether or not enable GPU-accelerated computing.- compile as C++ project and donnot need CUDA SDK if disable.
ENABLE_VIEWER
: Specifies whether or not enable real-time viewer.- no effect if disable GPU-accelerated computing.
Command Format: [--cpu/--gpu/--preview] [--bvh 'bvh type'] [--input 'config path'] [--output 'file path]
Program Option:
--cpu
: use CPU for offline rendering. if not specify specify CPU/CUDA/preview, use CPU.--gpu
: use CUDA for offline rendering, no effect if disbale CUDA when compiling. if not specify specify CPU/CUDA/preview, use CPU.--preview
: use CUDA for real-time rendering, no effect if disbale CUDA when compiling. if not specify specify CPU/CUDA/preview, use CPU.--bvh
: bvh type for ray tracing, available: [linear, normal], default: 'linear'.--input
: read config from mitsuba format xml file, load default config if empty, default: empty.--output
: output path for rendering result, only PNG format, default: 'result.png'.- press 's' key to save when real-time previewing.
- Mitsuba renderer
- 《GAMES101: 现代计算机图形学入门》
- 《GAMES202: 高质量实时渲染》
- 《Accelerated Ray Tracing in One Weekend in CUDA》
Results from 'develop' branch.
- conductor
- rough conductor, without energy compensation
- isotropic rough conductor, without energy compensation
- dielectric
- rough dielectric, without energy compensation
- isotropic rough dielectric, without energy compensation
- thin dielectric
- plastic
- rough plastic
- lte-orb, rough glass, without energy compensation
- lte-orb, silver, without energy compensation
- box
- dragon
- classroom
- dining room