Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

93 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPU Path Tracing

一个从零实现、面向教学的 C++17 CPU 基于物理的 路径追踪渲染器,同时也是 Bilibili 公开课 的配套代码仓库。

项目简介 Intro

项目从最基础的Hello World开始,逐步实现 线程池、光线求交、BVH、路径追踪、重要性采样、 微表面模型、光源采样、MIS、环境光照以及光谱路径追踪。

实现上尽量贴近算法本身,少用复杂框架和语言技巧,方便对照原理阅读代码。

功能 Features

  • Binned SAH BVH
  • Anisotropic GGX Microfacet
  • Multiple Importance Sampling
  • Environment Lighting
  • Spectral Path Tracing

画廊 Gallery

各向异性微表面

CPU Path Tracing Anisotropic GGX · Smith Masking-Shadowing · Conductor · Dielectric

多重重要性采样

CPU Path Tracing Light Sampling · BSDF Sampling · MIS

环境光照

CPU Path Tracing Environment Map · Importance Sampling · HDR

光谱路径追踪

CPU Path Tracing Spectral Rendering · Wavelength Sampling · Spectral MIS

公开课 Course

讲次 内容 视频 课件 代码
基础框架
01 课程介绍 视频 PPT Lecture01
02 线程池与胶片 视频 PPT Lecture02
03 自旋锁与并行 for 循环 视频 Lecture03
04 球体与相交测试 视频 PPT Lecture04
05 模型渲染 视频 PPT Lecture05
06 平面与场景 视频 PPT Lecture06
07 材质与极简光追 视频 PPT Lecture07
08 一些代码重构 视频 Lecture08
性能优化与路径追踪
09 性能优化(上):并行优化 视频 PPT Lecture09
10 性能优化(中):高性能 BVH 加速结构 视频 PPT Lecture10
11 性能优化(下):场景管理 视频 Lecture11
12 路径追踪与重要性采样 视频 PPT Lecture12
13 代码勘误与新材质类 视频 Lecture13
14 电介质与导体 视频 PPT Lecture14
微表面、采样与光照
15 往期勘误与代码重构 视频 Lecture15
16 微表面理论 视频 PPT Lecture16
17 实时预览 视频 Lecture17
18 向光源采样 视频 PPT Lecture18
19 多重重要性采样 视频 PPT Lecture19
20 BVH 构建优化 视频 Lecture20
21 环境光照 视频 PPT Lecture21
光谱渲染
22 代码勘误和一些改进 视频 Lecture22
23 光谱渲染(上):色彩科学 视频 PPT Lecture23
24-1 光谱渲染(中):基础框架 视频 PPT Lecture24
24-2 光谱渲染(中)Spectral MIS 视频 PPT Lecture24
25 光谱渲染(下) 制作中

代码构建 Build

获取源码

git clone --recursive https://github.com/HeaoYe/CPUPathTracing.git

下载资源文件

  • 新建models、hdris、spectrums文件夹
  • 下载资源文件
  • 将.obj模型文件放入models文件夹
  • 将.exr贴图文件放入hdris文件夹
  • 将.csv光谱文件放入spectrums文件夹
  • 文件夹结构预览
CPUPathTracing
├── hdris
│   ├── HdrOutdoorSnowMountainsEveningClear001_HDR_4K.exr
│   ├── kloppenheim_07_puresky_4k.exr
│   └── qwantani_night_puresky_4k.exr
├── models
│   ├── buddha.obj
│   ├── dragon_871k.obj
│   ├── dragon_87k.obj
│   └── simple_dragon.obj
├── spectrums
│   ├── Johnson-copper.csv
│   ├── Metameric_A_reflectance.csv
│   ├── Metameric_B_reflectance.csv
│   └── Zelmon-glass.csv
├── resource/
├── source/
├── thirdparty/
├── .vscode/
├── CMakeLists.txt
├── .gitignore
├── .gitmodules
├── README.md
└── LICENSE

编译

cmake -B build
cmake --build build -j 8

运行

./build/source/CPUPathTracing

操作 Controls

程序启动后会进入实时预览界面,可调整相机位置、视角与预览模式。

操作 功能
Enter 开始渲染
Esc 退出预览,不进行渲染
Caps Lock 捕获 / 释放鼠标
W A S D 移动相机
Space / Shift 相机上升 / 下降
鼠标移动 调整相机视角
鼠标滚轮 调整相机 FOV
Tab 切换预览模式
+ / - 调整预览目标 FPS,并自动改变预览分辨率

Tab 可在以下预览模式之间切换:

  • 正常渲染
  • 法线可视化
  • BVH 包围盒相交测试热力图
  • 三角形相交测试热力图

参考资料 References

许可证 License

本项目原创源代码基于 MIT License 开源。

仓库中包含的第三方源代码遵循其各自的原始许可证, 相关版权与许可证声明保留在对应文件中。

resource/ 目录中的内容不包含在 MIT License 的授权范围内。 PPT 中引用的第三方图片及其他材料,其版权归各自权利人所有。

仓库 Release 中提供的模型、HDRI、光谱数据及其他外部资源 不包含在 MIT License 的授权范围内。

About

Educational C++17 CPU path tracer built from scratch, featuring BVH, microfacet materials, MIS, environment lighting, spectral rendering, and an accompanying Bilibili course.

Resources

Stars

63 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages