rayQueryGetIntersectionCandidateAABBOpaqueEXT in GLSL
In Vulkan ray tracing using the GL_EXT_ray_query
extension, rayQueryGetIntersectionCandidateAABBOpaqueEXT is
a GLSL function that determines whether a candidate Axis-Aligned
Bounding Box (AABB) intersection is classified as opaque. When
evaluating procedural geometry during ray query traversal, this function
queries the resolved opacity state of the candidate AABB, allowing
developers to execute conditional custom intersection algorithms and
optimize traversal logic based on geometry and ray flags.
How Opacity is Resolved
The function returns a boolean value (true for opaque,
false for non-opaque). Opacity is not solely determined by
the acceleration structure; it is dynamically resolved at runtime by
evaluating several combined states:
- Geometry Flags: The presence of
VkGeometryFlagBitsKHRflags, such asVK_GEOMETRY_OPAQUE_BIT_KHRorVK_GEOMETRY_NO_DUPLICATE_ANY_HIT_INVOCATION_BIT_KHR, set when building the bottom-level acceleration structure (BLAS). - Instance Flags: Flags specified in the top-level
acceleration structure (TLAS) instance, such as
VK_GEOMETRY_INSTANCE_FORCE_OPAQUE_BIT_KHRorVK_GEOMETRY_INSTANCE_FORCE_NO_OPAQUE_BIT_KHR. - Ray Flags: Flags provided when initializing the ray
query in GLSL via
rayQueryInitializeEXT, such asgl_RayFlagsOpaqueEXTorgl_RayFlagsNoOpaqueEXT.
If ray flags or instance flags override the underlying geometry
properties, rayQueryGetIntersectionCandidateAABBOpaqueEXT
reflects the final overridden state.
Role in Procedural Ray Queries
Procedural primitives are represented in acceleration structures by
bounding boxes rather than explicit triangles. When a ray intersects an
AABB, traversal pauses, setting the candidate type to
gl_RayQueryCandidateIntersectionAABBEXT. At this stage, the
hardware leaves the mathematical hit evaluation to the shader.
Calling rayQueryGetIntersectionCandidateAABBOpaqueEXT at
this candidate stage has direct practical effects on how the shader
handles the hit:
- Conditional Intersection Testing: Shaders can branch on this value to execute different hit-testing complexity. For instance, an opaque candidate might trigger a fast analytic intersection test, whereas a non-opaque candidate might require evaluating procedural noise, volumetric density, or alpha textures.
- Traversal Control: If an AABB candidate is opaque
and the ray flags specify termination on the first hit (such as shadow
rays using
gl_RayFlagsTerminateOnFirstHitEXT), confirming an intersection withrayQueryGenerateIntersectionEXTimmediately commits the hit and can stop traversal early. - Hit Confirmation Logic: Ray queries require the application to explicitly report hits back to the traversal engine. Knowing the opacity allows the application to mirror the behavior of dedicated ray tracing pipelines (where intersection and any-hit shaders interact based on opacity) entirely within a compute or fragment shader workflow.