# 3D dynamic batch
# Features
In the process of drawing the scene in the mini game framework, for each MeshRenderer, a DrawCall will be generated for each SubMesh. In the case of too many objects in the scene, rendering overhead will become very large.
If there are many small objects with the same materials in the scene, you can consider turning on 3D dynamic batching to speed up rendering.
After enabling 3D dynamic batching, CPU performance will be consumed to reduce the burden on GPU, and objects of the same material will be combined into a DrawCall.
# Usage restrictions and potential usage scenarios
Not using 3D dynamic batching in any scene can achieve optimized results. In fact, in most cases, opening 3D dynamic batching will only produce negative optimization.
First of all, please make sure that there are many objects in the scene that use the same material, and these objects are all objects that are not too complicated (the number of vertices is small).
Secondly, please make sure that these objects not all use the same model. If the 3D dynamic batch objects all use the same model, please use GPU Instantiation instead, Will get better performance.
Finally, the best scenario for using 3D dynamic batching is that the batched objects are all dynamic objects, and their positions may change every frame. If the batched objects are all static objects, then the scene objects will be statically batched to get better results. Since the small game framework does not yet provide static batching auxiliary tools, developers can choose to use 3D dynamic batching instead, or find a third-party static batching tool.
# Instructions
# 1. Turn on the dynamic batch switch
On all the MeshRenderer
components that want to be dynamically batched, check the dynamicBatch
option.
# Second, control the rendering order of batched objects
It is necessary to manually ensure that the 3D batched objects are rendered in a batch, and no other objects that cannot be batched can be inserted in the batch.
The rendering order of objects in the scene is controlled by the renderQueue
on material, and objects with the same renderQueue
will be drawn in one batch. Therefore, if you want to render 3D batched objects in one batch, you need to manually modify their materials (should be the same), and set renderQueue
to a value different from any other objects in the scene.
# ▌Multiple SubMesh
Even if there are multiple SubMesh on MeshRenderer
, you can also perform 3D dynamic batching. Just make sure to use a different material SubMesh with a different renderQueue
.
# Difference from GPU instantiation
GPU instantiation requires the same model and higher performance than 3D dynamic batching.