-
Notifications
You must be signed in to change notification settings - Fork 54
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
Batched Rendering #1023
Batched Rendering #1023
Conversation
fbaa19b
to
bc3b9a4
Compare
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.
Well that is certainly something...
// obj.mirabufInstance.meshes.get(part)!.forEach(mesh => { | ||
// // iterating through each mesh and updating their position and rotation | ||
// mesh.position.setFromMatrixPosition(partTransform) | ||
// mesh.rotation.setFromRotationMatrix(partTransform) | ||
// }) |
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.
Saving this?
// this._mirabufInstance.meshes.get(part)!.forEach(mesh => { | ||
// mesh.position.setFromMatrixPosition(partTransform) | ||
// mesh.rotation.setFromRotationMatrix(partTransform) | ||
// }) |
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.
Saving this?
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.
Besides the comments it looks good
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.
Awesome! With two 2471s, went from 19 fps to 34.
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.
So fast.....
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.
🚀 Blazingly Fast 🚀
Description
WebGL attempts to give JavaScript native speeds when it comes to rendering; however, it tends to fall short due to translation and overhead with every WebGL to OpenGL call it makes. A significant gain in performance can be achieved by reducing the number of calls you make to the GPU. Enter: Batch Rendering
Batch Rendering
Normally you have buffers on your GPU when all the necessary rendering data, then you call draw on a set buffer (or buffers if you're using indexing) and it draws it to the screen. Without batching, you must make a draw call, separately, for every mesh you want to rendering. With batch rendering, you can merge multiple meshes that all use the same shader program into a single buffer, then make one draw call for multiple meshes.
If you're interesting in learning more about how batch rendering works, I strongly suggest taking a minute to watch this video from The Cherno.
Implementation Details
I separate each assembly into a BatchedMesh for each material that is used in the assembly. I work backwards, first categorizing each mesh by first material, then geometry, and finally part instance. While doing so I keep tallies to know how big the batches need to be. Then, the batches are constructed, along with a map pointing each part instance to a given set of tuples, correlating where the geometry of a given body.
Performance Improvements
System
For the following data, I used my desktop computer, which has a RTX 3060 with 12GB GDDR6, running Chrome.
To collect the data I used a combination of the Stats react component, the Chrome profiler, and a custom print out telling me the number of triangles and draw calls in a given update loop.
Testing Details
I compared this branch with the latest
dev
branch at the time (specific commit). In each branch, I had the default 2018 mean machine spawn in, let it fall to the ground, spawn the 2018 FRC field, keep it where it was, and then finally spawn in the 2018 mean machine robot again, and place it to the left of the scale, in front of the platform.Branch:
dev
Branch:
barclah/batching
Results
Notes