Unreal Engine 4.24
Material Functions encapsulate shading flow graphs (material blueprints) into reusable shading nodes that have their own inputs and outputs.
This allows development of custom shading nodes, and saving the time it takes to recreate the same flow graphs multiple times or even copy and paste material flow graphs.
Common shading processes and operations that have to be performed in many different materials, and even multiple times in a single material can be defined as a Material Function for quick and easy re-usability.
Material functions can also be used to encapsulate a full material blueprint with a Material Attributes output. this provides a convenient workflow for blending different materials together.
In this post I’ll detail the steps needed to create and use a Material Function.
The Material Function example we’ll create, called “ColorAngleBlend” performs a commonly needed shading operation of blending 2 colors or textures according to the surface viewing angle (facing ratio).
The ColorAngleBlend Material Function will have the following inputs:
- color a:
The color or texture appearing when viewing the surface at perpendicular angle.
- color b:
The color or texture appearing when viewing the surface at grazing view angle.
- curve exponent:
The steepness of the blend curve between the colors, 1 being a linear blend and higher values displaying color a at more angles “pushing” color b to be seen only at grazing angle.
- base color blend:
The percent of color b seen at perpendicular view angle.
bump normals input.
The final “ColorAngleBlend” Material Function Blueprint:
* The internals of the “ColorAngleBlend” Material Function
An example of the “ColorAngleBlend” Material Function node used to create a reach view-angle dependent color blend for a steampunk metal material:
An example of the “ColorAngleBlend” Material Function node used to create a reach color for a car-paint material:
An example of the “ColorAngleBlend” Material Function node used to create a washed-out effect for a cloth material:
Steps for creating the “ColorAngleBlend” Material Function:
- In the content browser, create a Material Function Object and name it “ColorAngleBlend”:
- Double click the ColorAngleBlend Material Function to open it for editing:
- Click the background of the work space to deselect the Output Result Node,
So that the Details panel on the left will display the Material Functions‘s properties.
Type a description into the Description field, check the Expose to Library option so that the new Material Function will be available to all materials in the Palate and node search, and define in which node categories it should appear:
- Select the Output Result node and in the Details panel on the left set its output name to “color”:
- Add a Linear Interpolate (Lerp) node, a Fresnel node and a Transform Vector (Tangent space to World space) node to the Blueprint and connect the nodes like this:
* The Lerp node will blend the 2 color inputs with the Fresnel providing view angle data as the alpha for the Lerp.
The Transform Vector node is needed to convert normal (bump) input to world space for the Fresnel node.
- Adding function inputs:
Create 2 Function Input nodes, in their Details panel, name them “color a” and “color b”, leave their Input Type as default Vector3D, check the option Use Preview Value as Default, number their Sort Priority parameters 0 and 1 to make them appear as the first inputs of the ColorAngleBlend node as it will appear when used in a material, and connect them to the Lerp node’s A and B inputs:
- Adding function inputs:
Create 2 new Function Input nodes, name them “curve exponent” and “base color blend”, this time set their Input Type to Scalar, check the option Use Preview Value as Default, set their Sort Priority parameters to 2 and 3 and connect their outputs to the Fresnel node’s ExpoentIn and BaseReflectFractionIn inputs:
- Adding function inputs:
Create the final Function Input node, name it “normal“, set its Input Type to Vector3D, check its Preview Value as Default option, set its Sort Priority to 4, and connect its output to the Fresnel node’s Normal input:
- Adding default inputs:
Finally, add constant nodes to serve as default input values for the Material Function.
A pure white Constant3Vector (color) constant as the default value for “color a” input,
A pure black Constant3Vector (color) constant as the default value for “color a” input,
A Constant with value 1.0 as the default value for “curve exponent” input,
A Constant with value 0.0 as the default value for”base color blend” input,
A pure blue Constant3Vector (color) constant as the default value for “normal” input.
> Tip for quick creation of constant value nodes
- Save the new Material Function.
To use the new ColorAngleBlend Material Function create a new material, in the node search start typing color… to locate the ColorAngleBlend node and create it, and connect it to the desired material input.
> Material Functions can also be used by dragging them from the Content Browser into the Material Blueprint.
UE4 – Procedural Bump Normals
UE4 – Material Instances
UE4 – Fresnel node
UE4 – Triplanar mapping