From 623874f38447175f3213bc2e6488a61a4b1797e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20R=C3=ADos?= Date: Sat, 11 May 2024 19:26:17 +0200 Subject: [PATCH] fix: speed up `bvh` nodes --- sources/utils/BVHNode.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/sources/utils/BVHNode.cpp b/sources/utils/BVHNode.cpp index ed5778b..0b8ae58 100644 --- a/sources/utils/BVHNode.cpp +++ b/sources/utils/BVHNode.cpp @@ -39,13 +39,7 @@ Raytracer::Utils::BVHNode::BVHNode( std::vector> &objects, size_t start, size_t end) { - _bbox = AxisAlignedBBox::Empty; - - for (size_t i = start; i < end; i++) { - _bbox = AxisAlignedBBox(_bbox, objects[i]->boundingBox()); - } - - int axis = _bbox.longestAxis(); + int axis = randomInt(0, 2); auto fn = (axis == 0) ? boxXCompare : (axis == 1) ? boxYCompare @@ -67,6 +61,8 @@ Raytracer::Utils::BVHNode::BVHNode( _right = std::make_shared(objects, mid, end); } + + _bbox = AxisAlignedBBox(_left->boundingBox(), _right->boundingBox()); } /**