Using Material Layers in UE5

🔖 game-development ⏲️ 6 minutes to read

Material Layers are a feature of Unreal Engine 5 (and were actually present in 4.26). This feature allows you to build up modular material node graphs, then pick and chose bits you want when editing Material Instances - including choosing the order and how the layers are blended together.

The above screenshot showcases a layered approach to a plaster material, with multiple layers used to control the base textures, detail textures and to modify the base color.

Layers essentially provide another way to build up your material node graph, but offer a lot more flexibility and control to artists than previously possible via Material Instances and Material Functions.

This video shows very basic editing of the material layers, but does not show many of the advanced features such as re-ordering the layers or swapping out the backround layer and keeping the stack above it in place. It also doesn't show saving "instances" of the layer parameters, another powerful feature to help create re-usable layer definitions.

Concepts

The core concepts involved are the Layer and Blend assets. This took me a long time to understand, since the differences between the two are quite nuanced:

Asset Type Access to Base Material Attributes Access to Previous Layer Material Attributes
Layer Yes No
Blend No1 Yes

1 You can give the blend access to the base material attributes if you pass them through the layer - but if the layer discards or overrides them, the blend can't get the originals.

It's clear from the above table that unless you need to access the Material which owns the layers, you could technically do everything you need in the Material Layer Blend (and make the layer a no-op). However I don't think that follows the spirit of the design of the system.

In the video above I show a Detail Texture layer (a standard technique to enhance the detail of materials without needing to increase the resolution of the textures). To achieve that, I decided to split the process between a layer and a blend:

  • Layer: samples the detail diffuse texture, and detail normal texture
  • Blend: blends the detail textures sampled above with the layer below

However as discussed I could have moved all detail sampling logic into the blend alongside the blending logic. I'm not sure if there are technical drawbacks when doing so, however keeping the conceptual split means you make things more re-usable, and can combine any layer with any blend.

In my example, I could swap out the detail layer for one which uses world-aligned UV coordinates for example, but keep the blend the same. The documentation has more detail on the different asset types (though it does not do a good job of explaining the differences).

Material Setup

Ensure you have Use Material Attributes checked in your material. The below material setup is all you technically need to get going:

However, if you want each layer to have access to a common material attribute, you can use the "Make Material Attributes" node and plug it into the "Material Attribute Layers" node.

Simple Background Layer

Instead of setting up the main textures for the material in the material itself, you can define a layer which allows those textures to be set. The advantage of doing it this way is that you can swap out the layer - for example, maybe you wanted to:

  • Swap in a layer to use world-aligned UVs instead of local UVs
  • Swap in a layer which has support for additional samples, for Ambient Occlusion, Metallic etc
  • Swap in a layer which has no normal map, or roughness map (maybe you don't need one)

Here's a basic layer which supports setting a Base Color, Normal and Roughness texture:

Simple Layer

The example below is a layer asset which modifies the "Base Color" of the input material attributes.

Simple Blend

Epic already have a few blends in the engine content. Here's the node graph for LayerBlend_Scalar, which allows you to blend between the "top" and "bottom" layers based on an alpha value:

Simple Layered Material Instance

Let's put all of the above together now in a material instance:

There are a few things going on:

  • The material graph itself is not doing much (it just sets up the layers)
  • The background layer is sampling the Base Color, Normal and Roughness textures
  • The top layer is modifying the base color to red, and its blend allows us to blend between the background layer with the texture samples, and the top layer with the red color

More Interesting Blends

However, you can get a lot more advanced, specifically with blend assets. In the simple example above, the blend between the top and background layers uses a simple alpha interpolation.

If you compare to Photoshop, it's a bit like using the "Normal" layer blend mode and changing the "Opacity" of the top layer. What if we could use more interesting blends, for example, Darken:

Here's a blend asset that emulates exactly that, in fact leveraging one of Epic's material functions Blend_Darken with that exact goal in mind:

And if I swap LayerBlend_Scalar for the custom "Darken" layer blend, we get the following result:

Detail Texturing

At the top of the post, I described and demoed a detail texturing layout involving both the Layer and a Blend. Let's take a look at how they're set up.

Detail Texturing Layer

The layer is responsible for sampling the detail base color texture, and the detail normal texture, with the specified scale for each (by default it's 5x):

Now we need to build a blend to mix it with the layer below.

Detail Texturing Blend

The blend takes the base color and normals from both layers, and blends them together, with controls for the intensity of both blends:

Note: the maths to blend the normals may need a bit of work

The resulting material instance with the layers set up looks like this:

Of course I can also swap the custom detail blend layer for the "Darken" blend layer we created above, and swap the textures:

And if I swap out the background layer, I could swap in a world-aligned layer, to keep the same layer stack, but change how the textures are projected onto the meshes. There are lots of possibilities for this really powerful system.

🏷️ layer material blend texture detail layers base swap color sample asset attributes blends top node

⬅️ Previous post: Running Rocket Chat on an Intel Celron CPU in 2023

➡️ Next post: Racing Tasks in C♯

🎲 Random post: Fixing UE5 Actors Disappearing when Building Lighting

Comments

Please click here to load comments.