WHAT IS GPU INSTANCING?
GPU Instancing is an optimization technique that Unity gives us to render multiple copies of the same object on screen with very few impacts on performance, and I mean lots of copies of that object, this is useful, for example, to render large amounts of grass or tree tops.
NOTE: Los ejemplos que veremos a continuación hablan del material estándar de Unity.
Hacer esto es muy sencillo con los materiales que Unity nos proporciona por defecto, basta con activar la casilla "Enable GPU Instancing" en el inspector y ya está.
In this example, I am showing you where the checkbox is (is in the material) and how the number of draw calls is dramatically reduced.
- Objects must use the same mesh
- Objects must share the same material
- Objects with GPU Instancing, although must use the same mesh, they can use different scales, rotation and position. .
- There are methods to achieve that these objects on GPU Instancing have different properties like textures or color, we're going to talk about this in another article.
- Unity only shows the "GPU Instancing" checkbox if the material allows it, if you need a material with special properties you can write your own shader and make it work with GPU Instancing.
- If you're doing 'Batching', Unity prioritizes the "Static batching" over 'GPU Instancing', so, if you have some of these objects checked as 'Static', Unity will delete the 'GPU Instancing' instruction at the moment of make the 'Batching'. Also, Unity will show you a console Alert advising you to deactivate the 'Static' mode from those objects.
- GPU Instancing allows global illumination with LightProbes.