In this lesson, you will learn how to use grayscale masks and mathematical operators within Shader Graph to blend two distinct surface materials on a single object.
The Concept of Masking
In PBR workflows, we often want a single mesh to exhibit different physical properties across its surface—such as a rusted metal patch on a clean painted pipe. Rather than creating two separate objects, we use Masking. A mask is simply a grayscale texture (or procedural noise) where white represents "Material A" and black represents "Material B." By using these values as a factor, we can mathematically interpolate between two sets of textures.
Implementing the Blend
In Unity’s Shader Graph, we achieve this using the Lerp (Linear Interpolation) node. The Lerp node takes three inputs: A, B, and T (the mask).
- A: Your first material property (e.g., Albedo of clean paint).
- B: Your second material property (e.g., Albedo of rough rust).
- T: Your grayscale mask texture.
When the mask value at a specific UV coordinate is 0, the node outputs A. When it is 1, it outputs B. If it is 0.5, you get an even mix of both, which is excellent for creating soft transitions or weathering effects.
Practical Application
To refine the transition, you can pass your mask through a Smoothstep node before feeding it into the Lerp. This allows you to tighten or soften the boundaries of your blend without needing to edit the source texture.
// Conceptual logic for blending two Albedo inputs
float3 blendedAlbedo = lerp(cleanPaint.rgb, rust.rgb, maskTexture.r);
By repeating this logic for different PBR channels—such as Normal Maps or Roughness Maps—using the same mask, you ensure that the "rust" not only looks different in color but also reacts to light as a physically distinct material compared to the surrounding paint. This technique is highly performant because it avoids complex geometry layering and relies instead on the GPU's ability to interpolate values efficiently.
Key Takeaway: Masking allows you to drive complex surface transitions by using grayscale values to interpolate between different PBR properties via the Lerp node.