Skip to content

Commit

Permalink
fix: speed up bvh nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jabolol committed May 11, 2024
1 parent ea24f9a commit 623874f
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions sources/utils/BVHNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,7 @@ Raytracer::Utils::BVHNode::BVHNode(
std::vector<std::shared_ptr<Raytracer::Interfaces::IHittable>> &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
Expand All @@ -67,6 +61,8 @@ Raytracer::Utils::BVHNode::BVHNode(
_right =
std::make_shared<Raytracer::Utils::BVHNode>(objects, mid, end);
}

_bbox = AxisAlignedBBox(_left->boundingBox(), _right->boundingBox());
}

/**
Expand Down

0 comments on commit 623874f

Please sign in to comment.