首页 > 代码库 > 如何降低Unity程序的Drawcall

如何降低Unity程序的Drawcall

如何降低Unity程序的Drawcall

  Unity can combine a number of objects at runtime and draws them together with a single draw call. This operation is called “batching”

  每帧能够有多少batch依赖于cpu。每个drawcall提交多少个三角形,对cpu压力变化不大,但是每帧有多少个drawcall则影响很明显。

  

一、Dynamic Batching。

  Dynamic Batching会自动进行。有与顶点呈线性相关的overhead。所以只对顶点数小于900的mesh进行batch。

    1)如果 Position, Normal and Single UV, then you can batch up to 300 verts

    2)Position, Normal, UV0, UV1 and Tangent, then only 180 verts

  动态Batching有以下要求:

  1、合并贴图,材质。

  2、Lightmapped objects s hould point to exactly the same lightmap location to be batched。

       想被batching的对象必须有相同的lightindex、及lightmapoffset/lightmapscale。

  3、Objects that receive real-time shadows will not be batched。

    勾选receive real-time shadow的对象不会被batch

  4、Batching dynamic objects has certain overhead per vertex,If your shader is using Vertex Position, Normal and single UV, then you can batch up to 300 verts; whereas if your shader is using Vertex Position, Normal, UV0, UV1 and Tangent, then only 180 verts.

  5、objects should be using the same transform scale.

 

二、Static Batching。

  Using static batching will require additional memory for storing the combined geometry.  If several objects shared the same geometry before static batching, then a copy of geometry will be created for each object. Sometimes you will have to sacrifice rendering performance by avoiding static batching for some objects to keep a smaller memory footprint.

  使用StaticBatching会产生额外内存使用,因为Unity会把多个对象Join成一个对象。

  StaticBatchingUtility.Combine()告诉UnityEngine把staticRoot作为static对象来处理。

 

  

  once combined children can NOT change their Transform properties, however staticBatchRoot can be moved.

 

三、其它降低Drawcall的方法

1、改变表现方法。如流水粒子改为流水动画。

2、高级特性Shader降级为统一的低级特性的Shader。

参考:

1、file:///C:/Program%20Files%20(x86)/Unity/Editor/Data/Documentation/html/en/ScriptReference/StaticBatchingUtility.Combine.html

2、http://docs.unity3d.com/Manual/DrawCallBatching.html

 

 

  

    

 

如何降低Unity程序的Drawcall