3

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
Felix Brüll
  • 367
  • 2
  • 13

2 Answers2

4

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

Felix Brüll
  • 367
  • 2
  • 13
2

I am wondering about that as well. Unfortunately, I can't give you a definitive answer but on this page I found the following statement:

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.

So if I understood that correctly, you either have to use a local root table or you have to restrict yourself to only one geometry per bottom level structure.

There is a MultiplierForGeometryContributionToShaderIndex parameter in TraceRay which you can set to 1 to get a different hit group per geometry. If you store a list of materials per hit group, you probably need only one hit group per geometry.

See also RaytracingMiniEngineSample.

George
  • 126
  • 1
  • 4