New: Nature Renderer 2021

Render vast amounts of detailed vegetation on your terrain.

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

Custom Shaders

Overview

The Procedural Instancing feature of Nature Renderer drastically increases performances by making use of advanced GPU instancing techniques.

However, to use this feature it needs to be supported by the shaders that are used by the detail objects. The Nature Shaders that come with Nature Renderer automatically support procedural instancing. Your own shaders or shaders from third-party assets may need some modification to support procedural instancing.

The following warning will show if procedural instancing is not supported by the shader:

nature-renderer-procedural-instancing-not-supported-warning.jpg

Patch Shaders

To add support for procedural instancing to the shader(s) you can click "Patch Shaders" in the warning message above. This will attempt to automatically modify the source code of the shader. The patcher works for most shaders but it is possible that you have a shader that can't be patched automatically, in which case you can manually modify the shader code with the changes described below in Shader Modifications.

To patch a specific shader you can right-click on a shader in the project window and choose Nature Renderer > Patch Shader.

Shader Graph

Support for procedural instancing can be easily added to Shader Graphs with the "Procedural Instancing" node:

  1. Add a new Procedural Instancing node to your Shader Graph:
    nature-renderer-shader-graph-create-procedural-instancing-node.jpg
  2. Add a new Position node, set the Space to "Object", and connect it to the Procedural Instancing node. Then, connect the Procedural Instancing node to the Position output. The Procedural Instancing node will only inject the code that is required for Nature Renderer, and will output the Position without any modifications.
    nature-renderer-shader-graph-procedural-instancing-node.jpg
  3. Add a Nature Renderer Instancing boolean property to your Shader Graph. Ensure that the Reference value is set to _NatureRendererInstancing and that the Default value is toggled. This is to let Nature Renderer know that procedural instancing is supported by this shader.
    nature-renderer-shader-graph-procedural-instancing-property.jpg

Shader Modifications

If you do not want to use the automatic shader patcher or if the patcher failed, then you can follow these steps to add support for Procedural Instancing to your own shaders:

  1. Add the tag "NatureRendererInstancing" = "True" to your shader.
    This tells Nature Renderer that the shader supports procedural instancing. This tag should be added to the Tags section in the SubShader, it does not need to be added to each pass. You can easily find the correct Tags section by searching for the RenderType or Queue tags in your shader, since most shaders contains these tags.
  2. Add the line #include "Assets/Visual Design Cafe/Nature Shaders/Integrations/Nature Renderer.templatex" to each pass to include the Nature Renderer code.
  3. Add #pragma instancing_options procedural:SetupNatureRenderer to each pass. This pragma enables the Nature Renderer code for the shader.
...
SubShader 
{ ...
Tags
{
"RenderType" = ...
"Queue" = ...
"NatureRendererInstancing" = "True"
} ...
Pass
{ CGPROGRAM ... #include "Assets/Visual Design Cafe/Nature Shaders/Integrations/Nature Renderer.templatex" #pragma multi_compile_instancing
#pragma instancing_options procedural:SetupNatureRenderer ... ENDCG
}
...
Pass
{ CGPROGRAM ... #include "Assets/Visual Design Cafe/Nature Shaders/Integrations/Nature Renderer.templatex" #pragma multi_compile_instancing
#pragma instancing_options procedural:SetupNatureRenderer ... ENDCG
} } ...
Was this article helpful?
0 out of 2 found this helpful