Comments (8)
You can update the bounding boxes of every node in a for loop like so:
// It's important to process the nodes in reverse order, as this makes
// sure that children are processed before their parents.
for (auto& node : std::ranges::reverse_view { bvh.nodes }) {
if (node.is_leaf()) {
// refit node according to contents
...
} else {
auto& left = bvh.nodes[node.index.first_id];
auto& right = bvh.nodes[node.index.first_id + 1];
node.set_bbox(left.get_bbox().extend(right.get_bbox()));
}
}
I should probably add a method for this. Anyway, this method is very fast but should not be run in parallel as it expects the children to have been processed before the parents. The method used in the previous version of the repository works in parallel but is only faster when the BVH is extremely large.
from bvh.
Yes, they are still supported. The interface is a bit lower-level in the new version, so you only need an axis-aligned bounding box and a center point for each primitive you need to insert in the BVH. For you, this means something like:
std::vector<BBox> bboxes(obbs.size()); std::vector<Vec3> centers(obbs.size()); executor.for_each(0, tris.size(), [&] (size_t begin, size_t end) { for (size_t i = begin; i < end; ++i) { bboxes[i] = get_box(obbs[i]); centers[i] = obbs[i].pos; } }); typename bvh::v2::DefaultBuilder<Node>::Config config; config.quality = bvh::v2::DefaultBuilder<Node>::Quality::High; auto bvh = bvh::v2::DefaultBuilder<Node>::build(thread_pool, bboxes, centers, config);You can get the AABB of an OBB this way (you do not need to transform the 8 points of a 3D OBB):
// Assuming the corners are obtained by multiplying the matrix with (+-1, +-1, +-1) struct OBB { Mat3x3 mat; Vec3 pos; }; inline Box3 get_bbox(const OBB& obb) { auto abs_mat = abs(obb.mat); auto half_extents = abs_mat * Vec3 { 1, 1, 1 }; return Box3 { obb.pos - half_extents, obb.pos + half_extents }; };Thanks, that works! But what about updates/refitting? In version 1 I could use the
HierarchyRefitter
, but I see no equivalent in version 2. I create the bvh like you describe:bvh = ::bvh::v2::DefaultBuilder<pragma::bvh::Node>::build(GetThreadPool(), bboxes, centers, config);After creation I need to update the bboxes/centers every frame, but I see no way to access those after the bvh has been built. Can the
ReinsertionOptimizer
be used for refitting somehow?::bvh::v2::ReinsertionOptimizer<Node>::optimize(GetThreadPool(), bvh);
There is now a refitting method which allows you to refit the BVH serially (since #74 has been merged). I might add a parallel version later.
from bvh.
Hello! You may take a look at the example on custom primitives. An instance is just a primitive like any other, which itself contains a BVH and a matrix. Before intersecting the instance, you transform the ray by the inverse of the matrix. That's basically it.
from bvh.
Hello! You may take a look at the example on custom primitives. An instance is just a primitive like any other, which itself contains a BVH and a matrix. Before intersecting the instance, you transform the ray by the inverse of the matrix. That's basically it.
Are custom primitives still supported? I noticed that the example for them is no longer available, and I need a BVH with OBBs as primitives.
from bvh.
Yes, they are still supported. The interface is a bit lower-level in the new version, so you only need an axis-aligned bounding box and a center point for each primitive you need to insert in the BVH. For you, this means something like:
std::vector<BBox> bboxes(obbs.size());
std::vector<Vec3> centers(obbs.size());
executor.for_each(0, tris.size(), [&] (size_t begin, size_t end) {
for (size_t i = begin; i < end; ++i) {
bboxes[i] = get_box(obbs[i]);
centers[i] = obbs[i].pos;
}
});
typename bvh::v2::DefaultBuilder<Node>::Config config;
config.quality = bvh::v2::DefaultBuilder<Node>::Quality::High;
auto bvh = bvh::v2::DefaultBuilder<Node>::build(thread_pool, bboxes, centers, config);
You can get the AABB of an OBB this way (you do not need to transform the 8 points of a 3D OBB):
// Assuming the corners are obtained by multiplying the matrix with (+-1, +-1, +-1)
struct OBB {
Mat3x3 mat;
Vec3 pos;
};
inline Box3 get_bbox(const OBB& obb) {
auto abs_mat = abs(obb.mat);
auto half_extents = abs_mat * Vec3 { 1, 1, 1 };
return Box3 { obb.pos - half_extents, obb.pos + half_extents };
};
from bvh.
Yes, they are still supported. The interface is a bit lower-level in the new version, so you only need an axis-aligned bounding box and a center point for each primitive you need to insert in the BVH. For you, this means something like:
std::vector<BBox> bboxes(obbs.size()); std::vector<Vec3> centers(obbs.size()); executor.for_each(0, tris.size(), [&] (size_t begin, size_t end) { for (size_t i = begin; i < end; ++i) { bboxes[i] = get_box(obbs[i]); centers[i] = obbs[i].pos; } }); typename bvh::v2::DefaultBuilder<Node>::Config config; config.quality = bvh::v2::DefaultBuilder<Node>::Quality::High; auto bvh = bvh::v2::DefaultBuilder<Node>::build(thread_pool, bboxes, centers, config);You can get the AABB of an OBB this way (you do not need to transform the 8 points of a 3D OBB):
// Assuming the corners are obtained by multiplying the matrix with (+-1, +-1, +-1) struct OBB { Mat3x3 mat; Vec3 pos; }; inline Box3 get_bbox(const OBB& obb) { auto abs_mat = abs(obb.mat); auto half_extents = abs_mat * Vec3 { 1, 1, 1 }; return Box3 { obb.pos - half_extents, obb.pos + half_extents }; };
Thanks, that works! But what about updates/refitting? In version 1 I could use the HierarchyRefitter
, but I see no equivalent in version 2. I create the bvh like you describe:
bvh = ::bvh::v2::DefaultBuilder<pragma::bvh::Node>::build(GetThreadPool(), bboxes, centers, config);
After creation I need to update the bboxes/centers every frame, but I see no way to access those after the bvh has been built. Can the ReinsertionOptimizer
be used for refitting somehow?
::bvh::v2::ReinsertionOptimizer<Node>::optimize(GetThreadPool(), bvh);
from bvh.
I need example for use in vulkan, for example.
Bvh can be create on CPU but usage on GPU
from bvh.
I need example for use in vulkan, for example. Bvh can be create on CPU but usage on GPU
Just look at the traversal code in bvh.h
. You can also look at https://madmann91.github.io/2021/01/06/bvhs-part-2.html for an introduction to BVH traversal. This article contains implementation code that you can just port to your target language (GLSL/HLSL).
from bvh.
Related Issues (20)
- raw, bvh node data to upload to the gpu HOT 1
- `build()` in debug build of v2 feels slower than v1 HOT 2
- Recovering "split axis" from MiniTreeBuilder HOT 1
- Face culling options? HOT 1
- Your code is building fine on MSYS2 MINGW64 HOT 1
- Two tests need pthread to compile on linux HOT 2
- Library does not handle rays parallel to axes HOT 5
- Identifiers near and far in bvh.h cause issues when precompiled headers are used HOT 3
- config.min_leaf_size > 1 Leads to assertion failure HOT 1
- What is the use case? is it slower than embree? HOT 1
- Cancel build +progress monitor HOT 4
- Consider adding to vcpkg HOT 1
- Ability to re-use BVH allocations? HOT 1
- Adding and Removing elements HOT 1
- Optimize node index serialization HOT 1
- Clarify what primitive data leaf nodes actually store HOT 1
- Potential bug in traversal functions HOT 1
- Possible stale pointer usage in extract_bvh()? HOT 4
- Sweep SAH builder HOT 4
- ReinsertionOptimizer sometimes gets stuck in an infinite loop HOT 16
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bvh.