Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow performance with axis aligned ray #21

Closed
stephomi opened this issue Dec 14, 2020 · 5 comments
Closed

Slow performance with axis aligned ray #21

stephomi opened this issue Dec 14, 2020 · 5 comments

Comments

@stephomi
Copy link

stephomi commented Dec 14, 2020

Great lib!

However I get very low performance when casting axis-aligned rays.
It takes 7 seconds or so, instead of ~10ms (~30k rays on a ~3M meshes, the mesh has axis aligned triangles as well).

When I add a small epsilon to the ray to make sure all components are non null, things become fast again.

I didn't dig the issue further.
I can just say there is no division by 0 here

auto inv_det = Scalar(1.0) / dot(n, ray.direction);

@madmann91
Copy link
Owner

madmann91 commented Dec 15, 2020

Hello, and thank you for the bug report. Are you on x86? If so, can you try adding the following code before doing anything (you need to include x86intrin.h)?

_mm_setcsr(_mm_getcsr() | (_MM_FLUSH_ZERO_ON | _MM_DENORMALS_ZERO_ON));

Regardless if this solves your issue or not, could you point me to more information to reproduce the bug? And maybe point me to a scene I could use to reproduce this?
Edit: Nevermind, I think I managed to reproduce that bug with an orthographic camera on one of my test scenes.

@madmann91
Copy link
Owner

I'm working on a fix. It seems that bvh::RobustNodeIntersector is not affected by the issue. You can try using that in the mean time. To do that, create the single ray traverser with that as a template parameter:

bvh::SingleRayTraverser<Bvh, 64, bvh::RobustNodeIntersector<Bvh>>

madmann91 added a commit that referenced this issue Dec 15, 2020
…false positives in the node-ray intersection function
@madmann91
Copy link
Owner

This issue should now be fixed by 3b2f3d0 (and following bug fix 354de26). This performance problem was caused by too many false positives in the ray-node intersection during BVH traversal. The fix introduced here will just prevent the traversal from processing nodes in that case, but keep in mind that bvh::FastNodeIntersector is anyway an intersector that loses precision for ray directions that are close to zero. That should not be a problem in most use cases, but you may want to switch to the robust intersector when you observe artefacts due to the ray missing the geometry. Could you please check that the issue is fixed on your end as well?

@stephomi
Copy link
Author

Yes it works!

I'm using the bvh to project a mesh onto another, so the rays are generated for each vertices (the ray length are very short as the 2 meshes are somewhat identical).

@madmann91
Copy link
Owner

Alright, then I'm closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants