官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 博兴县| 梅河口市| 邳州市| 贡嘎县| 日照市| 长沙县| 海城市| 外汇| 石城县| 宁阳县| 乌海市| 遂川县| 溧阳市| 永福县| 色达县| 凌海市| 绥中县| 舒兰市| 清新县| 沭阳县| 张家口市| 横峰县| 大庆市| 武乡县| 察隅县| 古丈县| 平舆县| 儋州市| 卓资县| 顺平县| 宝清县| 宣城市| 芦溪县| 南通市| 增城市| 和田县| 兰考县| 天峨县| 固始县| 崇阳县| 孙吴县|