OptiX-7入门教程

article/2025/11/9 13:12:44

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!


http://chatgpt.dhexx.cn/article/rkQL0o3r.shtml

相关文章

optix入门

射线追踪是embarrassingly parallel/perfectly parallel/pleasingly parallel的问题,就是说基本不用费劲就可以并行化。 射线追踪是指从某点发射射线,判断其与几何结构的交点,根据交点对图像进行渲染,或者计算。 nvidia optix是基…

jwt *

目录 一、jwt出现的原因及工作原理 1. JWT是什么 2. 为什么使用JWT 3. JWT的工作原理 4、jwt解决不需要登录就能直接访问的问题: 解决登录后树形菜单未出现的问题 : 二、jwt工具类介绍,三种场景 1、jwt工具类 2、三种场景 三、jwt…

JWT JWT

JWT(JSON WEB TOKEN) JWT的组成 header(头部):中主要存储了两个字段 alg,typ。 alg表示加密的算法默认(HMAC SHA256),typ表示这个令牌的类型默认为JWT。 payload&#…

JWT__

文章目录 JWT什么是JWT?JWT能做什么?认证流程JWT的结构是什么?使用代码要做一个JWT的例子引入pom依赖生成一个Token令牌验证令牌并从令牌中取出信息 JWT 什么是JWT? 官网地址:https://jwt.io/introduction/ 官方文档 JSON Web T…

JWT 和 JJWT 还傻傻的分不清吗

JWTs是JSON对象的编码表示。JSON对象由零或多个名称/值对组成,其中名称为字符串,值为任意JSON值。 JWT有助于在clear(例如在URL中)发送这样的信息,可以被信任为不可读(即加密的)、不可修改的(即签名)和URL - safe(即Base64编码的)。 JSON W…

【编码实战】2022年还在用jjwt操作jwt?,推荐你使用nimbus-jose-jwt,爽到飞起~

什么是nimbus-jose-jwt? nimbus-jose-jwt是基于Apache2.0开源协议的JWT开源库,支持所有的签名(JWS)和加密(JWE)算法。 对于JWT、JWS、JWE介绍 JWT是一种规范,它强调了两个组织之间传递安全的信息JWS是JWT的一种实现,包含三部分hea…

什么是JWT??

一、什么是JWT JWT(JSON WEB TOKEN),通过数字签名的方式,以json对象为载体,在不同的服务终端之间安全的传输信息,用来解决传统session的弊端。 JWT在前后端分离系统,或跨平台系统中,通过JSON形式作为WEB应用…

JJWT实现令牌Token

登录实现方式 Session 详情: https://www.cnblogs.com/andy-zhou/p/5360107.html 会话的概念 会话就好比打电话,一次通话可以理解为一次会话。我们登录一个网站,在一个网站上不同的页面浏览,最后退出这个网站,也是…

3.JJWT

目录 1.JWT简介 2.JWT的结构 3.基于服务器的传统身份认证 4.基于token的身份认证 5. JWT的优势 6.Java中使用JJWT实现JWT 1.JWT简介 Json web token (JWT), 是为了在网络应用环境间传递声明而执行的一种基于JSON的开放标准(RFC 7519)。该token被设计为紧凑且安全的…

JWT技术

JWT 一、 JWT 实现无状态 Web 服务 1、什么是有状态 有状态服务,即服务端需要记录每次会话的客户端信息,从而识别客户端身份,根据用户身份进行请求的处理,典型的设计如tomcat中的session。 例如登录:用户登录后&am…

token学习笔记(JWT、jjwt的使用及案例实现)

文章目录 1. 首先、了解什么是会话2. 会话跟踪的主要技术3. Token 令牌学习3.1 流程图3.2 token3.3 JWT(JSON web Tokens)Json web 令牌(规范)3.4 JWT结构3.5 JWT需要的依赖3.6 JWT的获取与验证流程3.7JWT的使用方式3.8 jjwt的使用(创建JWT方式)1. jjwt需…

JWT 进阶 -- JJWT

###jwt是什么? JWTs是JSON对象的编码表示。JSON对象由零或多个名称/值对组成,其中名称为字符串,值为任意JSON值。JWT有助于在clear(例如在URL中)发送这样的信息,可以被信任为不可读(即加密的)、不可修改的(即签名)和URL - safe(即Base64编码…

JWT详解和使用(jjwt)

JWT详解和使用 JWT是啥 JWT(JSON Web Token)是一个开放标准(RFC 7519),它定义了一种紧凑的、自包含的方式,用于作为JSON对象在各方之间安全地传输信息。该信息可以被验证和信任,因为它是数字签名的。 下列场景中使用…

JJWT 实现JWT

1什么是JJWT JJWT 是一个提供端到端的 JWT 创建和验证的 Java 库。永远免费和开源 (Apache License,版本2.0),JJWT 很容易使用和理解。它被设计成一个以建筑为中心的流畅界面,隐藏了它的大部分复杂性。 2JJWT快速入门 2.1token的创建 2.1…

什么是JWT?

在HTTP接口调用的时候,服务端经常需要对调用方做认证,以保证安全性。一种常见的认证方式是使用JWT(Json Web Token),采用这种方式时,经常在header传入一个authorization字段,值为对应的jwt_token,或者也有图…

JWT的学习和JJWT的使用

1.什么是JWT JWT(JSON Web Token)是一个开放的行业标准,它定义了一种简介的,自包含的协议格式,用于在通信双方传递json对象,传递的信息经过数字签名可以被验证和信任。JWT可以使用HMAC算法或者使用RSA的公…

JWT详解

本文从本人博客搬运,原文格式更加美观,可以移步原文阅读:JWT详解 JWT简介 1.什么是JWT 在介绍JWT之前,我们先来回顾一下利用token进行用户身份验证的流程: 客户端使用用户名和密码请求登录服务端收到请求&#xff…

JWT详解、JJWT使用、token 令牌

前言 在正式讲解JWT之前,我们先重温一下用户身份认证相关的一些概念: 有状态登录(session认证) 服务器当中记录每一次的登录信息,从而根据客户端发送的数据来判断登录过来的用户是否合法。 缺点: 每个用…

Java的JJWT实现JWT

1 什么是 JJWT JJWT 是一个提供端到端的 JWT 创建和验证的 Java 库。永远免费和开源 (Apache License,版本2.0),JJWT 很容易使用和理解。它被设计成一个以建筑为中心的流畅界面,隐藏了它的大部分复杂性。 2 token 的创建 2.1 引入依赖 &l…

解决Red Hat虚拟机与主机网络不通

虚拟机版本:Red Hat Enterprise Linux 7 64 位 安装:自定义安装,带GUI的服务器,创建图形化界面 创建完毕后发现网络ping不通,经过查阅各种资料,在同事的帮助下终于解决。做一个记录。 1、VMware网络配置。…