Graphics.DrawMeshInstanced
2024-09-30 20:45:35
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 勾上就不显示??? 模型的缩放调整有问题,去掉后原本的模型直接放显得特别大
感觉像是这个函数强行用了一次file scale,再用会变得更小(函数自身*导入参数)
去掉设置,这个函数的变正常,但直接拖到游戏就不对,应该是个bug
public class GpuInstancingTest : MonoBehaviour {
public Mesh mesh;
public Material material;
List<Matrix4x4> matrices = new List<Matrix4x4>();
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<Matrix4x4> matrices = new List<Matrix4x4>();
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
}
最新文章
- fedora22命令useradd,groupadd等命令不能自动补全
- C++ 基础知识复习(二)
- jQuery下通过$.browser来判断浏览器
- ViewController添加子控制器 并且弹出
- Python学习笔记-Day2-Python基础之列表操作
- 20145120 《Java程序设计》第8周学习总结
- dom4j生成、解析xml
- iPhone开发 Swift - NSNotification 通知
- Struts2.x jsp页面无法使用jsp:forward跳转到action
- A9.linux驱动
- 【译】UI设计基础(UI Design Basics)--iOS应用解析(iOS App Anatomy)(三)
- Java多线程练习
- css阴影--box-shadow的用法
- Dubbo java.io.IOException: Can not lock the registry cache file
- JQuery EasyUI combobox(下拉列表框)
- vue---由nextTick原理引出的js执行机制
- android 知识汇总
- Unix/Linux中/usr目录的由来
- c# 产生随机数 程序所在路径
- vertical-align负值和margin-bottom负值的区别
热门文章
- 洛谷——P3003 [USACO10DEC]苹果交货Apple Delivery
- X shell 6下载安装和简单使用
- subprocess操作命令
- BZOJ 4094 USACO 2013 Dec. Optimal Milking
- 51NOD 1183编辑距离(动态规划)
- Codeforces Educational Codeforces Round 17 Problem.A kth-divisor (暴力+stl)
- orcad中注意的事情
- const int * 和 int * const 傻傻分不清楚
- 控制公司(codevs 2051)
- 藏妹子之处(excel)