-
-
Notifications
You must be signed in to change notification settings - Fork 35.1k
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
Box3: optimized matrix transform - ApplyMatrix4 #28348
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
Unfortunately this won't work. It only supports affine-transformations in its current form. A similar attempt to change the Perhaps we could introduce an affine only transformation for this? I don't see many reasons to transform a Eitherway, using an affine-transform is likely much more common, and having a specialized function that doesn't incur a 4x performance penalty is probably desirable. @WestLangley @Mugen87 thoughts? |
I think it would be better to test if the matrix is affine, and use the proposed algorithm if it is, and the existing algorithm if it is not. But I would only do that if there is a compelling use case to justify doing so. |
I can provide a few recurring uses for my projects. I often rewrite a custom frustum culling system, which transforms object's AABB to world-space, independant of the default system. I do this for one of two reasons: Either because the default Another common usage has been when building alternative raycasting systems that also don't suffer from the default system traversal / excess of unnecessary information. I did a quick search and every single instance of Also worth mentioning, I already use the proposed method for my own uses. In fact the only reason I noticed that |
I would favor a single code path and not multiple ones depending on the input matrix. I have the feeling this would overcomplicate things. |
I agree. I would prefer to introduce a separate function If that's acceptable, I'll patch the PR. Otherwise, let me know so I can close it. |
Little known optimization for AABB matrix transformation.
Instead of performing a Vec3/Matrix multiplication 8 times (one for each corner), we instead perform only 2.
Once for the center of the box, and a direction transformation (normal-like) for the extent (half-size).
Then we reconstruct the box bounds back in the correct coordinate space.
AABB/Matrix Optimization Blog by Arseny Kapoulkine (Zeux)
Tests, on different devices, show a 3-5x performance gain.