rtcIntersect1(3)

πŸ“¦ version 3.13.5, in epel 9, fedora 43, fedora 44

πŸ’– rtcIntersect1 πŸ’–

okay bestie, welcome to the Embree Ray Tracing Kernels 3 manual, section 3, and today's main character is rtcIntersect1 β€” she finds the closest hit for a single ray. literally that's her whole job and she ate. πŸŽ€


✨ NAME ✨

rtcIntersect1 β€” finds the closest hit for a single ray πŸ¦‹


✨ SYNOPSIS ✨

#include <embree3/rtcore.h>

void rtcIntersect1(
  RTCScene scene,
  struct RTCIntersectContext* context,
  struct RTCRayHit* rayhit
);

✨ DESCRIPTION ✨

so. the rtcIntersect1 function finds the closest hit of a single ray with the scene (that's the scene argument, bestie 🌸). the ray/hit structure you hand over (the rayhit argument) holds the ray you wanna intersect plus some hit output fields that get filled in the moment a hit is found. it's giving "you give me a ray, I give you the tea." πŸ’…

now, before you call her, you gotta initialize a bunch of stuff yourself, she will NOT do it for you:

  • the ray origin (the org ray member)
  • the ray direction (the dir ray member)
  • the ray segment (the tnear and tfar ray members)
  • the ray flags, set those to 0 (the flags ray member)

if the scene has motion blur geometries, you also gotta initialize the ray time (the time ray member) to a value in the range [0, 1]. and if ray masks are enabled at compile time, you gotta initialize the ray mask (the mask ray member) too. no skipping steps, bestie, this is not a vibe-optional situation 😭

the ray segment has to be in the range [0, ∞] β€” so ranges that start behind the ray origin are not valid, but ranges can reach all the way to infinity. iconic. see Section [RTCRay] for the ray layout description. 🫢

the geometry ID (the geomID hit member) of the hit data must be initialized to RTC_INVALID_GEOMETRY_ID (-1). like, must must.

also you gotta create and initialize an intersection context for the ray query function (see rtcInitIntersectContext). 🧚

when no intersection is found, the ray/hit data is simply not updated β€” she minds her business. when an intersection is found, the hit distance gets written into the tfar member of the ray, and all the hit data gets set, such as:

  • the unnormalized geometry normal in object space (the Ng hit member)
  • the local hit coordinates (the u, v hit members)
  • the instance ID stack (the instID hit member)
  • the geometry ID (the geomID hit member)
  • the primitive ID (the primID hit member)

see Section [RTCHit] for the hit layout description. πŸ“–


πŸ¦‹ the instance ID stack lore πŸ¦‹

if the instance ID stack has a prefix of values not equal to RTC_INVALID_GEOMETRY_ID, then:

  • the instance ID on each level corresponds to the geometry ID of the hit instance of the higher-level scene
  • the geometry ID corresponds to the hit geometry inside the hit instanced scene
  • the primitive ID corresponds to the n-th primitive of that geometry

and if level 0 of the instance ID stack is equal to RTC_INVALID_GEOMETRY_ID, then:

  • the geometry ID corresponds to the hit geometry inside the top-level scene
  • the primitive ID corresponds to the n-th primitive of that geometry

πŸ’€ the chaos clause πŸ’€

the implementation makes no guarantees that primitives whose hit distance is exactly at (or very close to) tnear or tfar are hit or missed. nope. she said "maybe, maybe not, figure it out." πŸ™ˆ

so if you want to exclude intersections at tnear, just pass a slightly enlarged tnear. and if you want to include intersections at tfar, pass a slightly enlarged tfar. problem solved, slay. ✨

⚠️ also the ray/hit structure must be aligned to 16 bytes. do not play with her about this one, bestie, the alignment is not a suggestion, it's a lifestyle. πŸ’…

✨ EXIT STATUS ✨

for performance reasons this function does not do any error checks β€” so it will not set any error flags on failure. she's fast and she's silent about it. no cap. 😌


✨ SEE ALSO ✨

  • [rtcOccluded1]
  • [RTCRayHit]
  • [RTCRay]
  • [RTCHit]

and that's the whole page, bestie!! πŸŽ€βœ¨ you just read the rtcIntersect1(3) manual from the Embree Ray Tracing Kernels 3 docs. go forth and intersect, you absolute icon. mwah πŸ’–πŸ‘‘πŸŒˆ

πŸ“¦ where this page comes from