RTCSETGEOMETRYINTERSECTFILTERFUNCTION(3embree3)
π rtcSetGeometryIntersectFilterFunction β Embree Ray Tracing Kernels 3, section 3 β¨
okay bestie, sit down, hydrate, because today we're learning how to tell Embree which hits are actually valid. this is rtcSetGeometryIntersectFilterFunction from the Embree Ray Tracing Kernels 3 manual, and it's giving gatekeeper-of-the-hits energy π
πΈ NAME πΈ
rtcSetGeometryIntersectFilterFunction β sets the intersection filter for the geometry π
β¨ SYNOPSIS β¨
#include <embree3/rtcore.h>
struct RTCFilterFunctionNArguments
{
int* valid;
void* geometryUserPtr;
const struct RTCIntersectContext* context;
struct RTCRayN* ray;
struct RTCHitN* hit;
unsigned int N;
};
typedef void (*RTCFilterFunctionN)(
const struct RTCFilterFunctionNArguments* args
);
void rtcSetGeometryIntersectFilterFunction(
RTCGeometry geometry,
RTCFilterFunctionN filter
);
π¦ DESCRIPTION π¦
so rtcSetGeometryIntersectFilterFunction is literally the function that registers an intersection filter callback (that's the filter argument, bestie) for whichever geometry you point at (the geometry argument). one geometry, one callback, that's the rule π
only one callback per geometry, no cap. register another one and it just overwrites the one you had before. pass NULL as the function pointer and boom, the registered callback is disabled. gone. bye π
the intersection filter you registered gets invoked for every single hit that shows up during rtcIntersect-type ray queries, and it gets to accept or reject that hit. iconic. what's it for? defining a silhouette for a primitive and rejecting hits that fall outside it! like, imagine a tree leaf modeled with an alpha texture that decides whether hit points are inside or outside the leaf. that's the vibe πΏ
β οΈ okay important, listen up: if theRTC_BUILD_QUALITY_HIGHmode is set, filter functions may get called multiple times for the same primitive hit. AND rays hitting exactly the edge might also report two hits for the same surface. so for certain use cases the application may have to work around this limitation by collecting already reported hits (geomID/primIDpairs) and ignoring duplicates. yes, you have to do that yourself. no, it's not a bug, it's a limitation. periodt π
π the arguments struct, explained π
the filter callback is of type RTCFilterFunctionN and it gets handed a bunch of arguments through the RTCFilterFunctionNArguments structure. let's break it down, one member at a time, no skipping π₯
validβ points to an integer valid mask.0means invalid,-1means valid. that's it, that's the whole scale π«ΆgeometryUserPtrβ a user pointer, optionally set per geometry through thertcSetGeometryUserDatafunction. your lil custom data slot πcontextβ points to the intersection context passed to the ray query function.rayβ points toNrays in SOA layout.hitβ points toNhits in SOA layout, ready to be tested.Nβ the number of rays and hits inrayandhit. sameNfor both, they match π
a few more things you gotta know:
- the hit distance is provided as the
tfarvalue of the ray. - if the hit geometry is instanced, the
instIDmember of the ray is valid, and the ray and the potential hit are in object space.
π what your callback actually has to do π
your filter callback's whole job is: for each valid ray, decide if it wants to accept or reject the corresponding hit.
- to reject a hit β just write
0to the integer valid mask of the corresponding ray. - to accept the hit β just leave the valid mask set to
-1. don't touch it, it's already correct β¨
the filter function is also allowed to change the hit and decrease the tfar value of the ray. but bestie β it should not modify other ray data, and it should not touch any inactive components of the ray or hit. stay in your lane π§
π§ implementation options (both slay) π§
you've got choices, and honestly both eat:
- implement a single code path that uses the ray access helper functions
RTCRay_XXXand hit access helper functionsRTCHit_XXXto access ray and hit data. one path, clean, simple, we love her π - branch to optimized implementations for specific sizes of
Nand cast the ray and hit inputs to the proper packet types. spicy, fast, main character energy π
π EXIT STATUS π
on failure an error code is set, and you can query it using rtcGetDeviceError. so like, if something goes wrong, that's where you go lookin π
π SEE ALSO π
- [rtcSetGeometryOccludedFilterFunction]
and that's the whole page, bestie!! πβ¨
this was rtcSetGeometryIntersectFilterFunction(3) from the Embree Ray Tracing Kernels 3 manual, section 3, and no date was on the tin so we're just vibing with that. go forth and filter those hits responsibly π«Άπππ¦πΈ
π¦ where this page comes from
- epel 9: embree 3.13.5-4.el9 Β· Apache-2.0
- fedora 43: embree3 3.13.5-9.fc41 Β· Apache-2.0
- fedora 44: embree3 3.13.5-16.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms