从Unity5.4开始,多了一个叫做GPU instancing的功能。这个功能是做什么用的呢?下面做一个小例子来说明一下:
还是之前做 MaterialPropertyBlock的例子,在屏幕上面做了很多的cube,然后随机给颜色,使用MaterialPropertyBlock的方式设置颜色值。

可以看到,正常情况下,在改变完颜色之后,Batches有75个,而SetPass calls有75个。

下面换成GPU instancing的做法,同样的效果,可以看看数据:

和之前完全一样的视觉效果,但Batches和SetPass calls都变成只有11了。

这是怎么做到的呢?
首先 ,我们必须是使用MaterialPropertyBlock来设置材质的属性,因为如果用传统的设置颜色,会把材质生成多个实例,这样就没有办法合并了。使用MaterialPropertyBlock由于从始至终只有一个material,所以它们才可以合并。
然后,需要特殊的shader来配合工作。在Unity5.4和5.5版本,都可以看到在创建shader的时候,多了一个选项Standard Surface Shader(Instanced)。这个shader类型就是支持GPU Instancing的。到了Unity5.6这个选项已经消失了,因为默认创建的Standard Surface Shader已经支持GPU Instancing了。

当然了,我们不可能每个地方都用 Standard Surface Shader这种消耗特别大的shader,所以我们也可以手动的修改自己写的shader,官方的文档里面也有说明:

pragma multi_compile_instancing Use this to instruct Unity to generate instancing variants. It is not necessary for surface Shaders.

UNITY_VERTEX_INPUT_INSTANCE_ID Use this in the vertex Shader input/output structure to define an instance ID. See SV_InstanceID for more information.
UNITY_INSTANCING_CBUFFER_START(name) /UNITY_INSTANCING_CBUFFER_END Every per-instance property must be defined in a specially named constant buffer. Use this pair of macros to wrap the properties you want to be made unique to each instance.
UNITY_DEFINE_INSTANCED_PROP(float4, _Color) Use this to define a per-instance Shader property with a type and a name. In this example, the _Color property is unique.
UNITY_SETUP_INSTANCE_ID(v); Use this to make the instance ID accessible to Shader functions. It must be used at the very beginning of a vertex Shader, and is optional for fragment Shaders.
UNITY_TRANSFER_INSTANCE_ID(v, o); Use this to copy the instance ID from the input structure to the output structure in the vertex Shader. This is only necessary if you need to access per-instance data in the fragment Shader.
UNITY_ACCESS_INSTANCED_PROP(color) Use this to access a per-instance Shader property. It uses an instance ID to index into the instance data array.
举例说,我们可以在shader里面添加:
UNITY_INSTANCING_CBUFFER_START(Props)
UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color) // Make _Color an instanced property (i.e. an array)
UNITY_INSTANCING_CBUFFER_END
让它支持GPU Instancing。

在Unity5.4和5.5版本,只要你的Shader支持,自动就会开启GPU Instance。到了Unity5.6,在材质选项里面会多了一个勾选:

这是一个开关。假如你不勾选,就算你的shader是支持的,GPU Instance功能也不会生效。

GPU instancing介绍相关推荐

  1. Unity3D GPU Instancing测试

    GPU instancing 很早就支持手机了(Android只支持Opengl ES 3.0),最近在调研这个就对它测试了一下. 如果是不动的物体勾选static静态合并批次(40-50帧率) 自定 ...

  2. 【Unity游戏开发】静态、动态合批与GPU Instancing

    https://zhuanlan.zhihu.com/p/356211912 前言 动态合批与静态合批其本质是对将多次绘制请求,在允许的条件下进行合并处理,减少cpu对gpu绘制请求的次数,达到提高性 ...

  3. U3D 文档 GPU INSTANCING

    https://docs.unity3d.com/Manual/GPUInstancing.html 归纳总结: 一,快速使用U3D 的GPU 实例化功能 1,选择一个shader,勾选 enable ...

  4. Unity GPU Instancing的使用尝试

    似乎是在Unity5.4中开始支持GPU Instacing,但如果要比较好的使用推荐用unity5.6版本,因为这几个版本一直在改. 这里测试也是使用unity5.6.2进行测试 在5.6的版本里, ...

  5. 每天执行一次批处理_关于静态批处理/动态批处理/GPU Instancing /SRP Batcher的详细剖析...

    静态批处理[1] 定义 标明为 Static 的静态物件,如果在使用相同材质球的条件下,在Build(项目打包)的时候Unity会自动地提取这些共享材质的静态模型的Vertex buffer和Inde ...

  6. 闲云野鹤:吃鸡(一)之场景制作:使用GPU instancing方式制作刷草插件

    用GPU instancing方式制作刷草插件(unity版本8.2.2) 先上最终效果图(欢迎加我qq交流:358641634): 十种草 混刷生成比较自然的场景(带阴影.风力.草可见距离可调) 插 ...

  7. Unity的GPU Instancing

    Unity的GPU Instancing GPU Instancing可以用来批量绘制大量相同几何结构相同材质的物体,以降低绘制所需的batches.要想在Unity中使用,首先需要至少在shader ...

  8. unity gpu instancing

    Unity gpu instancing unity可以自动合并相同的material对象渲染 将对应shader enable instancing的选项勾上 本文说明一下直接调用unity api ...

  9. gpu服务器各硬件的全面认识ppt,GPU服务器介绍.ppt

    文档介绍: --杨跃江2018.3.29宝德GPU服务器介绍Q4'18Q3'19Q2'18Q3'18Q1'18Q2'19Q1'19通用双路服务器Q4'19PR4764GW双路4U4GPUPR2764G ...

最新文章

  1. HTML超文本描述语言,HTML超文本标记语言的介绍
  2. MacroMedia FreeHand 10中文版
  3. 关于“WireX Botnet”事件Android样本分析报告
  4. vCenter 6.0安装部署
  5. 【今晚七点】:对话余世兵——从OnVideo到快手云剪
  6. 密码可逆不可逆选择_膝关节损伤不可逆!跑步要注意!
  7. 数据挖掘—朴素贝叶斯分类算法(Java实现)
  8. pandas用众数填充缺失值_【机器学习】scikit-learn中的数据预处理小结(归一化、缺失值填充、离散特征编码、连续值分箱)...
  9. hadoop 基础命令
  10. Aurora一些使用过程中碰到的问题
  11. flash 与javascrip的t交互和注意事项
  12. 给Bert加速吧!NLP中的知识蒸馏Distilled BiLSTM论文解读
  13. Java从入门到精通 第11章 枚举
  14. 办公、学习不得不收藏的十个网站,有了它效率至少提升十倍
  15. 专访李亚锋:“大数据+”趋势下的电信实践之路
  16. 在小程序内嵌的webview中唤醒手机地图app
  17. 小程序--语音合成tts 对接多平台(讯飞,思必驰,百度)
  18. 1. THE REAL-TIME VOLUMETRIC CLOUDSCAPES OF HORIZON ZERO DAWN
  19. seo与外链绝密技巧珍藏版分享
  20. DS1307驱动代码

热门文章

  1. 实施整体变更控制专业笔记
  2. 全球PML_V2陆地蒸散发与总初级生产力数据集
  3. 域渗透-SPN与kerberoast攻击
  4. 最全的搭建Java的开发环境以及eclipse安装配置开发工具
  5. 名胜古迹扎堆的河北文博园(定州文博园)
  6. Visual Studio2017 15.4提供预览版,面向Windows 10秋季更新(FCU)
  7. On the value of temporal information in information retrieval (完)
  8. Java 坦克大战游戏
  9. Alamofire网络库基础教程:使用 Alamofire 轻松实现 Swift 网络请求
  10. 全知科技CEO方兴:数据流动时代大数据风险是大数据安全的核心