Placing Material Expression and Functions

Material Expressions and Material Functions are the building blocks used to create fully functional Materials inside Unreal Engine 4. Each expression or function is a self-contained black box that can run little snippets of code on their inputs and output the results. In this How-to guide, we will be learning the various ways that we can place Material Expressions and Material Functions inside of the Material Graph.

Material Expressions

Material Expression nodes contain tiny snippets of HLSL code that perform very specific tasks inside of a Material. Materials are built using combinations of Material Expression nodes that are combined together to do certain tasks. For example, if you want a Texture to move inside of a Material, you can use the Panner Material Expression node. This node contains specific HLSL code that tells the Material to move the UV coordinates of the Texture that it is applied to in a specific direction, making it look like it is moving. As you will soon see, Material Expression nodes are key to building and interacting with the Materials you create.

Difference Between Material Expressions and Material Functions

While Material Expressions and Material Functions are the building blocks used to create Materials, there are some differences between the nodes and how they work. The main difference between Material Functions and Material Expressions is that Material Functions are made inside of the Material Function Editor and saved assets in the Content Browser.

  • Material Expressions : Material Expressions are static pieces of code that can only do what they are programmed to do. For example, a Multiply node can only Multiply, it will never be able to add two numbers together. The only way you could change this was to make changes to the source code.

  • Material Functions : Material Functions are more dynamic because you can create Material Functions to perform any type of calculations you want. If you wanted your Material Function to have the ability to not only Multiply but also Add, you could set it up to do so as those changes would be made right inside the Material Function Editor without having to make source code changes.

Placing Material Expressions

You can place Material Expression into a Material Graph in the following three ways.

Drag and Drop from the Palette

You can drag and drop any Material Expression right form the Palette menu directly into the Material graph. To do this, search for the Expression that you want and then click on it with the Left Mouse Button and then drag it into the Material Graph. When you release the Left Mouse Button, the Material Expression will be placed in the Material graph.

Right-Click Search

You can also add Material Expressions by Right-Clicking anywhere in the Material graph and then selecting the Material Expression you want from the menu context menu by clicking on it with the Left Mouse Button to place it in the Material graph. You can also use the keyboard to search for the Material Expression you want. When you find the one you are looking for, press the Enter key to place the Expression node in the Material Graph.

Keyboard Shortcuts

There are a number of Keyboard shortcuts that you can use to help you quickly place down Material Expressions that are most commonly used. You can change what key spawns what Material Expression by going to Edit -> Editor Preferences -> Keyboard Shortcuts -> Material Editor Spawn Nodes.

Here is a list of the current default keyboard shortcuts and what Material Expression will be created when the keys are pressed.

Keyboard Shortcut Key Material Expression
A Add Material Expression
B Bump Offset Material Expression
1 Constant Material Expression
2 Constant2 Vector Material Expression
3 Constant3 Vector Material Expression
4 Constant4 Vector Material Expression
D Divide Material Expression
I If Material Expression
L Linear Interpolate Material Expression
F Material Function Material Expression
M Multiply Expression
N Normalize Expression
O One Minus Expression
P Panner Expression
E Power Expression
R Vector WS Expression
S Scalar Expression
U Texture Coordinate Expression
V Vector Sample Expression

Placing Material Functions

Material Functions can be placed inside of a Material Graph in the exact same manner as Material Expressions.

Drag and Drop from the Palette

You can drag and drop any Material Function right from the Palette menu directly into the Material graph. To do this, search for the Function that you want and then click on it with the Left Mouse Button and drag it into the Material Graph. When you release the Left Mouse Button, the Material Expression will be placed in the Material graph.

The Palette offers the ability to filter your search so that you can limit your search results to either Expressions, Functions, or both. To set your search filter settings, use the Left Mouse Button to click on the Category button and then select what you wish to search for from the drop down menu.

Placing_Functions_Search_Options.png

Right-Click Search

You can also add Material Functions by Right-Clicking anywhere in the Material graph and then selecting the Material Function you want from the menu context menu by clicking on it with the Left Mouse Button to place it in the Material graph. You can also use the Keyboard to search for the Material Function you want by typing the name of what you are looking for in the Search box. When you find the one you are looking for, press the Enter key to place the Function node in the Material Graph.

The Right-Click menu cannot filter by Functions or Expression and displays them both when you are searching.

Material Function nodes will always have the color Blue at the top. You can also use the Left Mouse Button to Double Click on them to open them up to see what they do.

Placing_Functions_Functions_Blue_Tops.png

From the Content Browser

One thing that is exclusive to Material Functions is that you also have the ability to Drag and Drop them from the Content Browser into your Material graph. To do this, find the Material Function you want to use in the Content Browser then click on it with the Left Mouse Button and drag it into your Material graph. Once your Mouse is over the Material graph, release the Left Mouse Button to add the Material Function you selected.

To find the Material Functions in the Content Browser, you will need to look in the Engine folder. However, by default the Engine folder is disabled and to see it you will need to enable it. To do this, use the Left Mouse Button to click on to View Options that is on the lower right hand corner of the Content Browser. Then from the pop-up menu, select the Show Engine Content option to display the content in the Engine Folder.

Conclusion

Material Expressions and Material Functions are key to getting what you want out of the Material Editor. No matter what type of Material you are building, the Material will always be made up of a combination of Material Expressions and or Material Functions. Keep in mind that when adjusting Material Functions that are currently in use, you can run the risk of breaking other Materials and Material Instances that use that Material Function. Also if you are unsure what a specific Material Expression node does, you can always do a quick internet search for the name of the Material Expressions node. Because most of the Material Expressions nodes are pure HLSL code, node just in node forum, the official Microsoft documentation on HLSL can sometimes help you figure out what the Material Expressions might do.

Tags