Skip to content

Commit

Permalink
Merge pull request #232 from Walther/push-qsmuvryqyqyr
Browse files Browse the repository at this point in the history
improvement: update distance_max in bvh traversal, reduce runtime
  • Loading branch information
Walther authored Jan 6, 2025
2 parents 681e334 + 47c6029 commit 185734a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions clovers/src/bvh/hitable_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl HitableTrait for BVHNode<'_> {
&self,
ray: &Ray,
distance_min: Float,
distance_max: Float,
mut distance_max: Float,
rng: &mut SmallRng,
) -> Option<HitRecord> {
// If we do not hit the bounding box of current node, early return None
Expand Down Expand Up @@ -54,8 +54,11 @@ impl HitableTrait for BVHNode<'_> {
};
let closest_bvh_hit = closest_bvh.hit(ray, distance_min, distance_max, rng);

// Is the hit closer than the closest point of the other AABB?
// Do we hit the closer AABB?
if let Some(ref hit_record) = closest_bvh_hit {
// Update distance_max with the distance of confirmed hit
distance_max = hit_record.distance;
// Is the hit closer than the closest point of the other AABB?
if hit_record.distance < furthest_aabb_distance {
return Some(hit_record.clone());
}
Expand Down
7 changes: 5 additions & 2 deletions clovers/src/bvh/testcount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl BVHNode<'_> {
depth: &mut usize,
ray: &Ray,
distance_min: Float,
distance_max: Float,
mut distance_max: Float,
rng: &mut SmallRng,
) -> Option<HitRecord> {
*depth += 1;
Expand Down Expand Up @@ -64,8 +64,11 @@ impl BVHNode<'_> {
};
let closest_bvh_hit = recurse(closest_bvh, depth, ray, distance_min, distance_max, rng);

// Is the hit closer than the closest point of the other AABB?
// Do we hit the closer AABB?
if let Some(ref hit_record) = closest_bvh_hit {
// Update distance_max with the distance of confirmed hit
distance_max = hit_record.distance;
// Is the hit closer than the closest point of the other AABB?
if hit_record.distance < furthest_aabb_distance {
return Some(hit_record.clone());
}
Expand Down

0 comments on commit 185734a

Please sign in to comment.