RTCHit(3)

πŸ’– RTCHit β€” single hit structure πŸ’–

okay bestie, pull up a chair πŸͺ‘ because we're talking about RTCHit, which is literally the lil' receipt the Embree Ray Tracing Kernels (that's version 4, mwah) hand you every time a ray smacks into a primitive. it's giving "proof of collision" energy and honestly? iconic. πŸ’…


✨ SYNOPSIS ✨

first thing's first, you gotta bring in the header:

#include <embree4/rtcore.h>

and here's the whole struct, verbatim, no notes (jk there are notes, they're in the comments):

struct RTCHit
{
  float Ng_x;                                        // x coordinate of geometry normal
  float Ng_y;                                        // y coordinate of geometry normal
  float Ng_z;                                        // z coordinate of geometry normal

  float u;                                           // barycentric u coordinate of hit
  float v;                                           // barycentric v coordinate of hit

  unsigned int primID;                               // geometry ID
  unsigned int geomID;                               // primitive ID
  unsigned int instID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance ID
};

like look at her. so organized. so demure. πŸŽ€


🌈 DESCRIPTION 🌈

so RTCHit is the type that holds the result of a ray/primitive intersection. basically: ray goes in, hit comes out, and this struct is the hit. πŸ¦‹

what's actually inside it, bestie:

  • the unnormalized geometric normal, in object space</>, right at the hit location β€” that's the Ng_x, Ng_y, and Ng_z members. note the "unnormalized" and note the "object space", they're both doing heavy lifting, don't skip past them.
  • the barycentric coordinates of the hit β€” that's u and v. πŸ’«
  • the primitive ID β€” the primID member.
  • the geometry ID β€” the geomID member.
  • the instance ID stack β€” the instID member. πŸ‘‘

and now the part that trips people up, so listen up fr fr: the parametric intersection distance is NOT stored inside the hit. it lives inside the tfar member of the ray instead. not the hit. the ray. i know. i know. but that's just how she is. 😭


🫢 the SOA glow-up (still DESCRIPTION, bestie)

the embree4/rtcore_ray.h header also defines the exact same hit structure, but in structure of array (SOA)</> layout, for hit packets of:

  • size 4 β€” the RTCHit4 type
  • size 8 β€” the RTCHit8 type
  • size 16 β€” the RTCHit16 type

and on top of all that, that same header defines an RTCHitNt template so you can make hit packets of whatever compile-time size your heart desires. no cap. πŸ’œ


πŸ’€ EXIT STATUS πŸ’€

...yeah, there's nothing here. it's a struct, bestie, she doesn't exit. she just is. πŸ™ˆ


πŸ‘€ SEE ALSO πŸ‘€

go read these next, i'm obsessed with them for you:

  • RTCRay
  • Multi-Level Instancing

and that's the whole page! πŸ“ this lil' slice of the Embree Ray Tracing Kernels 4 manual, filed under RTCHit(3), was written by the Embree team and is yours to go be a main character with. now go intersect something. πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from