【如何降低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则影响很明显。

  

  Currently, only Mesh Renderers、Trail Renderers、Line Renderers、Particle Systems and Sprite Renderers  are batched. This means that skinned Meshes, Cloth, and other types of rendering components are not batched.

  Skinned Meshes 不能被合批。  

一、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、Using different Material instances causes GameObjects not to batch together, even if they are essentially the same. The exception is shadow caster rendering.

    使用同一个Material实例。

  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、 GameObjects are not batched if they contain mirroring on the transform (for example GameObject A with +1 scale and GameObject B with –1 scale cannot be batched together).

    scale正负值相反的,没法动态合批。

  6、Almost all Unity Shaders support several Lights in forward rendering, effectively doing additional passes for them. The draw calls for “additional per-pixel lights” are not batched.

    前身渲染中的 additional pass不会被合批。 

什么时候动态合批才有用?

  Because it works by transforming all GameObject vertices into world space on the CPU, it is only an advantage if that work is smaller than doing a draw call. The resource requirements of a draw call depends on many factors, primarily the graphics API used. For example, on consoles or modern APIs like Apple Metal, the draw call overhead is generally much lower, and often dynamic batching cannot be an advantage at all.

  合批要把 vertex 转换到 world space。所以只有在 draw-call 时间大于 vertex transformation 时间时,合批才有效。在Apple的Metal上,draw-call 的开销已经非常小了,所以动态合批没有什么价值。

二、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的更多相关文章

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

    近期因为有须要在Unity程序执行在ios或android手机上显示内嵌网页.所以遍从网上搜集了一下相关的资料.整理例如以下: UnityWebCore 从搜索中先看到了这个.下载下来了以后发现这个的 ...

  2. 【拥抱元宇宙】创建你的第一个Unity程序HelloWorld,并发布

    第一个Unity程序--Hello World. 1.需要先下载一个Unity Hub,以及安装Unity编辑器.Unity Hub需要登陆,激活码可以选择个人用户,免费的.免费的无法改变启动画面,其 ...

  3. Unity性能优化-DrawCall

    1. DrawCall是啥?其实就是对底层图形程序(比如:OpenGL ES)接口的调用,以在屏幕上画出东西.所以,是谁去调用这些接口呢?CPU.比如有上千个物体,每一个的渲染都需要去调用一次底层接口 ...

  4. 面向Unity程序员的Android快速上手教程

    作者:Poan,腾讯移动客户端开发 工程师 商业转载请联系腾讯WeTest获得授权,非商业转载请注明出处. WeTest 导读 随着Unity.cocos2dx等优秀跨平台游戏引擎的出现,开发者可以把 ...

  5. Unity程序们经常用到的网址(方便自己用,一直更新)

    浏览器收藏夹不好用,那就整理到这里吧 官方 API查询: https://docs.unity3d.com/ScriptReference/index.html 文档查询:https://docs.u ...

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

    在unity中运行某段程序时往往需要运行另外一段不相干但是却对功能上有需求的程序,比如进行场景传送,在传送点处,点击I键,屏幕慢慢变黑,场景传送到另外一个场景,场景又慢慢变亮.这里首先涉及两个物体,一 ...

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

    ngui panel 被隐藏或者删除的时候调用ondisable,清空drawcall,如果这个操作是在ontriggerenter等物理操作中就会删除不掉导致留下残影 解决方式 : 讲这些操转移到协 ...

  8. 向.Net/Unity 程序员推荐一个十分因吹斯听的网站:sharplab.io

    0x00 前言 & 过程 & 结论 今天发现了一个十分有趣的网站: https://sharplab.io/ 网站的页面并不复杂,功能大体上能够在题图中得到概括.发现它的过程也很偶然, ...

  9. NGUI 降低drawcall

    前置说明一: Unity中的drawcall定义: 每次引擎准备数据并通知GPU的过程称为一次Draw Call. Unity(或者说基本全部图形引擎)生成一帧画面的处理过程大致能够这样简化描写叙述: ...

随机推荐

  1. 开启opcache提高性能

    在开启opcache之前,我们先介绍一下编译与解释: 编译器是把源程序的每一条语句都编译成机器语言,并保存成二进制文件,这样运行时计算机可以直接以机器语言来运行此程序,速度很快:而解释器则是只在执行程 ...

  2. JDBC的概念、实现原理与连接数据库的几种方法

    1.首先要知道jdbc(概念): 使用Java代码发送sql语句的技术就是jdbc技术(jdbc英文全称:Java DataBase Connectivity,java数据库连接).即jdbc是一个接 ...

  3. [转]nginx虚拟目录(alias与root的区别)

    今天配置awstats,awstats创建出的文件目录在/home/awstats下,在nginx中加入配置后狂报404,发现还是忽略了root和alias的区别,特将修改配置记录如下: 1.失败:s ...

  4. golang获取packed struct的大小

    网络协议里面,很可能遇到自定义的封包,对应到c里面的是 typedef struct _PackageHeader { int headerLen; int timeStamp; short cmd ...

  5. 0基础自学php教程

    轻松搞定网页设计之html 一.HTML介绍 1. HTML概念 HTML(Hyper Text Markup Language),即超文本标记语言.是目前网络上应用最为广泛的语言,是构成网页文档的主 ...

  6. java代码----------实现创建DataInputStream和DataOutputStream进行读写

    总结: 主要是 捕获异常 package com.a.b; import java.io.*; public class testData { public static void main(Stri ...

  7. python高手的自修课

    python高手的自修课 作者:相国大人 目录 0.第0课:前言与参考文献 目标读者: 具有一定python基础的编程爱好者. 本系列博文为了尽可能少说废话,凡是能够用代码表达的,都尽量直接用代码.读 ...

  8. iis 重新安装后 重新注册asp.net

    服务器IIS问题: 卸载并重新安装了IIS.... 解决方法:原因是IIS重装后要重新安装一下.NET Framework. 开始-->运行-->CMD-->然后在CMD窗口中输入命 ...

  9. webpack快速入门(二):使用入门

    继续之前请确认你已经安装了nodejs 安装.初始化: 然后找个目录新建名为webpack-demo的文件夹,然后在命令行下进入该目录,执行以下命令: npm init -y npm install ...

  10. php网站环境无法上传的解决办法?

    一. 检查网站目录的权限.二. php.ini配置文件php.ini中影响上传的有以下几处:file_uploads 是否开启 on 必须开启是否允许HTTP文件上传post_max_size = 8 ...