rtcSetGeo...tFunction(3)
β¨ rtcSetGeometryDisplacementFunction β¨
okay bestie, welcome to the Embree Ray Tracing Kernels 4 manual (section 3, the library-call girlies) π
this one's all about rtcSetGeometryDisplacementFunction and it's giving subdivision-geometry glow-up energy. no cap.
πΈ NAME πΈ
rtcSetGeometryDisplacementFunction β sets the displacement function for a subdivision geometry π¦
π SYNOPSIS π
#include <embree4/rtcore.h>
struct RTCDisplacementFunctionNArguments
{
void* geometryUserPtr;
RTCGeometry geometry;
unsigned int primID;
unsigned int timeStep;
const float* u;
const float* v;
const float* Ng_x;
const float* Ng_y;
const float* Ng_z;
float* P_x;
float* P_y;
float* P_z;
unsigned int N;
};
typedef void (*RTCDisplacementFunctionN)(
const struct RTCDisplacementFunctionNArguments* args
);
void rtcSetGeometryDisplacementFunction(
RTCGeometry geometry,
RTCDisplacementFunctionN displacement
);
copy that exactly, bestie, every field matters π
π DESCRIPTION π
so like, rtcSetGeometryDisplacementFunction registers a displacement callback function (that's the displacement argument) onto the subdivision geometry you picked (that's the geometry argument). iconic behavior honestly.
one callback per geometry, periodt. only a single callback function can be registered per geometry, and if you call this again it just overwrites whatever callback you set before β no stacking, no vibes-multiplying. and if you pass NULL as the function pointer? that disables the registered callback function. bye girl π
when does your callback actually get called? the registered displacement callback function is invoked to displace points on the subdivision geometry during spatial acceleration structure construction, which is to say, during the rtcCommitScene call. so it's not a render-time thing, it's a build-time thing. iykyk π₯
now the callback itself, the one of type RTCDisplacementFunctionN, gets invoked with a bunch of arguments all bundled up inside the RTCDisplacementFunctionNArguments structure. let's go through them like a group chat roll call π±:
- the provided user data pointer of the geometry β that's the
geometryUserPtrmember β you can use it to point at your application's representation of the subdivision mesh. it's yours, decorate it however π - a number
Nof points to displace is specified, and it's in a structure-of-arrays layout, not array-of-structs. important!! β¨ - for each point you're displacing you get:
- the local patch UV coordinates β the
uandvarrays - the normalized geometry normal β the
Ng_x,Ng_y, andNg_zarrays - the position β the
P_x,P_y, andP_zarrays
- the local patch UV coordinates β the
- and the task of the displacement function is literally just: use all that info and change the position data. that's the whole job. slay.
you also get the geometry handle (the geometry member) and the primitive ID of the patch to displace (the primID member), plus the time step timeStep β and that one's important if your displacement is time-dependent and motion blur is in the mix. don't sleep on timeStep, bestie π«Ά
β οΈ okay serious moment: all passed arrays must be aligned to 64 bytes and properly padded, so that wide vector processing inside the displacement function is easily possible. do not skip this. the SIMD girlies are counting on you. π
also!! there's a tutorial, [Displacement Geometry], that shows an example of how to use the displacement mapping functions. go read it, it ate π
π EXIT STATUS π
if something goes wrong β on failure β an error code gets set, and you can go query it with rtcGetDeviceError. so like, always check on your girl. π₯Ί
β SEE ALSO β
- [RTC_GEOMETRY_TYPE_SUBDIVISION]
and that's the whole page, no notes π this was rtcSetGeo...tFunction(3) from the Embree Ray Tracing Kernels 4 manual, section 3, bestie β go displace something gorgeous β¨ππ¦
π¦ 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