Comments (5)
This is an example file with all triangle data. Surface is a regular grid mesh.
In leaf function I always return false for this example so that I can count all visits. Epsilon is set to 0
for reproducibility. If you set this to std::numeric_limits<float>::epsilon() + 1ulp
traversal works as expected. For now I'll add a small epsilon value until better solution is found.
bvh-issue60.cpp
data.txt
mesh-preview.png
from bvh.
Thank you for fast response and for taking the time to fix the problem.
from bvh.
Here are a couple of things you could try:
- Adding an epsilon to your ray direction/origin,
- Avoiding rays that are very small,
- Using the robust node intersector (
IsRobust = true
),
If none of those things help, please send me a small reproducing example, and I'll have a look at it.
from bvh.
TLDR:
Use master
with the robust intersector.
Long version:
So I did a little investigation and that's what I found:
- You are not setting up the scene properly. Primitives are connected in the wrong way, creating degenerate triangles.
- I fixed that by changing the order in which coordinates are loaded from the stream, and validated it by exporting the result as OBJ and viewing it in Blender.
- With that, the robust intersector was producing fewer traversal steps, but still too much in my opinion, so I dug into the code and fixed a bug where the inverse of the ray direction was computed via
safe_inverse
instead of a direct inverse. - The fast intersector returns wrong results here. That's expected. After all, it's using FMA to compute
(pos - ray.org) / ray.dir
aspos * ray.inv_dir + inv_org_dir
(whereinv_org_dir = -ray.org * ray.inv_dir
). This means that if the direction is zero, thenray.inv_dir == inf
andinv_org_dir == -inf
and therefore the FMA returns NaN. To solve that problem, in fast mode, I don't compute the inverse exactly, but instead useFLT_MAX
as an inverse if the direction is too close to zero. This explains why when the direction is small, the fast intersector returns incorrect results.
from bvh.
Regarding generating an OBJ file and making sure the geometry is correct, here's the relevant code (modified version of your code):
std::fstream stream("data.txt", std::fstream::in);
while (stream) {
Vec3 a, b, c;
// WRONG ORDER:
//stream >> a[0] >> c[1] >> c[2]
// >> b[0] >> b[1] >> b[2]
// >> c[0] >> a[1] >> a[2];
// CORRECT ORDER:
stream >> a[0] >> a[1] >> a[2]
>> b[0] >> b[1] >> b[2]
>> c[0] >> c[1] >> c[2];
if (stream)
precomputed_tris.emplace_back(a, b, c);
}
std::ofstream s("data.obj");
int i = 0;
for (auto& precomp_tri : precomputed_tris) {
auto tri = precomp_tri.convert_to_tri();
s << "v " << tri.p0[0] << " " << tri.p0[1] << " " << tri.p0[2] << '\n';
s << "v " << tri.p1[0] << " " << tri.p1[1] << " " << tri.p1[2] << '\n';
s << "v " << tri.p2[0] << " " << tri.p2[1] << " " << tri.p2[2] << '\n';
s << "f -1 -2 -3\n";
}
from bvh.
Related Issues (20)
- 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
- 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
- Updating node positions and sizes? HOT 3
- Python bindings available? HOT 3
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.