How ignoreIntersectionEXT Works in GLSL Ray Tracing
In Vulkan ray tracing using GLSL via the
GL_EXT_ray_tracing extension, the
ignoreIntersectionEXT() intrinsic function allows any-hit
shaders to dynamically discard candidate ray-primitive intersections.
Rather than registering a hit and potentially shortening the ray, this
command rejects the current candidate and immediately commands the ray
tracing hardware or driver to resume spatial traversal. This mechanism
is essential for rendering transparent or cutout materials, such as
foliage and chain-link fences, where geometric boundaries do not
strictly match surface opacity.
Role in the Any-Hit Shader
The any-hit shader is invoked whenever a ray's bounding-box traversal
detects a potential intersection with a primitive. Under default
behavior, an intersection is automatically committed when the any-hit
shader execution finishes, updating the ray's maximum traversal distance
(gl_RayTmaxEXT) to the candidate hit distance
(gl_HitTEXT).
Calling ignoreIntersectionEXT() intercepts this default
acceptance. It acts as an early rejection signal, informing the ray
tracing engine that the surface point is transparent or
non-blocking.
Execution Flow and Ray Traversal Resumption
When ignoreIntersectionEXT() is invoked:
- Shader Execution Halts: The current invocation of the any-hit shader terminates immediately. Any code placed after the call within the shader will not be executed.
- Hit Discard: The ray tracing pipeline discards the
candidate hit. The candidate distance is ignored, meaning
gl_RayTmaxEXTis not updated and remains at its previous value. - Traversal Continuation: The ray continues traversing the acceleration structure along its original path and direction. It will test further bounding volumes and primitives beyond the rejected intersection point.
- Closest-Hit Preservation: Because the candidate hit is discarded, it does not overwrite the closest committed intersection found so far, nor does it trigger the closest-hit shader.
Typical Implementation
The most common application is texture-based alpha testing. The shader samples a texture map at the hit's UV coordinates; if the alpha value falls below a defined cutoff threshold, the intersection is ignored:
#version 460
#extension GL_EXT_ray_tracing : require
hitAttributeEXT vec2 attribs;
layout(binding = 0) uniform sampler2D alphaMask;
void main() {
vec2 uv = computeUV(attribs);
float alpha = texture(alphaMask, uv).r;
if (alpha < 0.5) {
ignoreIntersectionEXT();
}
}If the alpha condition evaluates to true,
ignoreIntersectionEXT() drops the hit completely, ensuring
that shadow rays pass straight through transparent regions and primary
rays search for geometry behind the cutout.