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

Consider storing axis of separation in nodes when splitting #34

Closed
mqp opened this issue Sep 21, 2018 · 2 comments
Closed

Consider storing axis of separation in nodes when splitting #34

mqp opened this issue Sep 21, 2018 · 2 comments

Comments

@mqp
Copy link
Contributor

mqp commented Sep 21, 2018

Physically Based Rendering had this great suggestion for improving raycasting performance. Ordinarily, if you want to find only the closest intersection for your ray, you need to test your ray against both bounding volumes at each level of the tree hierarchy, and take whichever has the intersection with the closest distance, because it could intersect both. But if you use an SAH strategy and you remember at each node which axis was used for splitting, you can look at where the ray is coming from with respect to the split plane and you know right away which child bounding volume must have the closest intersection, if it intersects that bounding volume at all. You may not have to even look at the other one.

Of course this will cost a little memory but it sounds like it might improve raycasting firstHitOnly performance very substantially.

@gkjohnson
Copy link
Owner

I believe we're already doing this in raycastFirst here:
https://github.com/gkjohnson/threejs-fast-raycast/blob/master/lib/MeshBVHNode.js#L64

It's not exactly the same approach but I believe it has the same effect and doesn't take any extra memory. Basically we check which node is closest to the ray and traverse that first. If no triangle is hit then we check the other node.

We don't do this in the regular raycast function, though -- I don't think there's a reason to?

@mqp
Copy link
Contributor Author

mqp commented Sep 21, 2018

Good point, I can't see why that approach would be any less effective at determining which to examine. The axis-remembering one seems more efficient per raycast (you will just have to check a single coordinate of the ray instead of doing the bit of vector math we do there) but I don't know if the gain would be worth the cost of storing the extra field.

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