Foliage Renderer – Advanced Shader Integration
1078
post-template-default,single,single-post,postid-1078,single-format-standard,bridge-core-3.2.0,ajax_fade,page_not_loaded,,qode_grid_1300,footer_responsive_adv,qode-content-sidebar-responsive,qode-child-theme-ver-1.0.0,qode-theme-ver-23.2,qode-theme-bridge,disabled_footer_bottom,qode_header_in_grid,wpb-js-composer js-comp-ver-7.7.2,vc_responsive

Foliage Renderer – Advanced Shader Integration

Foliage Renderer – Advanced Shader Integration

Foliage Renderer requires some specific Shader setup in order to place the Indirect Rendered Meshes correctly in your Scene with maximum efficiency. In most cases you will be able to use the included ShaderPatcher to create compatible copies of your Shaders.

To open the Shader Patcher, find any Foliage Renderer Component in your Scene, select it, and click the ‘Shader Patcher’ button near the top of the inspector to open the Shader Patcher. Or, navigate to Window/FoliageRenderer/ and select ‘Shader Patcher’ to open the Shader Patcher.

To use the Shader Patcher; first, click ‘Scan.’ This will find every Material and Shader in use by the Terrains currently loaded. Each Shader will be listed with a Patch Button next to it. The Patcher tries to predict Shaders that do not need to be patched, and will colorize the Patch button next to those Shaders Yellow. If you still click ‘Patch’ a confirm dialog will appear explaining why the Patcher thinks that Shader does not need patching, but you can still Patch it if you wish. You can click ‘Patch’ at the top of the Window to Patch all Shaders currently listed, but any “yellow” Shaders that seem to be already setup to the Patcher will be skipped.

The Patcher will attempt to modify these new shaders to be compatible with Foliage Renderer.  It is possible to heavily obfuscate Shader code, so we can’t guarantee the Patcher will automatically resolve every Shader, but it will fix many.

Note that if you are authoring Shaders yourself, you might want to include this code directly. Inside the package you will find a .cginc file and Shader Graph Node to make this easy. If you are authoring Shaders in Better Shaders, it already includes a stackable for Foliage Rendering instancing.  Read on for more information.

BetterShaders

If you are extending your BetterShaders Shader, you can take a look at the included SubShaders in ‘Packages/FoliageRenderer/Shaders/BetterShadersSource’ and include those or add them to your Stacked Shader.

Unity ShaderGraph

Upgrading a ShaderGraph to be FR compatible is just a matter of replacing Position inputs with the FoliageRendererInstancedIndirect Node included in the package.

Here you can see an example of remapping existing Position Object Space Node Inputs to the FoliageRendererInstancedIndirect Node.

Manual Shader Fixing

There are only two lines of code you will need to add at a minimum to get your Shader working if you have to resort to text editing. And, at most you will just need to add them multiple times, pretty easy overall.

#pragma instancing_options procedural:setupFoliageRenderer forwardadd
#include “Packages/com.jbooth.foliagerenderer/Shaders/FoliageRendererInstancing.cginc”

At the end of the #include block in each Pass of your Shader that needs position (usually all of them unless you’re doing something tricky) add the above two lines. Additionally, any place “instancing_options procedural” is in use you’ll want to replace whatever content is in that line with the first line.

TVE

If you are using the popular TVE asset, simply set the TVE ShaderManager to FoliageRenderer Mode. You do not need to do any additional Shader Patching at that point.

If you are using TVE’s Amplify Imposters package, note that the Imposter Alpha cutoff is (as of 3/25/24) inverted, so you may need to edit some Material properties to get the expected results.

NM

If you are using NM Shaders in the Built-in RP run the Shader Patcher on your target Shaders as described above and you will be all set.

If you are using HDRP or URP you will need to manually edit your Shaders. See above for an explanation. And check out the video below walking through fixing the HDRP Foliage Shader…