reportIntersectionEXT Parameters in GLSL Explained
This article provides a technical overview of the
reportIntersectionEXT function used in GLSL ray tracing
intersection shaders. It breaks down the intrinsic parameters passed by
the function, explains their roles in determining ray hit distance and
classification, and clarifies how associated custom hit attributes are
committed to internal communication registers for use by subsequent
any-hit and closest-hit shaders.
Function Signature and Direct Parameters
In the GL_EXT_ray_tracing extension for GLSL, the
intersection shader uses the reportIntersectionEXT
intrinsic to signal to the ray tracing pipeline that a ray-primitive
intersection has occurred. The function signature is:
bool reportIntersectionEXT(float hitT, uint hitKind);The function directly takes two input arguments:
float hitT(Parametric Distance): This parameter represents the parametric distance along the ray where the intersection took place. The pipeline checks whetherhitTfalls within the current valid interval defined bygl_RayTminEXTandgl_RayTmaxEXT. If the value lies outside this range, the intersection is automatically discarded.uint hitKind(Hit Type Identifier): This parameter is a user-defined integer identifying the type or category of the intersection. By specification, user-defined values must occupy the lower 7 bits (values ranging from 0 to 127), as higher bits are reserved by the implementation for built-in primitive types. This value is passed down the pipeline and can be read in any-hit and closest-hit shaders via the built-in variablegl_HitKindEXT.
Transferring Data to Hit Attribute Registers
While hitT and hitKind are the only
parameters explicitly passed into the function signature,
reportIntersectionEXT acts as the synchronization point
that commits custom geometry data into the communication registers.
Before invoking reportIntersectionEXT, custom geometry
attributes—such as barycentric coordinates, surface normals, or texture
coordinates—must be written to variables qualified with
hitAttributeEXT:
hitAttributeEXT vec2 customAttributes;
void main() {
// ... intersection testing logic ...
customAttributes = vec2(u, v);
reportIntersectionEXT(t, 0u);
}When reportIntersectionEXT executes, the hardware or
driver copies the contents of these hitAttributeEXT
variables into dedicated attribute communication registers. If the
intersection is accepted, these registers are preserved and made
readable by matching hitAttributeEXT declarations in
downstream any-hit and closest-hit shaders.
Return Value and Pipeline Behavior
The function returns a boolean value indicating the acceptance of the intersection:
true: The intersection was accepted, meaning the any-hit shader (if present) did not callignoreIntersectionEXT(), andhitTbecame the new upper bound (gl_RayTmaxEXT) for subsequent intersection tests.false: The intersection was rejected by either the ray interval bounds or the any-hit shader. In this case, the updated communication registers are discarded, and the previous ray state is maintained.