-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
BatchedMesh: add support for frustum culling per batched geometry #27120
Conversation
So the PR adds a frustum culling check for each geometry of the batched mesh in This is a different strategy to what is implemented in other classes. Normally, I would have expected bounding volumes on batched mesh level (similar to I think it would be more consistent to implement the bounding volume computation according to this policy for batched mesh as well. |
To be clear you're suggesting that we only generate bounding volumes on an as-needed basis for BatchedMesh, correct? I can adjust that if that's correct.
This case is a bit different, though, since we're talking about a geometry that could have hundreds or thousands of bounding boxes - only one of them could be invalidated. I'm thinking adding an optional argument to "setGeometryAt" that indicates that the bounds should be invalidated is a good option. |
# Conflicts: # examples/jsm/objects/BatchedMesh.js
Yes.
If you think it's important to have bounding volumes for each geometry of the batched mesh then I'm fine with that. But it would be good to add Ideally, frustum culling and raycasting test with the object level bounding volumes first, and then with the ones on geometry level. |
I don't know if I agree that this is as useful - but I can support keeping the ability. I'd want the ability to disable that feature, though, since keeping the full bounding box up to date with many dynamic objects spread throughout the scene is not super useful. In this case how do you feel about a different field like "perObjectFrustumCulled" or "batchFrustumCulling" that can be set to toggle the the "onBeforeRender" frustum culling feature? Also I just updated the PR to generate the boxes and spheres as-needed. When a geometry is replaced the existing bounding box is used or it's marked as needing to be regenerated. |
That sounds good to me! However, in order to keep the class consistent I would be glad to see the object level features mentioned in #27120 (comment). It's right that bounding volumes which enclose the entire batched mesh might not be useful for stuff like tiles rendering. But other scenarios might benefit from sorting out the entire batched mesh when rendering/raycasting. By implementing this approach, we keep the class consistent with |
Okay! I've just added "perObjectFrustumCulled" flag.
I'll add this in another PR, then. I guess one concern I have for things like raycasting or frustum culling when elements are dynamic (meaning the bounding volumes have to be regenerated every frame) is that the cost of regenerating the bounding box and / or sphere is more expensive than just checking the ray / frustum intersection with the child bounding boxes. Instancing would have the same issue, though I guess this would have to be tested. |
@Mugen87 I just updated the copy and toJSON functions to add support for bounds and perObjectFrustumCulled flag. This should be ready! |
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
.multiply( this.matrixWorld ); | ||
_frustum.setFromProjectionMatrix( | ||
_projScreenMatrix, | ||
_renderer.isWebGPURenderer ? WebGPUCoordinateSystem : WebGLCoordinateSystem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think something like _renderer.backend !== undefined ? _renderer.backend.coordinateSystem : WebGLCoordinateSystem
would be more correct. /ping @gkjohnson
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar enough with WebGPURenderer to know
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sunag What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can use _renderer.coordinateSystem
, it is compatible with both renderers.
Related issue: #22376, #27111
Description
Add support for frustum culling to BatchedMesh by storing the box and sphere bounds per geometry.
Upcoming PRs