A Gentle Introduction to DirectX Raytracing 0

引言

本 DirectX RayTracing 教程在 SIGGRAPH 2018 发布,做一下翻译学习。

What is DirectX Raytracing?

At the 2018 Game Developer’s Conference, Microsoft introduced an addition to DirectX 12 called DirectX Raytracing (DXR), an API allowing easy use of GPU-accelerated ray tracing in DirectX and allowing simple interoperability with traditional DirectX rasterization. Unlike most other GPU-accelerated ray tracing APIs, there are not specialized interoperability considerations to allow a rasterizer and ray tracer to efficiently share GPU resources. Instead, the same resources can easily be reused between rasterization and ray tracing.

在 2018 年游戏开发者大会上,微软推出了 DirectX 12 被称为 DirectX Raytracing (DXR)的新增功能,这是一个允许在DirectX 中轻松使用GPU加速光线追踪的API,并且能够与传统的 DirectX 光栅化进行简单的交互操作。与其他大多数 GPU 加速光线追踪的 API 不同,它不需要特殊的注意事项就能使光栅化器和光线追踪器有效地共享 GPU 资源,这些资源可以在光栅化和光线追踪之间轻松复用。

Additionally, as a Microsoft standard, this should enable writing cross-vendor ray tracers. If your GPU drivers do not support DXR today, Microsoft has a software fallback layer that should work on Windows 10 RS4 using any GPU with Shader Model 6.0 support.

此外,如果您的 GPU 驱动程序目前不支持 DXR,Microsoft 有一个 software fallback layer,该层能够在 Windows 10 RS4 任何支持 Shader Model 6.0 的 GPU 上运行 DXR。

We also presented a SIGGRAPH 2018 course covering the basics in an “Introduction to DirectX Raytracing”. You can find detailed slides and other resources on the course webpage.

我们还提到了 SIGGRAPH 2018课程,涵盖了“入门 DirectX 光线追踪”中的基础知识。您可以在课程网页上找到详细的幻灯片和其他资源。

Impatient to get started? Grab the code and jump to the tutorials walkthrough.

迫不及待地想开始? 获取代码跳转到教程演练。

Resources for Learning Ray Tracing

My goal is not to teach you ray tracing. Instead, I largely assume you understand the basics of ray tracing, e.g., from an introductory graphics text. If you are looking for resources to get you to that stage, some good options include:

我的目标不是教你光线追踪。相反,我在很大程度上假设您了解光线追踪的基础知识,例如从图形学入门读本中(已经了解)。如果您正在寻找资源来帮助您进入该阶段,那么下面是一些不错的选择:

Tutorial Goals

Frequently, when new APIs are released, documentation is accessible and understandable only by experts in the area. This is especially true with modern graphics APIs, like DirectX 12, which operate close to the hardware. These tutorials are explicitly designed to help more naive GPU programmers get a simple ray tracer running quickly and allow for easy experimentation.

通常当发布新的 API 时,只有该领域的专家才能理解文档。对于现代图形 API(如 DirectX 12)尤其如此,它们直接基于硬件运行。这些教程**明确设计用于**帮助对此生疏的 GPU 程序员快速运行简单的光线追踪器,并允许轻松进行尝试。

That means we have highly abstracted the CPU-side, C++ DirectX Raytracing API. If you want to learn the specifics of the host-side API, other tutorials can help you (e.g., the Falcor DXR API tutorials or Microsoft’s DXR SDK). To abstract the API, we use NVIDIA’s Falcor framework, an open-source prototyping infrastructure we built at NVIDIA Research to help improve our research productivity. I added an additional syntactic sugar layer to further simplify the interface.

这意味着我们已经高度抽象了 CPU 端,C++ DirectX Raytracing API。如果您想了解主机端 API 的细节,其他教程可以帮助您(例如 Falcor DXR API教程Microsoft的DXR SDK)。为了抽象 API,我们使用 NVIDIA 的 Falcor 框架,这是我们在 NVIDIA Research 构建的开源原型基础框架,帮助提高我们的研究生产力。我添加了一个额外的语法糖层,以进一步简化界面。

The tutorials build on each other, so each adds only an incremental, easy-to-grasp chunk of code. Our abstraction relies on a simple, modular render pass architecture that localizes changes and simplifies code reuse between tutorials. A resource manager abstracts creation and management of texture resources shared between these modular render passes.

这些教程相互连通,因此每个教程都只添加了一个增量的、易于掌握的代码块。我们的抽象层依赖于一个简单的模块化渲染通道架构,该架构可本地化更改并简化教程之间的代码重用。资源管理器抽象化了在这些模块化渲染通道之间共享的纹理资源的创建和管理。

After finishing the tutorials, you will be able to quickly and easily:

  • Open a window using a DirectX context,
  • Run raster, ray tracing, and compute passes that interact with each other,
  • Load Falcor scene files (ASCII text-based and can include .obj and .fbx files),
  • Generate an easily-customizable G-Buffer using either rasterization or ray tracing,
  • Spawn deferred shading rays from this G-Buffer for hybrid ray-raster rendering,
  • Use traditional ray tracing effects including: ambient occlusion, mirror reflections, shadow rays, and path tracing,
  • Use a simple GGX material model for direct and indirect lighting,
  • Easily add complex camera models introducing depth-of-field,
  • Accumulate samples temporally for generating ground truth ray traced images.
  • Build an interactive version of the final example from Pete Shirley‘s Ray Tracing In One Weekend e-book, which includes intersecting spheres and reflective and refractive materials.

完成教程后,您将能够快速轻松地:

  • 使用 DirectX 打开一个窗口
  • 运行相互作用的栅格、光线追踪和计算管线
  • 加载 Falcor 场景文件(基于 ASCII 文本,也可以包括 .obj 和 .fbx 文件)
  • 使用光栅化或光线追踪生成易于自定义的 G缓冲区
  • 从G缓冲区生成用于混合光线栅格渲染的延迟着色光线
  • 使用传统的光线追踪效果,包括:环境光遮蔽、镜像反射、阴影光线和路径追踪
  • 使用简单的 GGX 材料模型进行直接和间接照明
  • 轻松添加复杂的相机模型并引入景深
  • 暂时累积样本,以生成地面实况射线追踪图像
  • 构建 Pete Shirley《一个周末的光线追踪》电子书中最后一个示例的交互式版本,其中包括相交的球体以及反射和折射材料

Tutorial Requirements

Requirements depend on if you are using a release version of DirectX Raytracing (in Windows 10 RS5 or later) or are using the experimental version of DirectX Raytracing (in Windows 10 RS4). We encourage everyone to develop on RS5 or later, as it removes multiple sources of crypic errors.

配置需求取决于您使用的是 DirectX Raytracing 的发行版(在 Windows 10 RS5 中或更高版本中)还是正在使用 DirectX Raytracing 的实验版本(在 Windows 10 RS4 中)。我们建议每个人在 RS5 或更高版本上进行开发,因为它可以消除多个来源的神秘错误。

For all DirectX Raytracing, you need:

  • A 64-bit version of Windows 10. Check the version by running winver.exe.
    • Version 1803 is Windows 10 RS4.
    • Version 1809 is Windows 10 RS5.
    • Later versions should also work.
  • Visual Studion 2017. Note: the free Visual Studio Community Edition works just fine.
  • A graphics card and driver that support DirectX Raytracing
    • We suggest NVIDIA drivers should be 416.xx and above.

对于所有 DirectX 光线追踪,您需要:

  • 64 位版本的 Windows 10。通过运行 winver.exe 检查版本
    • 版本1803 为 Windows 10 RS4
    • 版本1809 为 Windows 10 RS5
    • 更高版本也应该有效
  • Visual Studion 2017.注意:免费的 Visual Studio 社区版 就足矣
  • 支持 DirectX 光线追踪的图形卡和驱动程序
    • 我们建议 NVIDIA 驱动程序应为 416.xx 及更高版本

For Windows 10 RS5, you also need:

  • Windows 10 SDK 10.0.17763.0 Get it here.
    • Later SDK versions may work, but you need to know how to update the SDK used in Visual Studio.

对于 Windows 10 RS5,您还需要:

  • Windows 10 SDK 10.0.17763.0 在此处获取.
    • 更高的 SDK 版本可能有效,但您需要知道如何更新在 Visual Studio 中使用的 SDK

For Windows 10 RS4, you also need:

  • Windows 10 SDK 10.0.16299.91 Get it here.
    • Later SDK versions may work, but you need to know how to update the SDK used in Visual Studio.
  • Ensure Windows is in Developer Mode. (See PC SettingsUpdate & SecurityFor Developers, and select “Developer mode”)
  • Our RS4 tutorials will only work on NVIDIA Titan V, Quadro GV100, and GeForce RTX cards.

对于 Windows 10 RS4,您还需要:

  • Windows 10 SDK 10.0.16299.91 1 在此处获取.
  • 确保 Windows 处于开发人员模式。(请参阅 PC 设置更新和安全面向开发人员,然后选择”开发人员模式”)
  • 我们的 RS4 教程只适用于 NVIDIA Titan V、Quadro GV100 和 GeForce RTX 卡

(译注:GTX可以运行前两个程序,从 GBuffer 开始会报错设备无法支持光线追踪,所以本教程至少需要一个 RTX 系列的显卡。)

We have not had a chance (or the hardware) to test the software fallback layer on Windows 10 RS5. In theory, these RS5 tuorials run on GPUs without hardware-accelerated ray tracing that support DirectX 12. We will update the information here as time permits. (Please let me know your results if you try running on other hardware.)

我们没有机会(或硬件)在Windows 10 RS5上测试 software fallback layer(译注:软件回退层?)。从理论上讲,这些 RS5 tuorials 也能在没有支持 DirectX 12 的硬件加速光线追踪的 GPU 上运行。如果时间允许,我们将在此处更新信息。(如果您尝试在其他硬件上运行,请让我知道您的结果。)

Getting the Code

You can grab the tutorials:

您可以于此获取教程:

Prebuilt binaries come with all dependencies included (except the GPU, driver, and OS). Please read the README in the binaries package for more details.

预编译的二进制文件包含所有依赖项(GPU、驱动程序和操作系统除外)。有关更多详细信息,请阅读二进制文件包中的自述文件。

Code comes with most dependencies. However, we rely on the open source Falcor framework, which has a number of external dependencies. These are downloaded via a simple script which runs as a build step in Visual Studio (see the README), so your first build may take longer than usual.

代码附带大多数依赖项。但是,我们依赖于开源的 Falcor 框架,它具有许多外部依赖关系。这些都是通过一个简单的脚本下载的,该脚本在 Visual Studio 中作为构建步骤运行(请参阅自述文件),因此您第一次构建项目可能比平时需要更长的时间。

The code for RS4 comes with a custom, precompiled version of Falcor. The code for RS5 comes with a source copy of Falcor 3.1.0, with one tiny update to a build script that copies tutorial shader files correctly during the build.

RS4 的代码带有自定义的预编译版本的 Falcor。RS5 的代码带有 Falcor 3.1.0 的源副本,并对构建脚本进行了一次微小的更新,该脚本在构建过程中正确复制了教程着色器文件。

Tutorial Walkthroughs and Descriptions

Code for all listed tutorials is included in our code bundle. Each page below contains a detailed walkthrough of important aspects for each tutorial:

  • Tutorial 1: Basics. Open a window, and clear it to a user-controllable color.
  • Tutorial 2: Basics. Create a simple raster full screen pass with HLSL pixel shader.
  • Tutorial 3: Basics. Create a rasterization-based G-buffer pass. Render a loaded scene.
  • Tutorial 4: Start using DXR. Create the same G-buffer, this time using DirectX ray tracing.
  • Tutorial 5: Ambient occlusion. Start from G-buffer, trace one AO ray per pixel.
  • Tutorial 6: Accumulate frames over time, giving AO with arbitrarily many rays per pixel.
  • Tutorial 7: Antialiasing. Adds camera jitter to antialias when accumulating temporially.
  • Tutorial 8: Depth-of-field. Add a controllable camera aperture, introducing depth of field.
  • Tutorial 9: Lambertian shading, shooting one shadow ray to each light in the scene.
  • Tutorial 10: Add a light probe environment map for rays that miss the scene geometry.
  • Tutorial 11: Reduce ray count. Shoot shadow ray to only one random light per pixel.
  • Tutorial 12: Add one-bounce diffuse global indirect illumination.
  • Tutorial 13: Apply Falcor’s tonemapper to allow display of high dynamic range outputs.
  • Tutorial 14: Swap out Lambertian for a glossy GGX material, add multiple light bounces.

所有列出的教程的代码都包含在我们的 代码包 中。下面的每个页面都包含每个教程的重要方面的详细解读:

  • 教程 1:基础知识.打开一个窗口,并将其清除为用户可控的颜色
  • 教程 2:基础知识.使用 HLSL 像素着色器创建简单的光栅全屏通道
  • 教程 3:基础知识.创建基于栅格化的 G 缓冲区通道。渲染加载的场景
  • 教程 4:开始使用 DXR。创建相同的 G 缓冲区,这次使用 DirectX 光线追踪
  • 教程 5:环境光遮蔽。从G缓冲区开始,追踪每个像素一条AO射线
  • 教程 6:随时间累积帧,为 AO 提供每像素任意多条光线
  • 教程 7:抗锯齿。在时间累积时将相机抖动添加到抗锯齿中
  • 教程 8:景深。添加可控相机光圈,引入景深
  • 教程 9: Lambertian 着色,向场景中的每盏灯拍摄一条阴影射线
  • 教程 10:为缺少场景几何图形的光线添加光照探针环境贴图
  • 教程 11:减少光线计数。将阴影射线拍摄到每个像素仅一个随机光
  • 教程 12:添加单反弹漫反射全局间接照明
  • 教程 13: 应用 Falcor 的音调映射器以显示高动态范围输出
  • 教程 14:将 Lambertian 换成光亮的 GGX 材质,添加多个光反射