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
}







Graphics.DrawMeshInstanced的更多相关文章

  1. 几个Graphics函数

    1.Graphics.Blit:Copies source texture into destination render texture with a shader 声明: 1.public sta ...

  2. Unity GPU Instancing的使用尝试

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

  3. Unity3D学习笔记6——GPU实例化(1)

    目录 1. 概述 2. 详论 3. 参考 1. 概述 在之前的文章中说到,一种材质对应一次绘制调用的指令.即使是这种情况,两个三维物体使用同一种材质,但它们使用的材质参数不一样,那么最终仍然会造成两次 ...

  4. DirectX Graphics Infrastructure(DXGI):最佳范例 学习笔记

    今天要学习的这篇文章写的算是比较早的了,大概在DX11时代就写好了,当时龙书11版看得很潦草,并没有注意这篇文章,现在看12,觉得是跳不过去的一篇文章,地址如下: https://msdn.micro ...

  5. Unity性能优化(4)-官方教程Optimizing graphics rendering in Unity games翻译

    本文是Unity官方教程,性能优化系列的第四篇<Optimizing graphics rendering in Unity games>的翻译. 相关文章: Unity性能优化(1)-官 ...

  6. java工具类之Graphics

    利用重写paint()方法绘画出一个坐标轴: package huaxian; import java.awt.Color; import java.awt.FlowLayout; import ja ...

  7. 解决C# WinForm Graphics绘制闪烁问题

    不直接使用form的CreateGraphics创建Graphics进行绘制,可以先在Form上面放一个需要大小的PictureBox,再创建一个同大小的Bitmap,将这个Bitmap设置为Pict ...

  8. [译]Modern Core Graphics with Swift系列

    第一篇 想象一下你已经完成了你的app并且运行的很好,但是界面看上去太土,你可以在PS里面画好多不同尺寸的自定义控件,Apple并没有4x的retina屏幕. 或者你已经未雨绸缪,在代码中使用Core ...

  9. 《3D Math Primer for Graphics and Game Development》读书笔记2

    <3D Math Primer for Graphics and Game Development>读书笔记2 上一篇得到了"矩阵等价于变换后的基向量"这一结论. 本篇 ...

随机推荐

  1. 【搜索、bfs】Find The Multiple

    Problem   Given a positive integer n, write a program to find out a nonzero multiple m of n whose de ...

  2. html option选中 回显 取值

    1.html <select class="form-control" id="sex"> <option value="-1&qu ...

  3. 如何防止XshellPortable、putty、SecureCRT等断网造成Linux命令中断

    在使用XshellPortable.putty.SecureCRT等工具远程连接Linux系统时,如果我们执行了一大堆命令,在命令尚未执行完毕,客户端突然断网或者XshellPortable.putt ...

  4. buf.writeIntBE()函数详解

    buf.writeIntBE(value, offset, byteLength[, noAssert]) buf.writeIntLE(value, offset, byteLength[, noA ...

  5. PHP+Python,轻量维护超轻松

    window下安装Python 直接去Python官网下载msi安装程序安装即可(选择自定义安装才能修改程序安装路径哦) widows下Python的数据库访问模块PyMysql的安装 1.open ...

  6. Q-criterion- definition and post-processing

    Q-criterion Table of Contents 1. Q-Criterion 1.1. Q-criterion– Hunt, Wray & Moin 1988 1.2. Q cri ...

  7. 二、第一个ECharts图表

    <!DOCTYPE html> <head> <meta charset="utf-8"> <title>ECharts</t ...

  8. 设置NODE_ENV=test环境变量

    之前开发时因为有内网测试环境和外网测试环境,再部署打包时总是切换两个域名,比较麻烦,所以最好能设置一个环境变量,来控制两个域名,于是做了如下配置: "scripts": { &qu ...

  9. 【Codeforces 711C】Coloring Trees

    [链接] 我是链接,点我呀:) [题意] 连续相同的数字分为一段 你可以改变其中0为1~m中的某个数字(改变成不同数字需要不同花费) 问你最后如果要求分成恰好k段的话,最少需要多少花费 [题解] dp ...

  10. Leetcode 123.买卖股票的最佳时机III

    买卖股票的最佳时机III 给定一个数组,它的第 i 个元素是一支给定的股票在第 i 天的价格. 设计一个算法来计算你所能获取的最大利润.你最多可以完成 两笔 交易. 注意: 你不能同时参与多笔交易(你 ...