From Material Expression

Use the From Material Expression shading model to combine multiple shading models in a single Material.

Windows
MacOS
Linux
See Also

The From Material Expression shading model is an advanced feature enabling you to combine multiple shading models into a single Material (or Material Instance) through logic in the Material Graph.

FromMatExpression.png

Usage

  1. In your Material, select the Material Inputs (top left) or Material Attributes node (bottom left) and in its Details panel, set the Shading Model to From Material Expression.

    Setting_FromMatExpresssion.png

  2. When selected, a new input is available on the Material Inputs node called Shading Model.

    MaterialInputs_ShadingModel.png

  3. Right-click in the Material Graph to search and add a Shading Model node.

    ShadingModel.png

  4. Use its dropdown to select the Shading Model you want to use.

    SelectShadingModel.png

See some examples below using different workflows available when setting up your Materials.

Used Shading Models in the Material

When you add different shading models to your material using the Shading Model expression, they are convienently listed next to Used Shading Models in the Details panel when the Material Inputs or Material Attributes node is selected.

Mat_UsedShadingModels.png

This example shows three Shading Models are set in this Material using the Shading Model node.

Keep in mind that this list only shows shading models set in the Material Graph and does not represent what is actually compiled, since Switch nodes can be used to remove entire parts of the graph, including shading models. For examples of this, see the Material Switch Nodes section below.

Blending Material Attributes

When using the Material Attributes workflow, there is a custom blend operation for the Shading Model parameter input with the rest of the Material Attribute parameters blending like normal.

Use the Shading Model node to select a shading model from the Details panel and then use the BlendMaterialAttributes node to blend them both.

BlendMaterialAttributes_Diagram.png

The Alpha input the Shading Model selects A if the alpha is less than 0.5f or selects B if it is greater or equal to 0.5f.

In this example, the Material Graph shows uses the SetMaterialAttributes node to set up two separate Materials. Each is using a Carbon Fiber texture with the top part of the graph using the Default Lit shading model. The bottom part of the graph is using the Clear Coat shading model. The BlendMaterialAttributes node is blending both of these different shading models together and using the Alpha input parameter as a mask on the combined material.

Click image for full size.

When the Material is applied to our Static Mesh, this Material Slot is only using a single draw call to render these two shading models instead of two draw calls. With the Alpha mask applied, you can see that top left is using a Clear Coat shading model with a dual normal while the top right is using Default Lit.

BlendMaterialAttributes_Result.png

If-Statements

An If expression can be used to the float value of A to B to set the Shading Model that is used, like the example below.

PerPixel_If_Graph.png

By default, if no value is set for B, it defaults to a value of 0. You can set a hardcoded value in the Details panel, use another float value derived from a texture or constant, or set up a parameter for the B input to control it within a Material Instance.

In the comparison below, the If expression evaluates value of B against A to set the shading model to either Default Lit or Clear Coat. If the float value of A is greater than that of B, Default Lit is used, if A is less than B, Clear Coat is used.

A > B: Uses Default Lit | B = 0.0

A <= B: Uses Clear Coat | B = 0.5

Switch Nodes

Use the available Switch nodes below to control functionality and quality of your material.

Mat_Switches.png

  • A Shading Path Switch is useful for specifying what part of your material logic should be used for a render path.

  • A Quality Switch is useful when using the engine's quality levels to control material logic.

  • A Feature Level Switch is useful when setting up a material for use on different devices.

  • A Static Switch or Static Switch Parameter is useful to exclude entire branches of your material in a base material or controllable through a Material Instance.

In the graph and comparison below, a Static Switch expression sets the shading model to Default Lit when set to True and Clear Coat when set to False.

Click image for full size.

Static Switch = True | Default Lit Shading Model

Static Switch = False | Clear Coat Shading Model

Material Instancing

Material Instancing is fully supported enabling you to setup and use logic in your Material Graph to drive parameters and variables to set which shading model(s) is used.

Keep in mind that the Material Instances shading model is shown as From Material Expression and it can be overridden to a static shading model. However, you cannot override a Material Instances shading model to be From Material Expression, it will silently fail and do nothing.

Additional Information

  • Shading Model Input Always Shown Enabled

    • When Use Material Attributes is enabled and using the Set, Get, Make, or Break Material Attributes nodes, the Shading Model input will always be shown enabled (not grayed out) even though From Material Expression may not be set as the selected shading model. The pin will not do anything unless From Material Expression is set as the shading model for the Material. This does not affect the Main Material Inputs node that is default.

  • Material Instance Overrides

    • Overriding the Shading Model of a Material Instance works as expected, however, setting it to From Material Expression will silently fail and do nothing unless the Parent Material uses it.

  • Unlit Shading Model

    • There is a lot of information that is compiled out, which means means that shading path cannot be properly supported without introducing regressions.

Tags
Select Skin
Light
Dark

Welcome to the new Unreal Engine 4 Documentation site!

We're working on lots of new features including a feedback system so you can tell us how we are doing. It's not quite ready for use in the wild yet, so head over to the Documentation Feedback forum to tell us about this page or call out any issues you are encountering in the meantime.

We'll be sure to let you know when the new system is up and running.

Post Feedback