RTCSETGEOMETRYINTERSECTFUNCTION(3embree4)
π rtcSetGeometryIntersectFunction β the Embree Ray Tracing Kernels 4 glow-up β¨
okay bestie, settle in, because this one is the function you call when you want your own lil custom primitives to actually get hit by rays. it lives in the Embree Ray Tracing Kernels 4 manual, page name rtcSetGeometryIntersectFunction(3), and yes it's giving main character energy π
β¨ NAME β¨
rtcSetGeometryIntersectFunction β sets the callback function to intersect a user geometry. that's it, that's the job π
π¦ SYNOPSIS π¦
#include <embree4/rtcore.h>
struct RTCIntersectFunctionNArguments
{
int* valid;
void* geometryUserPtr;
unsigned int primID;
struct RTCRayQueryContext* context;
struct RTCRayHitN* rayhit;
unsigned int N;
unsigned int geomID;
};
typedef void (*RTCIntersectFunctionN)(
const struct RTCIntersectFunctionNArguments* args
);
void rtcSetGeometryIntersectFunction(
RTCGeometry geometry,
RTCIntersectFunctionN intersect
);
like, look at that struct. gorgeous. no notes. πΈ
π DESCRIPTION π
so rtcSetGeometryIntersectFunction registers a ray/primitive intersection callback function (that's the intersect argument) for the user geometry you pass in (that's the geometry argument). match made in heaven fr fr π
lowkey important: only one callback function can be registered per geometry, and if you call this again it just overwrites whatever you set before. no stacking, no collecting them like pokΓ©mon. and if you pass NULL as the function pointer, you're disabling the registered callback entirely. bye bestie π
the registered callback gets invoked by rtcIntersect-type ray queries to calculate the intersection of a ray packet of variable size with one user-defined primitive. the callback is of type RTCIntersectFunctionN and it gets all its lil arguments handed to it through the RTCIntersectFunctionNArguments structure. let's break down the tea β:
Nβ the ray packet size.validβ points to an array of integers saying whether the corresponding ray is valid (-1) or invalid (0).geometryUserPtrβ points to the geometry user data you set earlier withrtcSetGeometryUserData.contextβ points to the ray query context that was passed to the ray query.rayhitβ points to a ray and hit packet of variable sizeN.geomIDandprimIDβ identify the geometry ID and the primitive ID of the primitive to intersect. iykyk π₯
okay now the spicy part. the ray component of the rayhit structure contains valid data β in particular the tfar value is the current closest hit distance found. but all data inside the hit component of the rayhit structure is undefined and you should not read it. not even a lil peek. do not do it π
so what's the actual task of the callback? intersect each active ray from the ray packet with the specified user primitive. simple. iconic.
- if the user-defined primitive is missed by a ray in the packet β the function should return without modifying the ray or hit. leave it alone, it's not yours.
- if an intersection of the user-defined primitive with the ray was found in the valid range (that's from
tneartotfar) β it should update the hit distance of the ray (thetfarmember) and the hit (theu,v,Ng,instID,geomID,primIDmembers). periodt.
β tiny but crucial detail: the currently intersected instance is stored in theinstIDfield of the ray query context, and you must deep copy it into theinstIDmember of the hit. don't skip this. it's the way that you absolutely have to do it. π
and since a primitive might have multiple intersections with a ray, the intersection filter function needs to be invoked by the user geometry intersection callback for each encountered intersection, if filtering of intersections is desired. you do that with the rtcInvokeIntersectFilterFromGeometry call. every single one, bestie, don't be lazy π«Ά
also good news: within the user geometry intersect function, it is safe to trace new rays and create new scenes and geometries. go wild. slay β¨
π EXIT STATUS π
on failure an error code is set, and you can go query it with rtcGetDeviceError. so if something's giving weird, that's where the receipts are π§
π SEE ALSO π
rtcSetGeometryOccludedFunctionrtcSetGeometryUserDatartcInvokeIntersectFilterFromGeometry
and that's the whole vibe check! π this was the rtcSetGeometryIntersectFunction page from the Embree Ray Tracing Kernels 4 manual β footer's just the truncated page name rtcSetGeo...ctFunction(3), so no date to spill, but you already knew that. go intersect something gorgeous, bestie. ππ¦β¨
π¦ where this page comes from
- alpine 3.24: embree-doc 4.4.1-r0 Β· Apache-2.0
- arch rolling: embree 4.4.1-1 Β· Apache-2.0
- fedora 43: embree 4.4.1-1.fc43 Β· Apache-2.0
- fedora 44: embree 4.4.1-1.fc44 Β· Apache-2.0
- nixpkgs unstable: embree 4.4.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms