- Unity Game Optimization
- Dr. Davide Aversa Chris Dickinson
- 518字
- 2021-06-24 12:13:10
Dynamic batching
Dynamic batching has the following three important qualities:
- Batches are generated at runtime (batches are dynamically generated)
- The objects that are contained within a batch can vary from one frame to the next, depending on what meshes are currently visible to the Main Camera view (batch contents are dynamic)
- Even objects that can move around the scene can be batched (it works on dynamic objects)
These attributes lead us to the name Dynamic Batching.
If we return to the Player Settings page and enable Dynamic Batching, we should see that the number of batches drops from nine down to six. Dynamic Batching automatically recognizes that our objects share material and mesh information and, therefore, combines some of them into a larger batch for processing. We should also see a different list of items in the Frame Debugger, demonstrating that meshes are now being dynamically batched:

As we can see from the Frame Debugger, our four boxes have been combined into a single draw call named Dynamic Batch, but our four spheres are still being rendered with four separate draw calls. This is because the four spheres do not fit the requirements of dynamic batching, despite the fact that they all use the same material. There are many more requirements we must fulfill.
You can find the list of the requirements needed to successfully dynamically batch a mesh in the Unity documentation at this address: http://docs.unity3d.com/Manual/DrawCallBatching.html.
The following list covers the requirements to enable dynamic batching for a given mesh:
- All mesh instances must use the same material reference.
- Only ParticleSystem and MeshRenderer components are dynamically batched. The SkinnedMeshRenderer components (for animated characters) and all other renderable component types cannot be batched.
- There is a limit of 300 vertices per mesh; however, the total number of vertex attributes used by the shader must be no greater than 900. This means that for complex shaders, the maximum number of vertices per mesh may be less than 300 (see the Vertex attributes section for more details).
- The objects must not contain mirroring on the transform (that is, a GameObject A with a positive scale and a GameObject B with a negative scale cannot be batched together).
- Mesh instances should refer to the same lightmap file.
- The material's shader should not depend on multiple passes.
- Mesh instances must not receive real-time shadows.
- There is an upper limit on the total number of mesh indices in the entire batch, which varies for the graphics API and platform used, which is around 32,000–64,000 indices (check out the documentation/previously mentioned blog post for specifics).
It is important to note the term material references because, if we happen to use two different materials with identical settings, the Rendering Pipeline is not smart enough to realize that, and they will be treated as different materials and, therefore, will be disqualified from dynamic batching. Most of the rest of these requirements have already been explained; however, a couple of these requirements are not completely intuitive or clear from their description, which merits some additional explanation.
- 深入理解Bootstrap
- Python自然語言處理實戰:核心技術與算法
- Python從菜鳥到高手(第2版)
- Getting Started with SQL Server 2012 Cube Development
- 從Excel到Python:用Python輕松處理Excel數據(第2版)
- 全棧自動化測試實戰:基于TestNG、HttpClient、Selenium和Appium
- Instant Ext.NET Application Development
- Learning Laravel's Eloquent
- Android開發三劍客:UML、模式與測試
- CRYENGINE Game Development Blueprints
- Training Systems Using Python Statistical Modeling
- ASP.NET jQuery Cookbook(Second Edition)
- Python人工智能項目實戰
- Go語言編程之旅:一起用Go做項目
- 看漫畫學Python:有趣、有料、好玩、好用(全彩版)