如何降低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

  

    

时间: 2024-08-03 23:28:32

如何降低Unity程序的Drawcall的相关文章

unity程序材质ProceduralMaterial使用

有些效果是用substance的材质,但是材质上的属性无法用平常的Material方法调用,需要ProceduralMaterial去调用, using UnityEngine; using System.Collections; public class TestProceduralMaterial : MonoBehaviour { public GameObject TestCube; public Texture2D tex; public ProceduralMaterial mate

关于Unity程序在IOS和Android上显示内嵌网页的方式

近期因为有须要在Unity程序执行在ios或android手机上显示内嵌网页.所以遍从网上搜集了一下相关的资料.整理例如以下: UnityWebCore 从搜索中先看到了这个.下载下来了以后发现这个的原理好像是通过调用浏览器内核.然后将网页渲染到mesh的方式完毕的. 但遗憾的是仅仅支持windows桌面版本号.但还是发出来大家假设有须要能够下载  下载地址: http://pan.baidu.com/s/1nt3FVkd unity-webview 这个是在github上找到的. 是一个kei

一台主机多开Unity程序,显示在多个显示器上

记录一个坑. 最近项目需要,一台主机带多台显示器,然后运行多个Unity程序. 1.连接显示器,设置为扩展模式. 2.编写代码, using UnityEngine; public class MyDisplay : MonoBehaviour { [SerializeField] public int displayIndex; //显示器编号 void Awake() { if (Display.displays.Length > 1) { Display.displays[displayI

Unity RenderPath与Drawcall

考察render path与drawcall的关系,每个camera可以单独设置render path.以计算光照,不考虑batching,且只有一个PASS的材质为样本,比如Diffuse:如果材质不受光照影响,则跳过光照相关的PASS,比如Unlit/Texture. 1.Forward Path. 最亮的directional light(自动成为pixel light)与其他的非pixel light一起被forward base PASS一次性绘制.其余的important light

Unity性能优化-DrawCall

1. DrawCall是啥?其实就是对底层图形程序(比如:OpenGL ES)接口的调用,以在屏幕上画出东西.所以,是谁去调用这些接口呢?CPU.比如有上千个物体,每一个的渲染都需要去调用一次底层接口,而每一次的调用CPU都需要做很多工作,那么CPU必然不堪重负.但是对于GPU来说,图形处理的工作量是一样的.所以对DrawCall的优化,主要就是为了尽量解放CPU在调用图形接口上的开销.所以针对drawcall我们主要的思路就是每个物体尽量减少渲染次数,多个物体最好一起渲染. 2. 优化方式 (

Unity程序协同问题,传送时屏幕变黑变亮的解决,常规操作的行为集合

在unity中运行某段程序时往往需要运行另外一段不相干但是却对功能上有需求的程序,比如进行场景传送,在传送点处,点击I键,屏幕慢慢变黑,场景传送到另外一个场景,场景又慢慢变亮.这里首先涉及两个物体,一个是传送触发器物体,点击I键,过一段时间后进行场景传送,另外一个就是遮罩物体,这里使用UGUI中的Panel,变黑和变亮主要修改它的透明度.达成上诉效果可以使用到以下几种方式:一,将panel物体作为触发器物体的参数物体,触发其物体执行panel中的代码,或者直接对panel物体进行操作.二,消息传

Android 降低应用程序版本

作者 : 卿笃军 原文地址:http://blog.csdn.net/qingdujun/article/details/39587893 今天在网上下载了一个Android Demo,发现版本号是android-19(4.1.2),而我自己的手机版本是android-15(4.0.3)所以需要降低系统版本要求. 将网上搜索的资料整理一下,具体做法如下: 1.打开project.properties文件,将target=Google Inc.:Google APIs:19 替换为target=G

unity panel删除drawcall失败导致的残留影像

ngui panel 被隐藏或者删除的时候调用ondisable,清空drawcall,如果这个操作是在ontriggerenter等物理操作中就会删除不掉导致留下残影 解决方式 : 讲这些操转移到协程中处理,比如这样 void OnTriggerEnter(Collider other) { // Destroy(gameObject); StartCoroutine(Dest()); } IEnumerator Dest() { yield return new WaitForSeconds

Unity程序优化之对象池

对于做程序的朋友来说优化是一个避免不了的话题,对于程序的优化可以从两个方面来入手,一个是CPU方面的优化,一个是GPU的优化.对于CPU与GPU的作用简单理解的话你可以暂时当做CUP是处理计算的.GPU是处理渲染的,例如程序中的一些计算啊逻辑处理啊都是有CPU来处理的,,我们程序的显示啊,特效等一切看到的东西都是GPU来处理的.当然他们的关系不单单如此,扯远了哈,我们这篇博客主要讲CPU优化方面的对象池技术.对象池大家应该都听说过,它主要应用于处理需要大量重复利用的资源的,因为如果有很多资源如果