rayQueryConfirmIntersectionEXT in GLSL Ray Queries
The rayQueryConfirmIntersectionEXT function in GLSL is
an intrinsic instruction provided by the GL_EXT_ray_query
extension, primarily designed to validate and record ray intersections
with procedural (custom) primitives. When performing ray queries against
Axis-Aligned Bounding Boxes (AABBs) containing analytical geometry, this
function serves as the definitive mechanism to confirm that a
mathematical intersection occurred within the primitive and to commit
the calculated hit distance back to the traversal engine.
When using ray queries, geometry is separated into
hardware-accelerated triangles and user-defined procedural primitives
enclosed by AABBs. During acceleration structure traversal via
rayQueryProceedEXT, hitting an AABB does not mean the
underlying procedural object was struckāit only indicates that the ray
passed through its bounding volume. When this happens, traversal pauses,
and the ray query state reports a candidate intersection of type
gl_RayQueryCandidateIntersectionAABBEXT.
At this point, the shader is responsible for custom intersection handling:
- Analytical Calculation: The developer must evaluate the intersection between the ray and the procedural object (such as a sphere, cylinder, or implicit surface) using the ray parameters retrieved from the ray query.
- Hit Validation: If the analytical test determines
that the ray misses the actual procedural surface, the shader takes no
action and resumes traversal using
rayQueryProceedEXT. - Hit Confirmation: If the ray successfully strikes
the object within the valid ray segment (between the current minimum and
maximum ray distance,
tMinandtMax), the shader must callrayQueryConfirmIntersectionEXT(rayQuery, hitT).
The primary role of rayQueryConfirmIntersectionEXT is
accepting the calculated distance (hitT) as a confirmed
hit. Calling this function instructs the ray query traversal state
to:
- Update Closest-Hit Distance: If the ray query is
searching for the closest hit, it updates the ray's maximum travel
distance (
tMax) to the providedhitT. Any subsequent candidate intersections farther than this newhitTwill be automatically culled by the traversal hardware. - Commit the Hit: It transitions the intersection status from a pending candidate into a committed intersection, ensuring that the procedural hit is recognized when querying final hit properties after traversal completes.
- Handle Early Termination: For shadow rays or ambient occlusion tests configured to terminate on the first hit, confirming the intersection allows the ray traversal to stop immediately, avoiding redundant traversal steps.
Without calling rayQueryConfirmIntersectionEXT, the ray
query engine assumes the ray traversed the bounding box without striking
any internal geometry, and any custom intersections computed in the
shader are discarded.