Skip to content

Commit

Permalink
-Handle case where all BVH elements in a leaf are centered at the sam…
Browse files Browse the repository at this point in the history
…e point
  • Loading branch information
tylermorganwall committed Dec 16, 2020
1 parent d53ad9d commit 6c91e6a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/bvh_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ bvh_node::bvh_node(std::vector<std::shared_ptr<hitable> >& l,
}
constexpr int nBuckets = 12;
size_t n = end - start;

std::vector<aabb> primitiveBounds(n);

l[start]->bounding_box(time0, time1, centroid_bounds);
Expand Down Expand Up @@ -119,6 +119,11 @@ bvh_node::bvh_node(std::vector<std::shared_ptr<hitable> >& l,
}
} else {
std::sort(l.begin() + start, l.begin() + end, comparator);
//Handle case where all shapes share the same centroid
if(central_bounds.diag.squared_length() == 0 ) {
sah = false;
bvh_type = 2;
}
//SAH
if(sah) {
for (int i = 0; i < n; ++i) {
Expand Down Expand Up @@ -150,7 +155,7 @@ bvh_node::bvh_node(std::vector<std::shared_ptr<hitable> >& l,
}
}

int minCostSplitBucket = -1;
int minCostSplitBucket = 0;
Float minCost = INFINITY;
for (int i = 0; i < nSplits; ++i) {
if (countBelow[i] == 0 || countAbove[i] == 0) {
Expand Down
3 changes: 0 additions & 3 deletions src/csg.h
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,6 @@ using Mix = CSG<mixFunc, float>;
class csg: public hitable {
public:
csg() {}
~csg() {
// delete mat_ptr;
}
csg(std::shared_ptr<material> mat, std::shared_ptr<ImplicitShape> shapes) : mat_ptr(mat), shapes(shapes) {
aabb box;
bool temp = shapes->bbox(0,1,box);
Expand Down

0 comments on commit 6c91e6a

Please sign in to comment.