博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Graphics.DrawMeshInstanced
阅读量:4506 次
发布时间:2019-06-08

本文共 1817 字,大约阅读时间需要 6 分钟。

Draw the same mesh multiple times using GPU instancing.
可以免去创建和管理gameObj的开销
并不是立即绘制,如需:Graphics.DrawMeshNow
每帧调用一次,当帧发送绘制请求
Meshes are not further culled by the view frustum or baked occluders, nor sorted for transparency or z efficiency.
You can only draw a maximum of 1023 instances at once
SE 3.0 以上支持
材质要勾上 enableInstancing  
总的检查:material.enableInstancing && SystemInfo.supportsInstancing 
过程中遇到的问题:
导入mesh,的Use File Scale 勾上就不显示??? 模型的缩放调整有问题,去掉后原本的模型直接放显得特别大
1146702-20171025175828504-887343071.jpg
感觉像是这个函数强行用了一次file scale,再用会变得更小(函数自身*导入参数)
去掉设置,这个函数的变正常,但直接拖到游戏就不对,应该是个bug
public class GpuInstancingTest : MonoBehaviour {	public Mesh mesh;	public Material material;		List
matrices = new List
(); void Start() { if (!material.enableInstancing || !SystemInfo.supportsInstancing) { enabled = false; return; } for (int i = 0; i < 10; ++i) { Matrix4x4 mt = Matrix4x4.TRS(transform.position + (i * 1.1f) * Vector3.up, transform.rotation, Vector3.one); matrices.Add(mt); } } // Update is called once per frame void Update () { Graphics.DrawMeshInstanced(mesh, 0, material, matrices); }}
x
26
 
1
public class GpuInstancingTest : MonoBehaviour {
2
public Mesh mesh;
3
public Material material;
4
 
5
List
matrices = new List
();
6
 
7
void Start()
8
{
9
if (!material.enableInstancing || !SystemInfo.supportsInstancing)
10
{
11
enabled = false;
12
return;
13
}
14
 
15
for (int i = 0; i < 10; ++i)
16
{
17
Matrix4x4 mt = Matrix4x4.TRS(transform.position + (i * 1.1f) * Vector3.up, transform.rotation, Vector3.one);
18
matrices.Add(mt);
19
}
20
}
21
 
22
// Update is called once per frame
23
void Update () {
24
Graphics.DrawMeshInstanced(mesh, 0, material, matrices);
25
}
26
}

转载于:https://www.cnblogs.com/Hichy/p/7730353.html

你可能感兴趣的文章
Node ejs
查看>>
android viewpager切换到最后一页时,跳转至其他activity
查看>>
centos查看实时网络带宽占用情况方法
查看>>
LINQ to SQL语句(3)之Count/Sum/Min/Max/Avg
查看>>
选择排序
查看>>
vs2008 ole excel
查看>>
Java之为何配置环境变量
查看>>
博客框架推荐
查看>>
下载并安装Prism5.0库 Download and Setup Prism Library 5.0 for WPF(英汉对照版)
查看>>
Sql server 系统表
查看>>
实现三级联动下拉框&nbsp;下拉列表… 分类: Android开发 ...
查看>>
Android的股票widget源代码 分类: Android开发 ...
查看>>
android开源项目和框架ZZ 分类: Android开发 ...
查看>>
转载:Window Azure 中的Web Role详解
查看>>
win7 关闭防火墙
查看>>
邮件操作类
查看>>
MySQL on Azure高可用性设计 DRBD - Corosync - Pacemaker - CRM (一)
查看>>
三角形的内切圆与外接圆面积之比【几何计算】
查看>>
递归程序练习:输出十进制数的二进制表示
查看>>
2287 火车站
查看>>