BlueRoseNote/03-UnrealEngine/Rendering/RayTracing/RayTracingGEM学习笔记——(1).md
2023-06-29 11:55:02 +08:00

47 lines
1.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: RayTracingGEM学习笔记——(1)
date: 2022-08-09 13:55:15
tags: RayTracing
rating: ⭐️⭐️
---
# RayTracingGEM
## Shader
- RayGeneration Shader是整个DXR可编程管线的入口负责投射光线将光照计算结果返回RenderTarget
- Closest Hit Shader光线与场景最近的有效交点主要用于着色计算
- Miss Shader光线与场景没有交点常用的操作是会去采样天空盒等
- Any Hit Shader可选的任意一次相交都会触发而且不保证触发顺序通常用来做Alpha Test
- Intersection Shader可选的非三角面片的程序化自定义的几何图形与光线的相交判断
使用CS生成样本集。
## Ray
DirectX Raytracing的光线定义如下
```c++
struct RayDesc
{
float3 Origin;
float TMin;
float3 Direction;
float TMax;
};
```
- WorldRayOrigin() WorldRayDirection() RayTMin() RayFlags()
- DispatchRaysIndex()查询光线index。
- DispatchRaysDimensions()查询光线维度。
- RayTCurrent()返回对应状态Hit、Intersection、Miss的Distance
- InstanceID()用户定义的ID
- InstanceIndex() and PrimitiveIndex()系统定义的ID
- ObjectRayDirection() and ObjectRayOrigin()实例空间坐标的Ray数据。
使用TraceRay()进行光线追踪计算。其工作流程如下:
![](https://cdn.jsdelivr.net/gh/blueroseslol/ImageBag@latest/ImageBag/Images/RTGem_TraceRay().png)
DXR还提供了3个额外功能来控制光线与图元相交以及命中Shader的行为。
- ReportHit()设定若干属性返回Ray Hit结果。
- IgnoreHit()在any-hit shader中停止处理当前当前Hit点。
- AcceptHitAndEndSearch()在any-hit shader中接受当前Hit跳过任何未搜索到的加速结构节点。并立即传入closest hit点到closest-hit shader来使用。一般用于简化着色或者光照计算。
###
- 3.8 BASIC DXR INITIALIZATION AND SETUP
76页