This future package for Unity engine features collection of four optimized tree shaders for all three render pipelines.
Performance is only 3-10% below basic lit shaders both on CPU and GPU side.
Shaders provide wind simulation without any additional vertex data or hierarchy information requirements, and shading and lighting features,
such as high-fidelity imitation of self-shading when outside of range of cast shadows, light transmission and volume-based shading of tree top.
Shading of tree top is simulated as attenuation of sun rays trough an ellipsoid with configurable flat density.
Ellipsoid extents and position are configurable in material settings.
Editor tool for visualization of the ellipsoid is part of the package.
Far self shading
Classical cast shadow have one big disadvantage: limited draw distance. This makes trees beyond the range of cast shadows look unnaturaly flat.
Once outside range, configurable in material settings, LPEnviroment shaders will apply own self shading, that closely imitates result produced by cast shading.
Implementation
All three render pipelines, built-in, URP, and HDRP are supported, with built-in support containg two shaders,
one based on Unity 5 Standard shader and second one based on legacy Unity 4 shader.
HDRP shader is implemented as a shader graph. Wind module is a separate subgraph, allowing usage in other shaders.
Since URP and built-in shader do not support light transmission on cutout variants, remaining shaders are implemented in HLSL.
Wind simulation and most of shading functions are separated into a separate module, which can also be included and used in other shaders.
All features
Shader properties
Cull mode is used to disable backface culling for leaves
Leaves bound extent and density defines size of the ellispoid trough which sun rays are attenuated. Last coordinate is density.
Leaves bound position is position of the ellipsoid. Last coordinate is ignored.
Far shadow fade controls the distance and strength of the far shading effect. Remaining coordinates are ignored.
The Shadow distance label shows the current cast shadow distance.
Wind noise is source of randomness for the wind simulation.
Wind weights (LFBT) controls the strength of components of the wind simulation, that being lift, flutter, turbulence and bend.
Lift lifts branches facing the wind direction, flutter randomly shakes all leaves and branches, turbulence imitates angular movenent of large branches and
bend bends the whole tree away from the wind direction.
Core size sets size of the area around ellipsoid vertical axis which should not be affected by wind. This reduces flutter of thick central branches.
Wind global properties
This script feeds wind parameters and randomized time of the simulation into the shaders.
The wind parameters are magnitude, magnitude variance, direction and direction variance.
Transition time fades in changes made to the previous four parameters.