Skip to content

Commit 69a3d51

Browse files
committed
Fix BVHAccel issues noted in issue mmp#22.
1 parent aff8e2b commit 69a3d51

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/accelerators/bvh.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ struct MortonPrimitive {
7979
uint32_t mortonCode;
8080
};
8181

82-
inline uint32_t LeftShift3(uint32_t x);
8382
struct LBVHTreelet {
8483
int startIndex, nPrimitives;
8584
BVHBuildNode *buildNodes;
@@ -252,6 +251,10 @@ BVHBuildNode *BVHAccel::recursiveBuild(
252251
return pi.centroid[dim] < pmid;
253252
});
254253
mid = midPtr - &primitiveInfo[0];
254+
// For lots of prims with large overlapping bounding boxes, this
255+
// may fail to partition; in that case don't break and fall
256+
// through
257+
// to EqualCounts.
255258
if (mid != start && mid != end) break;
256259
}
257260
case SplitMethod::EqualCounts: {
@@ -594,7 +597,7 @@ BVHBuildNode *BVHAccel::buildUpperSAH(MemoryArena &arena,
594597
return node;
595598
}
596599

597-
int BVHAccel::flattenBVHTree(BVHBuildNode *node, int *offset, int depth) {
600+
int BVHAccel::flattenBVHTree(BVHBuildNode *node, int *offset) {
598601
LinearBVHNode *linearNode = &nodes[*offset];
599602
linearNode->bounds = node->bounds;
600603
int myOffset = (*offset)++;
@@ -607,9 +610,9 @@ int BVHAccel::flattenBVHTree(BVHBuildNode *node, int *offset, int depth) {
607610
// Create interior flattened BVH node
608611
linearNode->axis = node->splitAxis;
609612
linearNode->nPrimitives = 0;
610-
flattenBVHTree(node->children[0], offset, depth + 1);
613+
flattenBVHTree(node->children[0], offset);
611614
linearNode->secondChildOffset =
612-
flattenBVHTree(node->children[1], offset, depth + 1);
615+
flattenBVHTree(node->children[1], offset);
613616
}
614617
return myOffset;
615618
}

src/accelerators/bvh.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class BVHAccel : public Aggregate {
8484
BVHBuildNode *buildUpperSAH(MemoryArena &arena,
8585
std::vector<BVHBuildNode *> &treeletRoots,
8686
int start, int end, int *totalNodes) const;
87-
int flattenBVHTree(BVHBuildNode *node, int *offset, int depth = 0);
87+
int flattenBVHTree(BVHBuildNode *node, int *offset);
8888

8989
// BVHAccel Private Data
9090
const int maxPrimsInNode;

0 commit comments

Comments
 (0)