{"id":883,"date":"2020-01-03T17:09:41","date_gmt":"2020-01-03T09:09:41","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=883"},"modified":"2020-09-27T17:02:13","modified_gmt":"2020-09-27T09:02:13","slug":"commandbuffer-drawinstance","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=883","title":{"rendered":"[Unity]CommandBuffer.DrawInstance"},"content":{"rendered":"\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"471\" src=\"http:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2020\/01\/image-1024x471.png\" alt=\"\" class=\"wp-image-884\" srcset=\"https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2020\/01\/image-1024x471.png 1024w, https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2020\/01\/image-300x138.png 300w, https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2020\/01\/image-768x353.png 768w, https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2020\/01\/image-70x32.png 70w, https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2020\/01\/image.png 1132w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>public class DrawInstance : MonoBehaviour\n{\n    private CommandBuffer mBuff = null;\n    public Material mMat;\n    public Mesh mMesh;\n    private Matrix4x4[] mMatrix44;\n    void Start()\n    {\n        mMatrix44 = new Matrix4x4[100];\n        Vector3 pos = Vector3.zero;\n        for(int i=0; i&lt;mMatrix44.Length; ++i)\n        {\n            pos.x = (i \/ 10) * 1.3f - 5 ;\n            pos.y = (i % 10) * 1.3f - 5 ;\n            mMatrix44[i] = Matrix4x4.TRS( pos, Quaternion.Euler(0, 90, 0), Vector3.one);            \n        }\n        mBuff = new CommandBuffer();\n        mBuff.name = \"MyCube\";\n        mBuff.DrawMeshInstanced(mMesh, 0, mMat, 0, mMatrix44, mMatrix44.Length);\n        Camera.main.AddCommandBuffer(CameraEvent.BeforeForwardOpaque, mBuff);\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/883"}],"collection":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=883"}],"version-history":[{"count":2,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/883\/revisions"}],"predecessor-version":[{"id":886,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/883\/revisions\/886"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}