OptiX-7入门教程

OptiX是英伟达专为光线追踪打造的SDK,但是他的官方案例都比较复杂,包含了大量初始化相关的代码,初学容易一头雾水。

本人跟着Github上的optiX7course一步步学习才算入门。这个课程是Siggraph 2019/2020上的OptiX课程,有源码,有PDF讲义,通过12个案例逐步搭建起optiX的框架,非常适合初学者。

考虑到国内访问Github速度较慢,我已将课程相关全部资料移植到Gitee和百度云。

【国内版】课程代码

【国内版】课程讲义+测试数据,提取码:kadz

Examples Overview

Example 1: Hello World

This is simplest example, that only initializes the OptiX Library, prints "hello world", and exits. It's pretty much testing only whether your SDK, driver, and PATH/LD_LIBRARY_PATH are properly set up to build, link, and run this tutorial.

This is how this should look like in Linux: Example 1 Linux output

And here, in Windows: Example 1 Linux output

Note: if you do not see this output file, you may have a driver that does not work properly with OptiX 7 or some other cause. Normally the console window will disappear before you can see the error. To run and see the console window's messages, use the Visual Studio option "Start Without Debugging" (or hit Ctrl+F5), which will keep the console window visible after exit. The other option (or for Linux) is to run the program in a console window, e.g., run build\Debug\ex01_helloOptix.exe

Example 2: First Pipeline Setup and Raygen Program

This is the first "real" OptiX example, and maybe somewhat surprisingly, the biggest "step" in all the examples.

The actual raygen program that this example launches is actually very (!) small, and pretty much trivial; and there are no other programs, not even geometry, nor a single ray being traced ... but to launch this simple raygen program we nevertheless have to go through the entire process of creating Modules, Programs, and, in particular, a valid "Shader Binding Table" (SBT), before we can launch our little raygen sample.

On the upside: Once this initial setup is done, everything will get much simpler in the following examples.

PNG file generated by Example 2

Example 3: Rendering in a GLFW Window

Rendering to files is nice and well, but probably you want to eventually do some online rendering; so this example moves the previous raygen example into a 3D viewer window (created and run using GLFW). For now this viewer just displays the rendered images, with no user interaction.

Same Raygen example, in GLFL Window (Linux) Same Raygen example, in GLFL Window (Windows)

Example 4: Creating a first Triangle Mesh and Accel Struct

Though the previous setup steps were important to get right, eventually you want to use a ray tracer to trace some real rays against some real geometry.

This example introduces how to create some Triangle Mesh Geometry (in this example, two simple, hardcoded, cubes), how to build an Acceleration Structure over this "BuildInput", and how to trace rays against it. To do this we also need to introduce a simple camera model.

First Triangle Mesh and Accel Struct

Example 5: First Shader Binding Table (SBT) Data

The earlier examples created an SBT (they had to, else they couldn't have executed any OptiX launch), but didn't actually put any data into the SBT. This example introduces how to do that, by putting just some simple constant per-object color into the mesh's SBT entry, then shading it based on the surface normal's angle to the view ray.

First SBT Data

Example 6: Multiple Triangle Meshes

This example introduces the concept of having multiple different meshes (each with their own programs and SBT data) into the same accel structure. Whereas the previous example used two (same color) cubes in one triangle mesh, this example split this test scene into two meshes with one cube (and one color) each.

Multiple Triangle Meshes

Example 7: First Real Model

This example takes the previous "multiple meshes" code unmodified, but introduces a simple OBJ file format parser (using Syoyo Fuyita's tinyobj, and hooks the resulting triangle meshes up to the previous example's render code.

For this example, you must download the Crytek Sponza model and unzip it to the (non-existent, until you create it) subdirectory optix7course/models.

And la-voila, with exactly the same render code from Sample 6, it suddenly starts to take shape:

First Real Model: Sponza

Example 8: Adding Textures via CUDA Texture Objects

This example shows how to create and set up CUDA texture objects on the host, with the host passing those to the device via the SBT, and how to use those texture objects on the device. This one will take a bit of time to load in Debug - it's worth the wait! Or simply build and run in Release.

Example 9: Adding a second ray type: Shadows

This is the last example that focuses on host-side setup, in this case adding a second ray type (for shadow rays), which also requires changing the way the SBT is being built.

This sample also shows how to shoot secondary rays (the shadow rays) in device programs, how to use an any-hit program for the shadow rays, how to call optixTerminateRay from within an any-hit program, and how to use the optixTrace call's SBT index/offset values to specify the ray type.

Example 10: Soft Shadows

Whereas the first 9 examples focused on how to perform all the required host-side setup for various incremental features, this example can now start to focus more on the "ray tracing 101" style additions that focus what rays to trace to add certain rendering effects.

This simple example intentionally only adds soft shadows from area lights, but extending this to add reflections, refraction, diffuse bounces, better material models/BRDFs, etc., should from now on be straightforward.

Please feel free to play with adding these examples ... and share what you did!

Example 11: Simple Denoising (LDR, color only)

This example takes the code from the previous example and simply runs the optix denoiser on the final frame (ie, color) buffer computed by this optix launch. It does not store any albedo or normal buffers, not compute HDR intensity, etc.

To fully see the impact of denoising without progressive resampling, feel free to turn denoising and/or progressive refinemnt on and off via the 'd' (denoising) and 'a' (accumulate) keys.

Example 11, single sample per pixel, no denoising: 

The same, with denoiser turned on: 

Example 12: Denoising with HDR and separate Normal Channel

This example improves on the simple denoising by computing a separate normal buffer (which improves the denoiser quality), and by doing denoising in HDR, with an added gamma pass after denoising.

As with example 11, to fully see the impact of denoising without progressive resampling, feel free to turn denoising and/or progressive refinemnt on and off via the 'd' (denoising) and 'a' (accumulate) keys.

Example 12, single sample per pixel, no denoising: 

The same, with denoiser turned on: 

Example 13: It's up to you ...

From here on, there are multiple different avenues of how to add to this simple viewer, in terms of visual features, performance, kind and complexity of geometry, etc. In no particular order, and just to serve as inspiration:

  • Performance
    • Multi-GPU
    • Denoising
    • Better random numbers, better sampling, importance sampling, ...
    • ...
  • Shading Effects
    • More/better light sources (eventually with importance sampling for multiple lights!)
    • Better camera model, with depth of field
    • Alpha/Transparency Textures for Cut-outs (Tip: often used in landscape scenes)
    • Better material model / BRDF
    • Indirect Illumination / path tracing
    • ...
  • Geometry-related Capabilities
    • Instancing, possibly multi-level instancing
    • Animation
    • Motion Blur
    • ...
  • Viewer/app extensions
    • Camera motion based on user input
    • More importers (PBRT parser?)
    • Picking and editing
    • ...

Whichever of these - or other - features you might want to play around with: Let me know how it works out ... and have fun doing it!

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Optix SDK 下载 4.1 . 1 Optix 4 现在 自由 使用 在 任何 应用 , 包括 商业 和 教育 应用 。 为 下载 你 必须 NVIDIA 这些 显影剂 - 。 通过 点击 "Agree & Download"按钮 , 确认 您 已 阅读 并 同意 遵守 软件 开发者 套件 、 采样 工具 和 许可 协议 用于 封装 的 SDK 使用 。 下载 将 开始 后 立即 点击 "Agree & Download"按钮 下方 。 Windows 7 和 更 高 、 64 位 同意 & 下载 Linux 接受 & 下载 Mac OSX 10.9 或 更 高 接受 & 下载 版本 说明 ( 615kB , PDF ) 版本 说明 Optix NVIDIA ® ™ 4.1 . 1 ( 2017 年 8 月 ) 欢迎 来到 的 第一个 重大 更新 的 Optix 4 SDK 。 Optix 4 是 发展 中 的 一个 重要 里程碑 Optix , 完全 重新 实现 的 核心 组件 , 包括 一个 全新 的 基于 LLVM 编译 流水线 。 重新 设计 内部 已经 酝酿 了 几年 , 人们 对 更好 的 总体 性能 、 多 GPU 缩放 , 调试 和 配置 、 以及 其他 特性 。 4 版本 保持 向 后 兼容 现有 的 Optix 应用 提供 的 API , 易于 使用 Optix 是 已知 的 。 Optix 4 现在 自由 使用 在 任何 应用 中 , 它 是 私人 或 商业 性质 , 而 无需 任何 额外 许可 或 批文 。 4.1 版本 是 一个 维护 版本 , 提供 性能 和 鲁棒性 的 改进 以及 最近 支持 CUDA 和 Visual Studio 版本 。 改进 4.1 . 1 主机 存储器 使用量 减少 场景 的 几何 形状 的 大量 实例 。 固定 一 臭虫 , 其 原始 索引 偏移 被 忽略 , 如果 一个 仅 包含 单个 geometrygroup geometryinstance 。 把 一 臭虫 固定 在 有 Optix 素数 的 最小 有效 位 的 浮点数 可以 命中 距离 确定性 的 三角形 中 的 一些 场景 , 根据 其 位置 在 BVH 中 。 所有 样品 使用 Optix CUDA SDK 主要 通过 默认 上下文 。 固定 的 场景 时 许多 材料 共享 geometryinstances 。 固定 内存 泄漏 在 GL Interop 破坏 缓冲器 修正 当 CUDA 计算 高速缓存 有时 没有 踢 中 , 导致 长 的 编译 时间 。 架构 更新 安装程序 以 在 安装 时 避免 安全 问题 的 SDK 。 改进 到 4.1 . 0 支持 CUDA 8.0 支持 Visual Studio 2015 年 建立 自己 的 SDK 各种 错误 修复 , 包括 更 坚固 的 节点 处理 复杂 图形 的 变化 在 某些 情况 下 , 内核 性能 更好 Optix 头 现在 nvrtc 兼容 , 与 运输 带 运行 时 编译 库 ( CUDA 阅读 更 多 ) 改进 4.0 . 2 新 的 EULA , 现在 允许 不 受约束 的 在 商业 应用 中 使用 Optix &bra; 黄金 &ket; Optix 和 几个 固定 的 问题 , 导致 使用 时 故障 trbvh 大 场面 修正 了 一个 问题 , 可能 导致 不必要 的 呼叫 重建 或 BVH 时 rtcontextsetentrypointcount rtcontextsetraytypecount 但 不 改变 表达式 的 值 修正 了 一个 问题 , 可能 会 导致 编译 错误 时 使用 的 不同 原子 类型 的 单个 节目 降低 的 存储器 要求 trbvh 当 使用 多个 改进 鲁棒性 Optix 上下文 &bra; 黄金 &ket; 修正 了 一些 在 内存不足 的 情况 下 RT _ 返回 ERROR _ UNKNOWN _ ERROR 代替 RTP 存储器 分配 失败 _ _ _ 改进 4.0 . 1 固定 “ 无效 设备 ” 错误 , 当 运行 在 某些 情况 下 , 在 GPU 帕斯卡 修正 了 某些 修改 可以 触发 断言 节点 图 修正 了 CPU 回退 的 trbvh 修正 了 一个 问题 , 可能 导致 损坏 输出 当 使用 3D 展开 当 使用 固定 的 性能 问题 的 实例 主要 对 Windows Optix 改进 编译 时 启用 Optix 例外 各种 改进 错误 消息 格式 的 半 添加 处理 rtugetsizeforrtfo

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值