diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2015-01-10 20:41:49 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2015-01-12 13:04:52 +0300 |
commit | bc7ff3c2b44e9cd8f3aea1a3943b787deede2838 (patch) | |
tree | b93c8de1b10b739fc7b7250305b4b0121f37a068 /intern/cycles/bvh/bvh_build.cpp | |
parent | c707b91ce6b14182a3a579b645cfd832fc1ae658 (diff) |
Cycles: Enable leaf split by primitive type and adopt BVH traversal for this
This commit enables BVH leaf nodes split by the primitive type and makes it
so BVH traversal code is now aware and benefits from this.
As was mentioned in original commit, this change is crucial to be able to do
single ray to multiple triangle intersection. But it also appears to give
barely visible speedup in some scene.
In any case there should be no noticeable slowdown, and this change is what
we need to have anyway.
Diffstat (limited to 'intern/cycles/bvh/bvh_build.cpp')
-rw-r--r-- | intern/cycles/bvh/bvh_build.cpp | 64 |
1 files changed, 1 insertions, 63 deletions
diff --git a/intern/cycles/bvh/bvh_build.cpp b/intern/cycles/bvh/bvh_build.cpp index d0542f064a3..23c696ea6b2 100644 --- a/intern/cycles/bvh/bvh_build.cpp +++ b/intern/cycles/bvh/bvh_build.cpp @@ -473,7 +473,7 @@ BVHNode *BVHBuild::create_primitive_leaf_node(const int *p_type, return new LeafNode(bounds, visibility, start, start + num); } -BVHNode* BVHBuild::create_leaf_node_split(const BVHRange& range) +BVHNode* BVHBuild::create_leaf_node(const BVHRange& range) { #define MAX_LEAF_SIZE 8 int p_num[PRIMITIVE_NUM_TOTAL] = {0}; @@ -564,68 +564,6 @@ BVHNode* BVHBuild::create_leaf_node_split(const BVHRange& range) #undef AMX_LEAF_SIZE } -BVHNode* BVHBuild::create_leaf_node(const BVHRange& range) -{ - if(params.use_split_leaf_types) { - /* Need to ensure leaf nodes has single primitive type only. */ - return create_leaf_node_split(range); - } - - vector<int>& p_type = prim_type; - vector<int>& p_index = prim_index; - vector<int>& p_object = prim_object; - BoundBox bounds = BoundBox::empty; - int num = 0, ob_num = 0; - uint visibility = 0; - - for(int i = 0; i < range.size(); i++) { - BVHReference& ref = references[range.start() + i]; - - if(ref.prim_index() != -1) { - if(range.start() + num == prim_index.size()) { - assert(params.use_spatial_split); - - p_type.push_back(ref.prim_type()); - p_index.push_back(ref.prim_index()); - p_object.push_back(ref.prim_object()); - } - else { - p_type[range.start() + num] = ref.prim_type(); - p_index[range.start() + num] = ref.prim_index(); - p_object[range.start() + num] = ref.prim_object(); - } - - bounds.grow(ref.bounds()); - visibility |= objects[ref.prim_object()]->visibility; - num++; - } - else { - if(ob_num < i) - references[range.start() + ob_num] = ref; - ob_num++; - } - } - - BVHNode *leaf = NULL; - - if(num > 0) { - leaf = new LeafNode(bounds, visibility, range.start(), range.start() + num); - - if(num == range.size()) - return leaf; - } - - /* while there may be multiple triangles in a leaf, for object primitives - * we want there to be the only one, so we keep splitting */ - const BVHReference *ref = (ob_num)? &references[range.start()]: NULL; - BVHNode *oleaf = create_object_leaf_nodes(ref, range.start() + num, ob_num); - - if(leaf) - return new InnerNode(range.bounds(), leaf, oleaf); - else - return oleaf; -} - /* Tree Rotations */ void BVHBuild::rotate(BVHNode *node, int max_depth, int iterations) |