rtcIntersect1(3)

πŸ’– rtcIntersect1 πŸ’–

okay so bestie, welcome to rtcIntersect1(3) from the Embree Ray Tracing Kernels 4 manual. this one's a whole vibe: it's the "find me the closest hit for ONE single ray" girlie. let's get into it ✨


🌸 NAME 🌸

rtcIntersect1 β€” finds the closest hit for a single ray 🎯


✨ SYNOPSIS ✨

#include <embree4/rtcore.h>

void rtcIntersect1(
  RTCScene scene,
  struct RTCRayHit* rayhit
  struct RTCIntersectArguments* args = NULL
);

(yes the missing comma is canon, we don't touch the sacred text πŸ’…)


πŸ¦‹ DESCRIPTION πŸ¦‹

so rtcIntersect1 finds the closest hit of a single ray (that's the rayhit argument) against the scene (the scene argument). the ray/hit structure you hand over carries the ray you wanna intersect plus some hit output fields that get filled in the moment a hit is found. and that optional args struct? it's for advanced use cases only, check the section [rtcInitIntersectArguments] for the deets 🫢

to actually trace a ray, you gotta initialize all of this yourself, no cap:

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

the ray time (the time ray member) must be initialized to a value in the range $[0, 1]$. the ray segment has to be in the range [0, ∞], so ranges that start behind the ray origin are not valid β€” but bestie, ranges can reach to infinity, slay. 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). don't forget it, it's giving important πŸ™ˆ

when no intersection is found, the ray/hit data is not updated. when an intersection is found, the hit distance gets written into the tfar member of the ray, and all the hit data gets set, like:

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

see Section [RTCHit] for the hit layout description. it's all there πŸ’œ


🌈 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

iykyk 🧚


πŸ’€ the edge case warning (read this one fr fr) πŸ’€

the implementation makes no guarantees that primitives whose hit distance is exactly at (or very close to) tnear or tfar are hit or missed. this is genuinely undefined-ish territory, 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. that's the move, periodt.

also, the ray/hit structure must be aligned to 16 bytes. that's not a suggestion bestie, that's the law πŸ‘‘


πŸŽ€ EXIT STATUS πŸŽ€

for performance reasons this function does not do any error checks, so it will not set any error flags on failure. it simply does not have the energy to catch your mistakes, and honestly? relatable 😭


⭐ SEE ALSO ⭐

  • [rtcOccluded1]
  • [rtcIntersect4/8/16]
  • [RTCRayHit]
  • [rtcInitIntersectArguments]

and that's the whole page bestie!! this lil icon comes to you from the Embree Ray Tracing Kernels 4 era, dated rtcIntersect1(3) β€” go trace something iconic with it πŸ’…βœ¨πŸŒΈπŸ¦‹

πŸ“¦ where this page comes from