Search code examples
hlslraytracingdirectx-12

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


I have multiple geometries (D3D12_RAYTRACING_GEOMETRY_DESC) inside of a single DXR bottom level acceleration structure (BLAS). How can I determine which of those was hit inside of a closest hit shader? The following HLSL intrinsics do something different:

  • PrimitiveIndex() returns the triangle index for the current geometry, but it restarts for each new geometry inside of the BLAS, so I don't know which one was hit.
  • InstanceIndex() returns the index of the top level but not of the bottom level
  • InstanceID() again, is only defined for the top level

Solution

  • Starting with D3D12_RAYTRACING_TIER_1_1 there is a new intrinsic called uint GeometryIndex() Specification.