TraceRay function

Sends a ray into a search for hits in an acceleration structure.


This intrinsic function definition is equivalent to the following function template:

void TraceRay(RaytracingAccelerationStructure AccelerationStructure,
              uint RayFlags,
              uint InstanceInclusionMask,
              uint RayContributionToHitGroupIndex,
              uint MultiplierForGeometryContributionToHitGroupIndex,
              uint MissShaderIndex,
              RayDesc Ray,
              inout payload_t Payload);



The top-level acceleration structure to use. Specifying a NULL acceleration structure forces a miss.


Valid combination of ray_flag values. Only defined ray flags are propagated by the system, i.e. are visible to the RayFlags shader intrinsic.


An unsigned integer, the bottom 8 bits of which are used to include or reject geometry instances based on the InstanceMask in each instance. For example:

if(!((InstanceInclusionMask & InstanceMask) & 0xff)) { //ignore intersection }


An unsigned integer specifying the offset to add into addressing calculations within shader tables for hit group indexing. Only the bottom 4 bits of this value are used.


An unsigned integer specifying the stride to multiply by GeometryContributionToHitGroupIndex, which is just the 0 based index the geometry was supplied by the app into its bottom-level acceleration structure. Only the bottom 16 bits of this multiplier value are used.


An unsigned integer specifying the index of the miss shader within a shader table.


A RayDesc representing the ray to be traced.


A user defined ray payload accessed both for both input and output by shaders invoked during raytracing. After TraceRay completes, the caller can access the payload as well.

Return Value



This function can be called from the following raytracing shader types:

See also

Direct3D 12 Raytracing HLSL Reference