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. cc.Node—场景树

    对于cc.Node我分了四个模块学习: 1.场景树,2.事件响应,3.坐标系统,4.Action的使用:在此记录经验分享给大家. 场景树 1: creator是由一个一个的游戏场景组成,通过代码逻辑来 ...

  2. docker-ce安装官翻

    参考http://www.cnblogs.com/maple42/p/5868846.htmlhttp://blog.csdn.net/lizehua123/article/details/50601 ...

  3. eclipse自动提示配置

    打开Window->Preferences

  4. C++ <queue>用法

    C++队列可以不需要自己写,有现成的模版类 头文件: #include <queue> #include <iostream> using namespace std; (之前 ...

  5. 解决windows安装TensorFlow2.0beta版本时ERROR: Cannot uninstall 'wrapt'问题

    pip install -U --ignore-installed wrapt enum34 simplejson netaddr 参考:https://bugs.launchpad.net/rall ...

  6. 多校1007 Naive Operations

    >>点击进入原题测试<< 思路:好像是第一次这么印象深刻的写线段树,说实话,这个题确实很有意思,值得学习. 看了大神讲解视频,但是自己写的还是超时了. 参考来自 https:/ ...

  7. hadoop 3.0.0新特性

    1.Minimum required Java version increased from Java 7 to Java 8 java最低支持版本变成java8 2.Support for eras ...

  8. web项目的创建

    1) 创建Mave的webapp项目 2) 在Pom文件中添加servlet-api的依赖 <dependency> <groupId>javax.servlet</gr ...

  9. RabbitMQ整合spring----https://www.cnblogs.com/woms/p/7040902.html

    https://www.cnblogs.com/woms/p/7040902.html

  10. poj 1364 查分约束

    #include<stdio.h> #include<iostream> #include<stack> #include<string.h> usin ...