An example of my custom foliage shaders: Opaque and Masked
Description
Project: Personal Instruments used: UE5, Megascans, Photoshop
Here is an example of my custom foliage shaders which include an Opaque shader for trees bark and details and a Masked shader for branches and grass foliage. I took megascans trees and foliage to demonstrate how these shaders work.
I decided not to cover a process of preparation and rendering last-LOD billboards here so it could be a topic of one of the next articles, I just left the native megascans impostors on trees as they were imported.
Opaque shader functionality
3 layers: unique bark (lower), tiled bark (upper), details Additional functionality: wind sway, color variation, normal bump. Vertex Colors: R: lower bark/upper bark blending G: Details B: (reserved for another layer, eg. ash)
Wind
It uses custom MF_WindSway function for trunk swaying and it takes no vertex paint but based on trees height. There are WindSpeed and SwayScale parameters connected from the parameter collection MPC_Wind to control speed and amplitude of the swaying. Additional functionality (optional): Color Variation, FuzzShader, FullyRough, SprecularDetails (based on AO map).
Vertex Colors: R — Wind G — Details B — (reserved for baked Occlusion)
Wind
MF_WindSway — to synchronise branches with trunk swaying. SimpleGrassWind — for leaves fluttering. It takes a gradient painting in R channel, for branches not to flake off in the base. The wind parameters were taken outside and put into MPC to have a universal control over wind intensity, speed and sway scale on the whole scene. Additional functionality (optional): Subsurface Scattering — uses BC texture, parameters Tint and SSS Scale to control the translucency. Color Variation — can be implemented with the standard function SpeedTreeColorVariation or via Curve Atlas like here. FuzzShader — using FuzzyShadingGrass function for BC. FullyRough — only scalar parameters instead of Specular and Roughness maps.