RTCSETGEOMETRYINTERSECTFUNCTION(3embree3)
π rtcSetGeometryIntersectFunction β bestie edition π
okay so you're in the Embree Ray Tracing Kernels 3 manual (yes, the 3embree3 one, she's iconic) and you wanna teach your own geometry how to get hit by a ray?? say less, this page is literally for you π«Ά
β¨ NAME β¨
rtcSetGeometryIntersectFunction β sets the callback function to intersect a user geometry π
β¨ SYNOPSIS β¨
#include <embree3/rtcore.h>
struct RTCIntersectFunctionNArguments
{
int* valid;
void* geometryUserPtr;
unsigned int primID;
struct RTCIntersectContext* context;
struct RTCRayHitN* rayhit;
unsigned int N;
unsigned int geomID;
};
typedef void (*RTCIntersectFunctionN)(
const struct RTCIntersectFunctionNArguments* args
);
void rtcSetGeometryIntersectFunction(
RTCGeometry geometry,
RTCIntersectFunctionN intersect
);
β¨ DESCRIPTION β¨
so basically rtcSetGeometryIntersectFunction registers a ray/primitive intersection callback function (that's the intersect argument, bestie) for the user geometry you point at with the geometry argument. it's giving "here's how you hit me" energy π
only one callback function can be registered per geometry, no cap β if you invoke this again it just overwrites whatever callback was set before. and if you pass NULL as the function pointer? that disables the registered callback function entirely. bye bye callback π
the registered callback function 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 function of type RTCIntersectFunctionN gets handed a bunch of arguments through the RTCIntersectFunctionNArguments structure, so let's break down the group chat:
Nβ specifies the ray packet size π¦validβ points to an array of integers that specify whether the corresponding ray is valid (-1) or invalid (0)geometryUserPtrβ points to the geometry user data you previously set throughrtcSetGeometryUserDatacontextβ points to the intersection context passed to the ray queryrayhitβ points to a ray and hit packet of variable sizeNgeomIDandprimIDβ identify the geometry ID and primitive ID of the primitive to intersect
so the ray component of the rayhit structure contains valid data β specifically the tfar value is the current closest hit distance found. but all the data inside the hit component of the rayhit structure are undefined and should not be read by the function. do not read them. i'm so serious π
now the actual job of the callback function: intersect each active ray from the ray packet with the specified user primitive. that's it, that's the task, main character energy β¨
- if the user-defined primitive is missed by a ray of the ray packet, the function should return without modifying the ray or hit. nothing happened, no notes π
- if an intersection of the user-defined primitive with the ray was found in the valid range (from
tneartotfar), it should update the hit distance of the ray (thetfarmember) and the hit (u,v,Ng,instID,geomID,primIDmembers).
and here's the sneaky part β the currently intersected instance is stored in the instID field of the intersection context, and you must deep copy that into the instID member of the hit. must. deep copy. do it π«‘
also, because 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 β that's only if filtering of intersections is desired, iykyk. you can achieve that through the rtcFilterIntersection call πΈ
and the good news bestie: within the user geometry intersect function, it is safe to trace new rays and create new scenes and geometries. go off, live your truth π₯
β¨ EXIT STATUS β¨
if something goes wrong, on failure an error code is set that can be queried using rtcGetDeviceError. so like, check that if things feel off π
β¨ SEE ALSO β¨
- [rtcSetGeometryOccludedFunction]
- [rtcSetGeometryUserData]
- [rtcFilterIntersection]
ok that's the whole page, you ate that fr fr π
this was rtcSetGeometryIntersectFunction from the Embree Ray Tracing Kernels 3 manual β and yeah, the footer at the bottom is just that same rtcSetGeo...ctFunction(3) title-and-section line doing its little truncated thing, she's shy but she's there π byeee, go intersect something iconic π
π¦ 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