Kiwi Foliage Renderer Docs
View all packages

Features

Shaders

Convert shaders automatically, set presets, add the three-line HLSL setup or use Shader Graph, and use Foliage Lit.

Kiwi Foliage Renderer 26.12.0Unity 6000.0+URP · HDRP · Built-in

Instances drawn with the Shader Integration sample's custom shader

The renderer draws with indirect instancing. A shader can draw foliage instances when each pass it uses has the procedural instancing setup from KiwiFoliageInstancing.hlsl. That setup replaces the object matrices and the LOD fade of the instance being drawn, so the shader's own transforms, lighting and cross-fade keep working.

Automatic conversion

With Convert Shaders Automatically on (the default, in the renderer's ••• menu or the Shader Setup window), the first time a material with an unknown shader is drawn:

  1. Its shader is copied to Assets/Kiwi Foliage/Converted Shaders and renamed Kiwi Foliage/Converted/<original name>.

- Text shaders (.shader): every pass the renderer draws gains the instancing pragma, the procedural setup option and the include. Meta, 2D, picking and ray tracing passes are left alone. Relative includes are made absolute. Surface shaders gain addshadow so their shadows follow the instances. - Shader Graphs: the Kiwi Foliage Setup Custom Function node is inserted between the graph's vertex position and the Vertex Position block, and Support LOD CrossFade is turned on for every target.

  1. A persistent copy of the material is created in Assets/Kiwi Foliage/Converted Materials so players include the right shader variants.
  2. Both are recorded in the material library, and every renderer refreshes.

Until the conversion finishes (a moment later in the editor) the material draws with Foliage Lit. Editing the source material copies its values into the converted copy. Saving the source shader converts it again.

Open Window > Kiwi Foliage > Shader Setup to see every shader your foliage uses, how it is drawn, and to convert, reconvert or forget each one.

Presets

Presets decide how a family of shaders is handled and which texture names the impostor baker reads.

PresetShadersHandling
Kiwi FoliageKiwi Foliage/*Native
LeafshaperLeafshaper/*Native
URP Lit familyLit, Simple Lit, Complex Lit, Baked Lit, UnlitConverted
URP SpeedTreeUniversal Render Pipeline/Nature/SpeedTree*Converted (see limitations)
HDRP Lit familyHDRP/Lit, HDRP/LitTessellation, HDRP/UnlitConverted
HDRP SpeedTreeHDRP/Nature/SpeedTree*Converted (see limitations)
The Vegetation EngineBOXOPHOBIC/The Vegetation Engine/*Converted
Nature ShadersNature Shaders/*Converted, replacing their own procedural setup
NatureManufactureNatureManufacture*, Shader Graphs/NM_*Converted
Built-in Standard and LegacyStandard, Legacy Shaders/*, Mobile/*, Unlit/*Foliage Lit fallback
Built-in NatureNature/*, terrain detail shadersFoliage Lit fallback

Any other shader with source in the project is converted. To override a family, create Assets > Create > Kiwi Foliage > Shader Preset, set its name patterns (a trailing * matches the start of a name), its handling and its texture names. Project presets win over the built-in list.

Adding the setup to your own shader

Add these three lines to every pass the renderer draws (forward, shadow caster, depth, depth normals, motion vectors, G-buffer), after the pass's own includes. Just before ENDHLSL or ENDCG is a safe place:

hlsl
#pragma multi_compile_instancing
#pragma instancing_options procedural:kiwiFoliageSetup
#include "Packages/net.kiwistudios.foliage/ShaderLibrary/KiwiFoliageInstancing.hlsl"

Also add the tag "KiwiFoliage" = "Instanced" to the SubShader's Tags, so the renderer draws the shader as it is instead of converting it.

Two more SubShader tags are optional:

TagEffect
"KiwiFoliageCrossFade" = "Instanced"The shader dithers its own cross-fade from kiwiFoliageFade. The renderer draws your instanced material as it is, without a copy that turns on LOD_FADE_CROSSFADE, so edits to the material show at once.
"KiwiFoliageImpostor" = "True"The shader draws baked impostor cards. A level of detail drawn only with such materials counts as an impostor, and its card does not widen the culling bounds of a prefab that also has mesh levels.

Shaders that keep their own object matrices, for example to work in absolute world space in every pipeline, can #define KIWI_FOLIAGE_CUSTOM_MATRICES before the include. The setup then leaves unity_ObjectToWorld, unity_WorldToObject and unity_LODFade alone, and the shader reads the values below.

The pass must call UNITY_SETUP_INSTANCE_ID in its vertex function, as Unity's own shaders do. For dithered LOD cross-fade, declare #pragma multi_compile _ LOD_FADE_CROSSFADE and apply Unity's LODFadeCrossFade (URP) or your own dither in the fragment function: the setup writes unity_LODFade with Unity's sign convention.

Inside the procedural variant, KIWI_FOLIAGE_INSTANCED is 1 and these values describe the current instance:

ValueMeaning
kiwiFoliageObjectToWorld, kiwiFoliageWorldToObjectThe instance matrices.
kiwiFoliageFadeSigned cross-fade: positive for the outgoing level, negative for the incoming one.
kiwiFoliageTintA per instance value from 0 to 1 (terrain tree colour variation, or the tint you pass when adding instances).

A function that reads these values has to come after the include. Place the three lines above it, but still after the pass's own includes, as the Shader Integration sample does.

Shaders that keep their own matrices can define KIWI_FOLIAGE_CUSTOM_MATRICES before the include. The setup then leaves unity_ObjectToWorld alone and only fills the values above.

Amplify Shader Editor

Add the three lines under Additional Directives in the graph's output node. Converting an Amplify shader as text works too, but saving it from Amplify again removes the conversion.

Shader Graph

Add a Custom Function node:

  • Type: File. Source: Packages/net.kiwistudios.foliage/ShaderLibrary/KiwiFoliageShaderGraph.hlsl. Name: KiwiFoliageSetup. Turn on Use Pragmas.
  • Inputs: Position (Vector 3). Outputs: Out (Vector 3) and Tint (Float).
  • Connect a Position node in Object space (or your own vertex offset) to Position, and Out to the Vertex Position block.

Turn on Support LOD CrossFade in the Graph Settings for cross-fades. Tint is available in the vertex stage.

The Shader Setup window can also convert a Shader Graph for you: it writes a converted copy and leaves your original untouched.

Foliage Lit

Kiwi Foliage/Foliage Lit is the renderer's own shader for leaves, grass and anything converted to a fallback. It works in URP, HDRP and the Built-in Render Pipeline with main texture, colour, cutout, normal map, smoothness, healthy and dry colours mixed by instance tint, translucency, an up-facing normal blend for grass, ground occlusion, and wind driven by the renderer's Wind Zone.

Still stuck?

Bring the renderer state with you.

Include the Kiwi Foliage version, Unity and render-pipeline versions, the graphics API, the Foliage Renderer's header state and statistics, the Shader Setup row for any shader involved, and a minimal scene.

Email supportJoin Discord

Kiwi Foliage Renderer 26.12.0

Search documentation