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

The Leafshaper GPU Renderer draws with indirect instancing. A shader can draw GPU instances when each pass it uses has the procedural instancing setup from LeafshaperGpuInstancing.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.
Leafshaper's own shaders, Leafshaper/Tree, Leafshaper/Tree Impostor, Leafshaper/Foliage Lit and Leafshaper/Foliage Impostor, already have the setup and draw as they are.
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:
- Its shader is copied to
Assets/Leafshaper Generated/GPU Rendering/Converted Shadersand renamedLeafshaper/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 Leafshaper GPU 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.
- A persistent copy of the material is created in
Assets/Leafshaper Generated/GPU Rendering/Converted Materialsso players include the right shader variants. - 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 > Leafshaper > Shader Setup to see every shader your GPU instances use, 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.
| Preset | Shaders | Handling |
|---|---|---|
| Leafshaper | Leafshaper/* | Native |
| URP Lit family | Lit, Simple Lit, Complex Lit, Baked Lit, Unlit | Converted |
| URP SpeedTree | Universal Render Pipeline/Nature/SpeedTree* | Converted (see limitations) |
| HDRP Lit family | HDRP/Lit, HDRP/LitTessellation, HDRP/Unlit | Converted |
| HDRP SpeedTree | HDRP/Nature/SpeedTree* | Converted (see limitations) |
| The Vegetation Engine | BOXOPHOBIC/The Vegetation Engine/* | Converted |
| Nature Shaders | Nature Shaders/* | Converted, replacing their own procedural setup |
| NatureManufacture | NatureManufacture*, Shader Graphs/NM_* | Converted |
| Built-in Standard and Legacy | Standard, Legacy Shaders/*, Mobile/*, Unlit/* | Foliage Lit fallback |
| Built-in Nature | Nature/*, terrain detail shaders | Foliage Lit fallback |
Any other shader with source in the project is converted. To override a family, create Assets > Create > Leafshaper > 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:
#pragma multi_compile_instancing
#pragma instancing_options procedural:leafshaperGpuSetup
#include "Packages/net.kiwistudios.trees/ShaderLibrary/LeafshaperGpuInstancing.hlsl"Also add the tag "LeafshaperGpu" = "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:
| Tag | Effect |
|---|---|
"LeafshaperGpuCrossFade" = "Instanced" | The shader dithers its own cross-fade from leafshaperGpuFade. 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. |
"LeafshaperGpuImpostor" = "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. |
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, LEAFSHAPER_GPU_INSTANCED is 1 and these values describe the current instance:
| Value | Meaning |
|---|---|
leafshaperGpuObjectToWorld, leafshaperGpuWorldToObject | The instance matrices. |
leafshaperGpuFade | Signed cross-fade: positive for the outgoing level, negative for the incoming one. |
leafshaperGpuTint | A 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 Custom Shader Integration sample does.
Shaders that keep their own object matrices, for example to work in absolute world space in every pipeline, can #define LEAFSHAPER_GPU_CUSTOM_MATRICES before the include. The setup then leaves unity_ObjectToWorld, unity_WorldToObject and unity_LODFade alone, and the shader reads 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 two Custom Function nodes:
- Type: File. Source:
Packages/net.kiwistudios.trees/ShaderLibrary/LeafshaperGpuShaderGraph.hlsl. Name:LeafshaperGpuSetup. Inputs:Position(Vector 3). Outputs:Out(Vector 3) andTint(Float). - Type: String. Name:
LeafshaperGpuInstancing. InputInand outputOut(both Vector 3). Body:
``hlsl #pragma instancing_options procedural:leafshaperGpuSetup Out = In; ``
Unity ignores the procedural option when it comes from an included file, so it needs its own string node.
Connect a Position node in Object space (or your own vertex offset) to Position, the first node's Out to the second node's In, and the second node's 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 with the Leafshaper GPU Setup node and leaves your original untouched.
Pipeline shader sources
The URP and HDRP parts of Leafshaper's shaders and of the Custom Shader Integration sample sit in their own shader sources with the .leafshapershader extension, such as InstancedTint.Universal.leafshapershader. Leafshaper builds each one into a shader when its pipeline is installed, and into an empty stand-in otherwise. Use the same layout for your own shaders with separate URP and HDRP parts; see Render pipelines.
Foliage Lit
Leafshaper/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. Leafshaper/Foliage Impostor draws impostors baked for any prefab; see Impostors.
Still stuck?
Bring the recipe with you.
Include the Leafshaper, Unity and render-pipeline versions, the operating system and graphics API, the first Console error, the preset and seed, the GPU renderer's header state for forest or shader problems, and the steps that reproduce the problem.