DXR:如何在最近的命中着色器中识别底层 AS 的几何实例

DXR: How to identify the geometry instance of the bottom level AS inside the closest hit shader

我在单个 DXR 底层加速结构 (BLAS) 中有多个几何结构 (D3D12_RAYTRACING_GEOMETRY_DESC)。我如何确定其中哪些是在最近的命中着色器中被命中的? 以下 HLSL 内部函数做一些不同的事情:

我也在想这个。不幸的是,我无法给你一个明确的答案,但在 this page 上我发现了以下声明:

Since hit groups need information about the geometry that was hit – its vertex data and material properties – you typically need a local root table for them. To avoid passing data through the local root table, you may also use the instance id field in the top-level instance descriptor and utilize the instance index, which are implicitly available in the hit group shaders. Remember, though, that these values are shared between all geometries in the instance when the bottom level structure contains more than one geometry. To have unique data for each geometry, a local root table must be used.

因此,如果我理解正确的话,您要么必须使用本地根 table,要么必须将自己限制在每个底层结构中仅使用一个几何体。

TraceRay 中有一个 MultiplierForGeometryContributionToShaderIndex 参数,您可以将其设置为 1 以获得每个几何体的不同命中组。如果您为每个命中组存储一个材料列表,则每个几何体可能只需要一个命中组。

另见 RaytracingMiniEngineSample

D3D12_RAYTRACING_TIER_1_1 开始,有一个名为 uint GeometryIndex() Specification 的新内在函数。