Skip to content

hit_record

Stefan Zellmann edited this page Jun 2, 2016 · 10 revisions

Content of this page: Built-in versions of the hit_record struct that store the result of one or more ray / object intersection tests.

Note that the current version of Visionaray is an early preview. At this stage, the framework, including the API, are likely to undergo frequent changes.

Description

Routines like the customization point intersect() or functions that are derived from it return an instance of struct hit_record storing information that is associated with the ray / object intersection. The information returned from a ray / object intersection typically varies among primitive types. Visionaray provides a few hit_record implementations that may serve as a common base; the user is expected to return a custom hit_record from his or her custon ray / object intersection test if the built-in hit_records provide insufficient data fields.

Derived built-in operations, such as the intersection of a ray and a bounding-volume hierarchy or the result from custom intersectors, return instances of the hit_record struct pertaining to the contained primitive. This is also true if the bounding-volume hierarchy contains custom primitives.

Visionaray provides built-in hit_record structs for ray / triangle and ray / sphere intersections as well as for ray / axis-aligned bounding box intersections.

The user can reuse the hit_record struct for ray / triangle and ray / sphere intersections by deriving from the base class template visionaray::primitive and by returning an instance of type hit_record<R, primitive> from her custom intersect() routine. In that case, the data fields prim_id - a unique 32-bit signed integer primitive identifier, and geom_id - a 32-bit signed integer geometry identifier that can e.g. be used by kernels as an index to material or texture lists, must be manually set.

In order to fulfill the hit_record concept, a custom data type must provide the member typedef scalar_type.

Data Fields

hit_record - Ray, Triangle/Sphere
    hit:        mask_type       // Was an object hit (true/false)?
    prim_id:    int_type        // Id of the primitive (32-bit signed)
    geom_id:    int_type        // Id of the parent geometry (32-bit signed)
    t:          scalar_type     // Distance between ray origin and intersection position, FLT_MAX if no hit
    u:          scalar_type     // Surface parameter
    v:          scalar_type     // Surface parameter
hit_record - Ray, AABB
    hit:        mask_type       // Was an object hit (true/false)?
    tnear:      scalar_type     // Distance between ray origin and nearest intersection, FLT_MAX if no hit
    tfar:       scalar_type     // Distance between ray origin and farthest intersection, FLT_MAX if no hit