UE4 Grass Shader Material Showcase 04

Dynamic UE4 Grass Realtime Shader

For the last few months, I have been phasing Unreal Engine 4 into some of my projects. I was pleasantly surprised to find the transition from UDK to UE4 unhindered by the demands of learning an unfamiliar interface. This is due to many of UDK’s UI/UX design features making a seamless appearance in UE4. The new material editor is a familiar sight with very little of its interface having changed. This made learning/developing art workflows a walk in the park. It is a shame to see the light vector missing as a per-pixel input, but this is a necessary trade-off in a deferred shading pipeline.

What we have here, is a UE4 grass asset I have been developing for use in current-gen PC games. The grass blades are displayed on low-poly alpha planes, featuring normal map textures, and sub-surface scattering to create a realistic end result.

I have added, to the shader, many features for creating a natural, varied look. It can be configured to: clump together into localised clusters; vary in colour and translucency; vary in elasticity/wind-resistance ― all of this is controlled by procedurally-generated alpha masks.

Below, is a fly-through video, showcasing the grass in action!

Some of the features demonstrated in this video include:

  • LOD instance swapping based upon camera distance (used in combination with native instance culling);
  • Dynamic, sine wave wind (plus world-space perturbation map) that varies over time;
  • Rigidity based upon UV derived gradients and vertex colours (for eccentricity);
  • Colour variation and clustering (i.e. translation along normal axis) to improve realism;
  • World-space normal map projection (supplemental to tangent-space normal map).

I have made two flavors of grass thus far: garden and wild. Garden grass has a higher mesh density, having been designed for cinematic scenes and small enclosures (i.e. gardens). Wild grass, on the other hand, is optimised for large-scale use and interpolates between a bigger, sparser mesh and a smaller, more detailed mesh depending upon viewing distance. This is in addition to UE4’s vegetation feature that automatically groups distant mesh clusters into single draw-calls.

Here is an early version of the grass:

As the grass is fundamentally just a collection of meshes with a fancy shader and textures, it can be applied to any surface, including a sphere. Below, is a sphere scene I created while prototyping the shader.


We can see in the last image, a visualisation of the sine waves driving the wind animation. A little trigonometry is used to derive the sine wind propagation direction from an arbitrary floating-point value (in radians). This value is itself oscillated by a sine wave to create a more natural feel. The outputted vector of these operations is then added to a lower-frequency sine wave with a value perturbed by an alpha mask projected in world-space. This approach produces a fairly natural wind animation.

Many individuals and studios have requested that I put my UE4 grass on the Unreal Marketplace so I am working on making this a reality. Most of the indie studios I have spoken to would pay a non-trivial sum for a commercial license so perhaps there is indeed a product to be sold here.