From e6155681019674b5e084f808d322b27a35597d6c Mon Sep 17 00:00:00 2001 From: Jacco Bikker Date: Thu, 23 Jan 2025 19:43:37 +0100 Subject: [PATCH] Using tinybvh_transform_*. --- tiny_bvh_custom.cpp | 5 +++-- tiny_bvh_custom_double.cpp | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tiny_bvh_custom.cpp b/tiny_bvh_custom.cpp index efc11d8..c093fac 100644 --- a/tiny_bvh_custom.cpp +++ b/tiny_bvh_custom.cpp @@ -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 ) diff --git a/tiny_bvh_custom_double.cpp b/tiny_bvh_custom_double.cpp index d4591ea..eb486e3 100644 --- a/tiny_bvh_custom_double.cpp +++ b/tiny_bvh_custom_double.cpp @@ -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 )