如何降低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 RenderersTrail RenderersLine RenderersParticle 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. 【requirejs】JS模块化工具requirejs教程

    初识requirejs 随着网站功能逐渐丰富,网页中的js也变得越来越复杂和臃肿,原有通过script标签来导入一个个的js文件这种方式已经不能满足现在互联网开发模式,我们需要团队协作.模块复用.单元 ...

  2. LG3960 列队

    题意 传送门 分析 参照博客 树状数组+离线处理即可. 利用树状数组下标本质即可\(O(\log n)\)求第k大. 代码 #include<iostream> #include<c ...

  3. quick 状态机StateMachine

    function Player:addStateMachine() self.fsm_ = {} cc.GameObject.extend(self.fsm_) :addComponent(" ...

  4. ecmall2.3.0 前后台样式等无效,导致前台页面显示不正常问题解决

    问题一:按照安装手册安装及数据初始化后,前后台中文均出现乱码 解决方法:在upload/index.php 和 upload/admin/index.php 头上加上header("Cont ...

  5. Charles 协助解决 metaweblog 排序问题

    Charles 是 http代理抓包工具,可有效用于手机客户端网络抓包,详见Charles安装说明.这里使用使用Charles的请求转发功能调试metaweblog的最近博文排序功能. 由于OpenL ...

  6. android视频处理相关资料

    <开源>基于Android的点对点视频通信/RTSP/RTP/H.264 http://blog.csdn.net/cazicaquw/article/details/8650543 历经 ...

  7. hsqldb简单使用总结

      hsqldb数据库是一款纯Java实现的开源免费数据库,相对其他数据库来说,体积非常小,使用方便,非常利于在测试环境中使用,无需复杂的数据库配置.   hsqldb数据库引擎有几种服务器模式:Se ...

  8. 20181106_线程之异常_取消_变量_安全Lock

    一. 线程的异常处理: try { TaskFactory taskFactory = new TaskFactory(); List<Task> taskList = new List& ...

  9. python学习(二十七) 元组

    # 元组是不可变的,不能改变元素的值,也不能增加.减少元素my_tuple = (1, 2, 3, 3)print(my_tuple) # 查找元素位置print(my_tuple.index(2)) ...

  10. 在Centos中导入sql文件的方法

    在Centos中导入sql文件的方法 利用mysql -u root -p进入mysql数据库 对于文件的导入,在Centos下里面的是首先要新建一个和文件相同名字的数据库.例如:mysql>c ...