Post by packetslave on Aug 10, 2020 18:41:20 GMT
I've almost got the BVH optimization working in my renderer, but it's just a little... off. Here's my teapot after calling root->divide(600)
And here's the teapot after only calling the first iteration of divide (so leaving out the recursive divisions):
Obviously I'm missing a step somewhere in the division (or I have an off-by-one that I'm not seeing), since it's leaving out chunks of the images
Any thoughts?
And here's the teapot after only calling the first iteration of divide (so leaving out the recursive divisions):
Obviously I'm missing a step somewhere in the division (or I have an off-by-one that I'm not seeing), since it's leaving out chunks of the images
std::pair<ShapeVector, ShapeVector> Group::partition_children() {
ShapeVector out_left;
ShapeVector out_right;
auto bounds = this->bounds_of();
auto [left, right] = bounds->split();
ShapeVector::iterator it;
for (it = children_.begin(); it != children_.end(); /* no increment */) {
auto child_bounds = (*it)->parent_space_bounds_of();
if (left.contains(*child_bounds)) {
out_left.push_back(*it);
it = children_.erase(it);
updated_ = true;
continue;
}
if (right.contains(*child_bounds)) {
out_right.push_back(*it);
it = children_.erase(it);
updated_ = true;
continue;
}
++it;
}
return { out_left, out_right };
}
void Group::make_subgroup(ShapeVector shapes) {
auto g = std::make_shared<Group>();
for (const auto& s : shapes) {
g->add(s);
}
add(g);
}
void Group::divide(const size_t threshold) override {
if (threshold <= children_.size()) {
auto [left, right] = partition_children();
if (! left.empty()) {
make_subgroup(left);
}
if (! right.empty()) {
make_subgroup(right);
}
}
for (const auto& i : children_) {
i->divide(threshold);
}
}
Any thoughts?