GPU instancing is a draw call optimization method that renders multiple copies of a mesh with the same material in a single draw call. Each copy of the mesh is called an instance. This is useful for drawing things that appear multiple times in a scene, for example, trees or bushes.
GPU instancing renders identical meshes in the same draw call. To add variation and reduce the appearance of repetition, each instance can have different properties, such as Color or Scale. Draw calls that render multiple instances appear in the Frame Debugger as Render Mesh (instanced).
This section includes information about the platform, render pipeline, and SRP Batcher compatibility of GPU instancing.
GPU instancing is available on every platform except WebGL 1.0.
功能 | 内置渲染管线 | 通用渲染管线 (URP) | 高清渲染管线 (HDRP) | Custom Scriptable Render Pipeline (SRP) |
---|---|---|---|---|
GPU instancing | 是 | 是 (1) | 是 (1) | 是 (1) |
注意:
GPU instancing isn’t compatible with the SRP Batcher. The SRP Batcher takes priority over GPU instancing. If a GameObject is compatible with the SRP Batcher, Unity uses the SRP Batcher to render it, not GPU instancing. For more information about optimization method priority, see Optimization priority.
If your project uses the SRP Batcher and you want to use GPU instancing for a GameObject, you can do one of the following:
Unity uses GPU instancing for GameObjects that share the same mesh and material. To instance a mesh and material:
To use GPU instancing for a material, select the Enable GPU Instancing option in the Inspector.
GPU instancing supports Unity’s Baked Global Illumination system. Unity Standard Shaders and surface shaders support GPU instancing and Unity’s Baked Global Illumination system by default.
Each GPU instance supports global illumination from one of the following sources:
GPU instancing automatically works with:
To enable Light Probe rendering for Graphics.RenderMeshInstanced
, provide a MaterialPropertyBlock that includes the Probe data. For more information and code examples, see LightProbes.CalculateInterpolatedLightAndOcclusionProbes.
Alternatively, you can pass an LPPV component reference and LightProbeUsage.UseProxyVolume to Graphics.RenderMeshInstanced
. When you do this, all instances sample the volume for the L0 and L1 bands of the Light Probe data. If you want to supplement L2 data and occlusion data, use a MaterialPropertyBlock
. For more information, see Light Probes: Technical Information.
Meshes that have a low number of vertices can’t be processed efficiently using GPU instancing because the GPU can’t distribute the work in a way that fully uses the GPU’s resources. This processing inefficiency can have a detrimental effect on performance. The threshold at which inefficiencies begin depends on the GPU, but as a general rule, don’t use GPU instancing for meshes that have fewer than 256 vertices.
If you want to render a mesh with a low number of vertices many times, best practice is to create a single buffer that contains all the mesh information and use that to draw the meshes.
2017–10–24 页面已修订
在 5.6 版中增加了 Enable Instancing 复选框指南、DrawMeshInstancedIndirect 和 #pragma multi-compile
在 2017.3 版中增加了针对 GPU 实例化的着色器预热 NewIn20173
在 2018.1 版中增加了 GPU 实例化的全局光照 (GI) 支持 NewIn20181
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.