NoteTube

How I built a realistic grass shader in UE5! Shader driven bend, clump, tilt, wind and more!
43:51

How I built a realistic grass shader in UE5! Shader driven bend, clump, tilt, wind and more!

Ghislain Girardot

6 chapters7 takeaways10 key terms5 questions

Overview

This video details advanced techniques for creating realistic, animated grass in Unreal Engine 5, primarily using World Position Offset (WPO). It covers mesh preparation, procedural bending, clumping, wind effects, camera-facing logic for performance, and normal reconstruction. The creator emphasizes achieving natural movement and density through shader-driven features, offering practical solutions and workarounds for complex visual effects, while also discussing performance considerations and the trade-offs of different techniques.

How was this?

Save this permanently with flashcards, quizzes, and AI chat

Chapters

  • Grass meshes are prepared as flat, undeformed cards oriented towards the positive X-axis, with custom UVs for textures, pivot points, height, and random values.
  • World Position Offset (WPO) is the primary tool for manipulating grass features procedurally.
  • Initial WPO techniques involve reconstructing world position, centering cards on pivots, and applying instance-based scaling.
  • A per-instance fade amount is used to smoothly transition grass visibility based on distance.
Properly preparing the mesh and understanding the foundational WPO techniques are crucial for enabling complex procedural animations and manipulations later in the shader.
Centering grass cards on their pivots by subtracting baked pivots in local space after reconstructing world position.
  • Random rotation around the Z-axis is achieved by constructing a new coordinate system using a random 2D direction, often stored in vertex normals.
  • A custom Blender add-on or scripting can bake random 2D directions into vertex normals across different LODs.
  • Clumping is created using a 'clump map' texture, generated procedurally within Unreal Engine, which influences grass card orientation.
  • A radial direction derived from the clump map is used to orient cards towards a central point, with a Bonar mask preventing self-intersection artifacts.
These techniques introduce essential variation and organic grouping, making the grass appear more natural and less uniform.
Using a generated clump map to orient grass cards towards a single point, creating the visual effect of grass growing in dense patches.
  • Grass cards can be tilted to match the landscape normal by using the instance's Z vector transformed to world space.
  • Wind effects are applied by sampling a wind texture and using the wind velocity to influence the grass card's orientation.
  • The dot product between wind direction and card orientation modulates wind influence, making grass react more realistically to wind when facing it.
  • A noise texture can drive the bend amount, and wind magnitude can reduce bending, causing grass to straighten in strong winds.
Simulating wind and landscape interaction adds dynamic movement and grounds the grass realistically within its environment.
Grass straightening and reorienting to face the wind when the wind force increases, creating a dynamic response to environmental forces.
  • To maximize perceived density, grass cards are rotated to face the camera using view-space vectors.
  • A simplified 2D billboard effect is achieved by removing the Z component of the view vector and handling edge cases.
  • The camera-facing logic must be applied before bending and rotation to avoid visual artifacts.
  • A complex workaround involves un-rotating the view vector by the inverse of the card's rotation to maintain camera-facing orientation after other transformations.
This technique significantly boosts perceived grass density and visual fidelity without increasing the actual vertex count, improving performance.
Rotating grass cards to face the camera, making a sparse field of grass appear much denser and fuller.
  • Distant Level of Detail (LODs) are crucial for performance, with custom mipmaps used to control opacity and prevent texture mushing at a distance.
  • Pixel Depth Offset can be used to fake depth and self-shadowing on grass cards, creating a less flat appearance.
  • The shadow pass can be manipulated (e.g., making cards opaque or transparent) to enhance shadow coverage and perceived density.
  • A custom tool bakes landscape layers into a texture for use in the shader, enabling effects like grass bleeding onto dirt.
These techniques refine the visual quality, manage performance effectively, and add subtle details that contribute to realism, especially at varying distances.
Using custom mipmaps for the grass opacity texture to ensure that distant grass cards don't become overly transparent due to mipmapping.
  • Rebuilding world-space normals from scratch is often easier than fixing existing ones, especially when vertex normals store custom data.
  • A choice exists between upward-facing normals (for unified lighting) and default vertex normals (for realistic light interaction).
  • A cheat involves lerping world normals towards a tilt direction to ensure wind and clump effects influence lighting.
  • Tangent-space normal maps are remapped to world space by reconstructing the XYZ coordinate system based on the card's orientation and transformations.
Correctly reconstructing normals is vital for accurate lighting and shading, ensuring the grass interacts realistically with light sources.
Remapping a tangent-space normal map to world space by defining new X, Y, and Z axes based on the grass card's orientation, bend, and tilt.

Key takeaways

  1. 1World Position Offset is a powerful and versatile tool for achieving complex procedural effects in shaders without relying solely on geometry.
  2. 2Storing custom data (like random directions) in vertex normals is an efficient way to drive shader variations across instances and LODs.
  3. 3Balancing visual fidelity with performance is key; techniques like camera-facing logic and aggressive LODs are essential for dense foliage.
  4. 4Procedural generation of textures (like clump maps) within the engine offers greater control and flexibility than purely artist-painted assets.
  5. 5Understanding how transformations affect vectors and normals is critical for accurate lighting and shading, especially when reconstructing them.
  6. 6Custom mipmap generation and manipulation offer advanced control over texture appearance and behavior at different distances.
  7. 7The choice between upward-facing and default vertex normals impacts lighting and shading, with trade-offs for different rendering scenarios.

Key terms

World Position Offset (WPO)Vertex NormalsClump MapLODs (Levels of Detail)MipmapsTangent SpaceWorld SpacePixel Depth OffsetCamera Facing LogicNormal Reconstruction

Test your understanding

  1. 1How does World Position Offset enable procedural bending and orientation of grass cards?
  2. 2What is the purpose of a 'clump map' and how is it generated and used to influence grass appearance?
  3. 3Explain the trade-offs between using upward-facing normals and default vertex normals for realistic grass rendering.
  4. 4How does the camera-facing logic improve the perceived density of grass, and what challenges arise when combining it with other transformations like bending?
  5. 5What are custom mipmaps, and why are they useful for controlling grass opacity and appearance at a distance?

Turn any lecture into study material

Paste a YouTube URL, PDF, or article. Get flashcards, quizzes, summaries, and AI chat — in seconds.

No credit card required

How I built a realistic grass shader in UE5! Shader driven bend, clump, tilt, wind and more! | NoteTube | NoteTube