﻿# Embree intersection filters: candidate callbacks are not unique ordered surface events

Implement Embree intersection filters without counting duplicate candidates as distinct surfaces, modifying inactive lanes or assuming callback data arrives in application-friendly order.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-embree-intersection-filter-duplicate-candidate-events/
Language: en

## Separate filtering from event collection

A ray-intersection filter can implement a cutout or reject a candidate according to application logic. It can also tempt a renderer to count callback invocations as physical surface events. Those are different uses. Before collecting training labels, path statistics or layered geometry, define what an accepted event means and whether the traversal callback provides that guarantee. A callback that looks correct for a single triangle can violate the intended interpretation in a more complex acceleration build.

## Expect documented repeated candidates

The [intersection-filter reference](https://github.com/RenderKit/embree/blob/423865d4a0b7ab6cf9bcf8e5df9cab31bcbfc1c6/doc/src/api/rtcSetGeometryIntersectFilterFunction.md) documents possible repeated primitive-hit callbacks under high build quality and at shared edges. An invocation counter can therefore overcount a surface. If the application needs uniqueness, define a deduplication key scoped to the ray and intended instance context. Do not maintain one global primitive-seen set across unrelated rays, because legitimate observations of the same geometry must remain separate.

## Respect the lane-validity contract

The filter reference describes active masks, packet-oriented input and permitted changes when accepting or rejecting a hit. Work only on valid lanes and preserve inactive components. Access ray and hit data through helpers appropriate to the provided layout, rather than assuming a scalar struct behind every callback. Keeping the callback's transformation within the documented permissions is essential when a renderer changes query width or moves from a scalar diagnostic scene to vectorized execution.

## Preserve the query and backend semantics

The [closest-hit documentation](https://github.com/RenderKit/embree/blob/423865d4a0b7ab6cf9bcf8e5df9cab31bcbfc1c6/doc/src/api/rtcIntersect1.md) defines the enclosing query's result and instance information. Filtering candidates does not by itself turn it into an ordered traversal stream. The [SYCL API guide](https://github.com/RenderKit/embree/blob/423865d4a0b7ab6cf9bcf8e5df9cab31bcbfc1c6/doc/src/api.md) adds device-execution requirements for GPU integrations. Check callback accessibility and supported operations on the selected backend instead of assuming a host function pointer and mutable host state are valid inside device traversal.

## Test edges and repeated instances

Compare ordinary surfaces, a shared edge, a cutout and repeated instances of the same asset under different build settings. Inspect accepted query results separately from callback counts. The guides to [GPU BVH traversal](/journal/learn-gpu-bvh-traversal/) and [dataset annotation identity](/journal/data-guide-coco-instance-caption-identities/) give related context. A reliable filter preserves query semantics while its diagnostic event collector explicitly handles duplicates, ray identity and instance scope; it does not derive physical counts from incidental callback behavior.
