Skip to content

Commit

Permalink
Using tinybvh_transform_*.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbikker committed Jan 23, 2025
1 parent 0075cf9 commit e615568
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions tiny_bvh_custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@ static bvhvec3 eye( -15.24f, 21.5f, 2.54f ), p1, p2, p3;
static bvhvec3 view = tinybvh_normalize( bvhvec3( 0.826f, -0.438f, -0.356f ) );

// callback for custom geometry: ray/sphere intersection
void sphereIntersect( tinybvh::Ray& ray, const unsigned primID )
bool sphereIntersect( tinybvh::Ray& ray, const unsigned primID )
{
bvhvec3 oc = ray.O - spheres[primID].pos;
float b = tinybvh_dot( oc, ray.D );
float r = spheres[primID].r;
float c = tinybvh_dot( oc, oc ) - r * r;
float t, d = b * b - c;
if (d <= 0) return;
if (d <= 0) return false;
d = sqrtf( d ), t = -b - d;
bool hit = t < ray.hit.t && t > 0;
if (hit) ray.hit.t = t, ray.hit.prim = primID;
return hit;
}

bool sphereIsOccluded( const tinybvh::Ray& ray, const unsigned primID )
Expand Down
5 changes: 3 additions & 2 deletions tiny_bvh_custom_double.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@ static bvhvec3 eye( -15.24f, 21.5f, 2.54f ), p1, p2, p3;
static bvhvec3 view = tinybvh_normalize( bvhvec3( 0.826f, -0.438f, -0.356f ) );

// callback for custom geometry: ray/sphere intersection
void sphereIntersect( tinybvh::RayEx& ray, const uint64_t primID )
bool sphereIntersect( tinybvh::RayEx& ray, const uint64_t primID )
{
bvhdbl3 oc = ray.O - spheres[primID].pos;
double b = tinybvh_dot( oc, ray.D );
double r = spheres[primID].r;
double c = tinybvh_dot( oc, oc ) - r * r;
double t, d = b * b - c;
if (d <= 0) return;
if (d <= 0) return false;
d = sqrt( d ), t = -b - d;
bool hit = t < ray.hit.t && t > 0;
if (hit) ray.hit.t = t, ray.hit.prim = primID;
return hit;
}

bool sphereIsOccluded( const tinybvh::RayEx& ray, const uint64_t primID )
Expand Down

0 comments on commit e615568

Please sign in to comment.