TECHNOLOGY

Embree ray queries: use closest-hit data and occlusion results for different questions

In this article
THE QUICK TAKE

An occlusion query answers whether an accepted blocker exists; it does not supply the same result contract as a nearest-surface query.

Choose the question before the query

A renderer may need the nearest surface for shading or only a decision about whether a light is blocked. These are different questions. A nearest-hit implementation can return geometry information that a visibility-only test does not need, while a visibility query can terminate without discovering the nearest accepted surface. Specify the required result before optimizing traversal so later shading code does not interpret an early-exit visibility outcome as a complete geometric intersection.

Read the closest-hit result contract

The closest-hit reference describes rtcIntersect1, initialized ray state and the invalid geometry-ID sentinel. On a hit, the query updates hit fields and the ray’s far parameter. On a miss, it leaves the provided data unchanged. Initialize the result sentinel before each intended query rather than allowing a previous hit to survive accidentally and appear to describe a new ray that actually missed.

Interpret occlusion through its own signal

The occlusion reference documents rtcOccluded1 and its negative-infinity far-value signal for a committed blocker. That outcome is not a physical hit distance. Preserve the original shadow-segment bounds separately if later logic needs them. Check initialization of direction, range, mask, time and flags, because an incorrect ray segment or visibility mask can produce a plausible unblocked result without testing the intended path to a light.

Keep accepted blockers distinct from candidates

The occlusion-filter documentation explains acceptance and rejection of candidate hits. Once a hit is committed, occlusion traversal terminates; it is not an interface for gathering successive intersections. A transparent cutout can reject a candidate, but collecting layered surfaces requires a method with the appropriate intersection contract. Do not reuse the occlusion result as though it were a sorted list of object boundaries.

Validate both hit and miss paths

Use a scene with a nearby surface, a farther surface and a masked blocker. Test a fresh miss after a successful hit to reveal stale output state. The guides to GPU BVH traversal and ray coherence provide neighboring context. Correct query selection preserves the distinction between nearest geometry and accepted visibility while allowing the renderer to choose an appropriate execution backend and measure its actual performance.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles