How ignoreIntersectionEXT Works in GLSL Any-Hit Shaders

In hardware-accelerated ray tracing pipelines using GLSL and Vulkan, the ignoreIntersectionEXT function allows an any-hit shader to reject a candidate intersection and immediately resume ray traversal. This article explores how ignoreIntersectionEXT functions under the hood, how it alters the ray-tracing hardware state by preventing updates to the closest hit distance, and how it differs from other ray termination intrinsics during traversal.

Ray Traversal and the Any-Hit Stage

When a ray intersects a primitive—such as a triangle—in an acceleration structure, the ray tracing hardware pauses traversal to determine if the hit is valid. If an any-hit shader is bound to that geometry and the instance does not force opaque handling, the pipeline invokes the any-hit shader for that candidate hit point.

At this stage, the intersection is tentative. It has not yet been committed as the accepted closest hit or an accepted occlusion hit.

Mechanics of ignoreIntersectionEXT

Calling ignoreIntersectionEXT() triggers two immediate effects:

  1. Immediate Execution Termination: The function acts as an exit instruction. The current invocation of the any-hit shader is terminated instantly; no subsequent shader instructions or cleanup code following the call will execute.
  2. Hit Rejection in the Traversal Unit: The hardware's fixed-function traversal unit is notified to discard the candidate intersection.

Under normal circumstances, an accepted intersection updates the ray's maximum traversal distance (\(t_{max}\) or gl_RayTmaxEXT) to the candidate's parametric distance (\(t\)), effectively shortening the ray for subsequent intersection tests. When ignoreIntersectionEXT() is called, this update is bypassed. The traversal unit discards the candidate distance, retains the existing \(t_{max}\), and resumes traversing the acceleration structure along the ray's original path to find subsequent intersections.

Primary Use Cases

The most common application of ignoreIntersectionEXT is alpha testing or cutout transparency:

  • Alpha Masking: The shader samples a texture map at the hit's UV coordinates. If the alpha value falls below a defined cutoff threshold, the shader executes ignoreIntersectionEXT(). The ray passes through the transparent portions of the geometry as if no geometry were present.
  • Custom Geometric Filtering: It can be used to dynamically filter out specific primitives or instances based on custom per-primitive data without rebuilding the acceleration structure.

Comparison with terminateRayEXT

It is essential to distinguish ignoreIntersectionEXT() from terminateRayEXT():

  • ignoreIntersectionEXT() rejects the current candidate hit and commands the traversal hardware to keep searching for other intersections along the ray.
  • terminateRayEXT() immediately halts the entire ray traversal process. When used without ignoring the hit, it commits the current intersection and stops searching for further hits, which is typically used to optimize shadow and ambient occlusion rays (any-hit confirmation).

If ignoreIntersectionEXT() is called, the ray continues traversal until it either finds another valid intersection, reaches its maximum range, or is explicitly terminated.