forked from jan-van-bergen/GPU-Raytracer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: Common BVH class + its memory is now owned by an Array
- Loading branch information
1 parent
9138920
commit 601be4d
Showing
27 changed files
with
476 additions
and
480 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,79 @@ | ||
#include "BVH.h" | ||
|
||
void BVH::aggregate(BVHNodePtr aggregated_bvh_nodes, int index_offset, int bvh_offset) const { | ||
#include "BVH/Builders/QBVHBuilder.h" | ||
#include "BVH/Builders/CWBVHBuilder.h" | ||
|
||
BVH * BVH::create_from_bvh2(BVH2 bvh) { | ||
switch (config.bvh_type) { | ||
case BVHType::BVH: | ||
case BVHType::SBVH: { | ||
BVHNode2 * dst = aggregated_bvh_nodes._2 + bvh_offset; | ||
|
||
for (int n = 0; n < node_count; n++) { | ||
BVHNode2 & node = dst[n]; | ||
node = nodes._2[n]; | ||
|
||
if (node.is_leaf()) { | ||
node.first += index_offset; | ||
} else { | ||
node.left += bvh_offset; | ||
} | ||
} | ||
break; | ||
return new BVH2(std::move(bvh)); | ||
} | ||
case BVHType::QBVH: { | ||
BVHNode4 * dst = aggregated_bvh_nodes._4 + bvh_offset; | ||
|
||
for (int n = 0; n < node_count; n++) { | ||
BVHNode4 & node = dst[n]; | ||
node = nodes._4[n]; | ||
|
||
int child_count = node.get_child_count(); | ||
for (int c = 0; c < child_count; c++) { | ||
if (node.is_leaf(c)) { | ||
node.get_index(c) += index_offset; | ||
} else { | ||
node.get_index(c) += bvh_offset; | ||
} | ||
} | ||
} | ||
break; | ||
BVH4 * bvh4 = new BVH4(); | ||
|
||
// Collapse binary BVH into quaternary BVH | ||
QBVHBuilder qbvh_builder = { }; | ||
qbvh_builder.init(bvh4, std::move(bvh)); | ||
qbvh_builder.build(bvh); | ||
|
||
return bvh4; | ||
} | ||
case BVHType::CWBVH: { | ||
BVHNode8 * dst = aggregated_bvh_nodes._8 + bvh_offset; | ||
BVH8 * bvh8 = new BVH8(); | ||
|
||
// Collapse binary BVH into 8-way Compressed Wide BVH | ||
CWBVHBuilder cwbvh_builder = { }; | ||
cwbvh_builder.init(bvh8, std::move(bvh)); | ||
cwbvh_builder.build(bvh); | ||
|
||
return bvh8; | ||
} | ||
default: abort(); | ||
} | ||
} | ||
|
||
for (int n = 0; n < node_count; n++) { | ||
BVHNode8 & node = dst[n]; | ||
node = nodes._8[n]; | ||
void BVH2::aggregate(BVHNodePtr aggregated_bvh_nodes, int index_offset, int bvh_offset) const { | ||
BVHNode2 * dst = aggregated_bvh_nodes._2 + bvh_offset; | ||
|
||
node.base_index_triangle += index_offset; | ||
node.base_index_child += bvh_offset; | ||
for (size_t n = 0; n < nodes.size(); n++) { | ||
BVHNode2 & node = dst[n]; | ||
node = nodes[n]; | ||
|
||
if (node.is_leaf()) { | ||
node.first += index_offset; | ||
} else { | ||
node.left += bvh_offset; | ||
} | ||
} | ||
} | ||
|
||
void BVH4::aggregate(BVHNodePtr aggregated_bvh_nodes, int index_offset, int bvh_offset) const { | ||
BVHNode4 * dst = aggregated_bvh_nodes._4 + bvh_offset; | ||
|
||
for (int n = 0; n < nodes.size(); n++) { | ||
BVHNode4 & node = dst[n]; | ||
node = nodes[n]; | ||
|
||
int child_count = node.get_child_count(); | ||
for (int c = 0; c < child_count; c++) { | ||
if (node.is_leaf(c)) { | ||
node.get_index(c) += index_offset; | ||
} else { | ||
node.get_index(c) += bvh_offset; | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
|
||
void BVH8::aggregate(BVHNodePtr aggregated_bvh_nodes, int index_offset, int bvh_offset) const { | ||
BVHNode8 * dst = aggregated_bvh_nodes._8 + bvh_offset; | ||
|
||
for (int n = 0; n < nodes.size(); n++) { | ||
BVHNode8 & node = dst[n]; | ||
node = nodes[n]; | ||
|
||
node.base_index_triangle += index_offset; | ||
node.base_index_child += bvh_offset; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.