Employing GPU instancing

GPU Instancing is a means to render multiple copies of the same mesh quickly by exploiting the fact that they will have identical Render States, hence require minimal draw calls. This is practically identical to dynamic batching, except that it is not an automatic process. In fact, we can think of dynamic batching as a poor man's GPU instancing since GPU instancing can enable even better savings and allows for more customization by allowing parameterized variations. 

GPU Instancing is applied at the Material level with the Enable Instancing checkbox, and variations can be introduced by modifying shader code. This way, we can give different instances of different rotations, scales, colors, and so on. This is useful for rendering scenes such as forests and rocky areas where we want to render hundreds or thousands of different copies of a mesh with some slight variation.

Note that Skinned Mesh Renderers cannot be instanced for similar reasons that they cannot be dynamically batched, and not all platforms and APIs support GPU Instancing.

The following screenshot shows the benefits of GPU Instancing on a group of 512 cube objects (with some extra lighting and shadowing applied to increase the total draw call count):

This system is much more versatile than dynamic batching since we have more control over how objects are batched together. Of course, there are more opportunities for mistakes if we batch things in inefficient ways, so we should be careful to use them wisely.

Check out the Unity documentation for more information on GPU Instancing at https://docs.unity3d.com/Manual/GPUInstancing.html.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.104.248