The example explained in this article is creating a blend between a mud material, and a mud-leaves material using a mask (Alpha) texture.
>> The scanned PBR materials in demonstrated in this post are from Texture Haven (texturehaven.com)
How does it work? There is actually no blending of Unreal materials, but rather a regular Unreal material in which each of the parameters is defined as a linear blend between 2 different source values for that parameter.
We could create such a material blueprint that uses a Lerp (Linear Interpolate) node’s to provide each of the material parameters with a blend of 2 input textures/colors or parameters, connecting the alpha texture to all the Lerp nodes’s Alpha input, and effectively achieve blending of 2 different materials, but it would be a complex blueprint in which it’s very inconvenient to design each of the individual materials participating in the blend:
This complexity can be greatly simplified by collecting each of the participating materials parameters into a Material Attributes data structure.
The Material Attributes data structure contains all the data needed to compile a material, and allows input, output, and processing of this data as a single blueprint data stream (connection).
For example, when the material parameters are grouped as a Material Attributes data structure, they can be blended by connecting them into a single BlendMaterialAttributes node, instead of “Lerping” (blending) between 2 inputs to create each individual material parameter, which produces an unworkable complex material blueprint like the previous example.
> To collect material parameters into a Material Attributes data structure, connect them into a MakeMaterialAttributes node:
> To create a blend between 2 Material Attributes data streams, use the BlendMaterialAttributes node:
* The Alpha parameter determines the weights of the blend (a black and white texture can be connected to it as the blend mask)
> In order for the material output to receive a grouped Material attributes input instead of individual inputs for each parameter, select the material output, and in the Details panel, check the Use Material Attributes option:
Using the Material Attributes data structure, the blended material’s Blueprint in now much simpler and cleaner, while producing the exact same result as before:
But designing 2 different materials within one material Blueprint is still far from being ideal..
What if we want to use just one of these materials on some surfaces?
What if the individual materials are not as simple as the materials shown here, it would be mush more efficient to be able to have one Blueprint for each of the materials allowing to focus on its development and preview it.
We can achieve this desired workflow by developing each of the materials as a Material Function.
Each of the participating materials is created as a Material Function with a Material Attributes output.
> One of the huge advantages of UE4’s material editing is that it allows us to preview a full material while developing it as a Material Function.
* This may sound trivial, but it isn’t. the Material Function isn’t compiled by itself as a material, it just produces data needed to define a material. in many other media production systems, this would have meant that you can develop data within the function but only preview it in the main material where the function is used.
The Material Function defining the mud-leaves material:
The Blend material using the Material Function nodes:
When blending a non-metallic material with a metal material, the alpha values (mask colors) should be only 0 or 1 (black or white), otherwise blend areas that have a mid-range metallic value will make no sense visually.
> A RemapValueRangenode can be used to force a color threshold on the mask texture or value.
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 ColorAngleBlendMaterial Function will have the following inputs:
The color or texture appearing when viewing the surface at perpendicular angle.
The color or texture appearing when viewing the surface at grazing view angle.
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 Fresnelproviding 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 Fresnelnode.
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.
Having to remap a value range is very common in designing shaders, whether it’s to perform a traditional “levels” operation on a texture, or use just a specific range of values in a float input.
The RemapValueRange node let’s us do just that. this node has 5 inputs:
Input: The input value
Input Low: Input mapping range minimum
Input High: Input mapping range maximum
Target Low: Output range minimum
Target Height: Output range maximum
Mono Noise examples:
The original noise pattern:
Mapping input 0 -> 1 to output 0 -> 1 obviously has no effect:
Mapping input 0 -> 1 to output 0.3 -> 0.7 reduces the pattern contrast:
Mapping input 0.3 -> 0.7 to output 0 -> 1 increases the pattern contrast:
Mapping input 0 -> 1 to output 1 -> 0 inverts the pattern:
In this example RemapValueRange nodes are applied to a texture’s individual color channels to increase contrast (Levels): > Note that this operation can be performed using a simpler graph by using float3d adding and multiplication operations on the texture color (this will be a subject for a different post) > Note that a different remapping operation can be performed on each color channel of a texture to adjust its color balance.
Before the value remapping:
After the value remapping tha value in each channel 0.1 -> 0.9 to 0.0 to 1.0:
The same operation performed by multiplication by 1.2 and subtracting 0.1:
The Delay node serves as a timer that will execute the connected blueprint after a predefined time in seconds.
An example of usage could be triggering a game event at a set time after the player entered a location.
You can use random values or other expressions connected to the Duration input to create a richer and less predictable interaction.
The quest to find an affordable Node-Based Compositing software
I generally prefer doing compositing for video and 3D animation using Node Based Compositing software.
In the past I worked happily with Autodesk Combustion, until it was discontinued, than I went on working with Autodesk Composite (Toxik) which was also kind-of discontinued, and was installed as part of the 3ds max package, and can still be downloaded for free at Autodesk Exchange.
Autodesk Composite is an awesome compositing technology, and I did a lot of work with it, but the only reason I could afford it in the first place was that Autodesk stopped actively developing it and shipped it as a (rather powerful) ‘goody’ along with 3ds max and Maya. while I can still go on working with Autodesk Composite, Its lack of active development is showing, and I decided to look for a better solution.
Obviously, this discussion can’t be serious without mentioning The Foundry’s Nuke compositing software, which as far as I understand the leading node based compositing solution in the VFX industry today.
But in my small indie studio perspective Nuke is expensive, and for my compositing needs, there’s simply no justification to make the investment.
Another node based compositing software that must be mentioned here is the open source software Natron.
Natron is a very serious development, there’s a growing community around it, and it seams to me that it might be on its way to become the ‘Blender’ of the compositing industry.
I did some tests with Natron 2.1.4, it’s interface is very similar to Nuke’s interface, and from the way the interface is designed, its approach to reading and processing 32 bit float multi-channel EXR file sequences, and it’s current library of available nodes, it’s pretty obvious that this development effort is aiming to be a high end VFX node based compositor.
But for me, there are still some key features missing, like 3D compositing, a vector blur node and more.
* It should be noted that you can add Re-Vision Effects ReelSmart Motion Blur plugin to get vector blur functionality and other features like motion estimation.
Enter Blackmagic Fusion
Fusion is actually not a newcomer in the field of node based compositing.
Initially developed by Eyeon software, it was named ‘Digital Fusion’, than just ‘Fusion’, and in the past decade was heavily developed in the direction of 3D compositing.
If I remember correctly, Fusion was also expensive, I think it cost around 6000 dollars…
But than magic happened..
A couple of years ago Blackmagic Design, which is by-far the most disruptive company in the production and post-production gear industry, has purchased Eyeon software, continued developing it, integrated it into their product pipeline and made it available as a free edition of the software and a more heavily equipped ‘Studio’ edition of the software, that costs 299$, which is absolutely accessible in small indie studio terms.
I downloaded the free edition of the software, and immediately started working with it, getting used to the interface while working on actual animation projects in the past year,
And to cut the long story short, it’s awesome and it’s a very happy ending to my quest for finding a compositing solution, for the following reasons:
Full 32 float workflow.
Robust support for multi-channel EXR file sequences.
Excellent Vector-Motion-Blur and Depth-Blur (DOF) effects,
And many other 3D channel based tools like Volume-Mask, and more.
Very fast GPU accelerated OpenCL processing (render are extremely quick).
In conclusion, my opinion is that it’s a no brainer,
If your looking for an affordable, robust node-based compositing software that’s well equipped for 3D animation needs, Blackmagic Fusion is the answer.
The UE4 Fresnel node is actually a “Facing Ratio” node (aka Perpendicular / Parallel) with some extra control.
It basically allows controlling material effects according to the incident angle the surface is viewed at, which is a hugely important feature for designing advanced material effects.
The steepness of the value / angle curve.
Base Reflect Fraction:
The value at perpendicular angle.
An option to connect World Space surface normals input to affect the output of the Fresnel node.
* Tangent Space normals must be converted to World Space by using a Transform Vector node.
A value of 1.0 for the Exponent parameter, and a value of 0.0 for the Base Reflect Fraction will produce a linear “Facing Ratio” (“Perpendicular / Parallel”) falloff blend.