This page may not work correctly inside the Unity editor. Open in browser

Add Procedural Instancing support to custom shader

The Procedural Instancing feature of Nature Renderer allows you to run the entire rendering pipeline on the GPU using compute shaders. This drastically increases performance.

Because the entire rendering pipeline is handled on the GPU it is directly connected to your shaders. This means that you will have to make a few small modifications to your custom shaders to make them work with the procedural instancing feature.

All Nature Shaders that come with Nature Renderer already support Procedural Instancing.


This code may be updated with new major Nature Renderer versions. If something does not work with a future version of Nature Renderer then please check this page again for updated instructions.

1. Add a tag

Add the tag "NatureRendererInstancing" = "True" to your shader. This tells Nature Renderer that the shader supports procedural instancing.


2. Add Instancing Options

Add the following pragma to your shader. The pragma multi_compile_instancing adds a second shader variant with support for GPU instancing. The pragma instancing_options procedural:SetupNatureRenderer tells Unity to call the function 'SetupNatureRenderer' for this shader before rendering so that Nature Renderer can set up the rendering data.

#pragma multi_compile_instancing
#pragma instancing_options procedural:SetupNatureRenderer

If you shader already contains these 2 lines then you should replace them.

3. Reference the Nature Renderer library

You need to included Nature Renderer's shader code in your shader. You can do this by adding a reference to the Nature Renderer.cginc include file:

#include "Assets/Visual Design Cafe/Nature Shaders/Common/Nodes/Integrations/Nature Renderer.cginc"



If you need to support multiple renderers then you can use the NATURE_RENDERER keyword to include/exclude Nature Renderer's code. Nature Renderer automatically sets the NATURE_RENDERER keyword for materials that are rendered with Nature Renderer.

For example:

#include "Assets/Visual Design Cafe/Nature Shaders/Common/Nodes/Integrations/Nature Renderer.cginc"

Don't forget to add NATURE_RENDERER as a shader feature if you need to support multiple renderers so that two shaders variants are created: one with Nature Renderer and one without:

#pragma multi_compile_local _ NATURE_RENDERER


Was this article helpful?
5 out of 12 found this helpful