Material functions in Unreal Engine sound scary, and I remember I was avoiding them as they sounded more like something programmer would use. None of my concern.. I thought. Well, I was wrong. These are super easy to create and use.
The concept of a material function is very simple. They are like a containers or building blocks that have outputs and sometimes inputs as well.
![Creating material functions in Unreal Engine is easy](https://i0.wp.com/www.creativewithjaakko.com/wp-content/uploads/2021/09/materianfunction.jpg?resize=1134%2C638&ssl=1)
You can create Material Function by right clicking empty area in content browser and diving to Materials & Textures. Choose Material Function.
What you can see is a lonely Output Result node. Let’s build something.
![Empty material functions in Unreal Engine](https://i0.wp.com/www.creativewithjaakko.com/wp-content/uploads/2021/09/fqc1QrQ.jpg?resize=832%2C556&ssl=1)
Let’s say that we want to create reusable roughness adjusting function. This is just a very simple example, but you can see how this technique could be used to make very advanced adjustable materials.
Lets start by making a scalar input to this. Right click on canvas and type “input” and choose Function Input. By default it is Vector3 but we only a single value, so choose Function Input Scalar from the left side Input Type. If you want to create material functions dealing with RGB color, choose 3 way vector for that.
![](https://i0.wp.com/www.creativewithjaakko.com/wp-content/uploads/2021/09/uB6ognD1.jpg?resize=1164%2C685&ssl=1)
Lets call this RoughnessInput. You can name it as you like in the Input Name.
Next press M on keyboard and left click on empty area of the canvas this will create Multiply node. Connect a line from the newly created RoughnessInput to the A input of the Multiply. Right click on B and select “Promote to a parameter”.
![](https://i0.wp.com/www.creativewithjaakko.com/wp-content/uploads/2021/09/EqrWqiH.jpg?resize=883%2C556&ssl=1)
Let’s name this parameter RoughnessStrength and give it a default value of 0.5. We are almost done.
Just drag a line from Multiply to the Output Result node. Our Material Function is now complete.
![A completed material function](https://i0.wp.com/www.creativewithjaakko.com/wp-content/uploads/2021/09/6P9gUlasdn-2.jpg?resize=890%2C576&ssl=1)
It will accept Roughness (well actually any scalar value) as input and we have created a parameter that multiplies the input. Actually any parameters or switches we create along the way can be adjusted in resulting child materials. Let’s test it.
![](https://i0.wp.com/www.creativewithjaakko.com/wp-content/uploads/2021/09/x7OLsMC.jpg?resize=1500%2C609&ssl=1)
Here I have a lovely pink material. Its very simple, just color and .5 roughness value. Let’s drag and drop the function we created and connect it as follows.
![](https://i0.wp.com/www.creativewithjaakko.com/wp-content/uploads/2021/09/BOkMxOI.jpg?resize=657%2C428&ssl=1)
Now we have this. In order to see and adjust the param, let’s create material instance of this material by right clicking the material in the content browser.
![](https://i0.wp.com/www.creativewithjaakko.com/wp-content/uploads/2021/09/materialinstancecrt.jpg?resize=1112%2C668&ssl=1)
Now we have a new Global Scalar Parameter in the material instance that controls the roughness strength.
![](https://i0.wp.com/www.creativewithjaakko.com/wp-content/uploads/2021/09/yHE4kMd.jpg?resize=1243%2C772&ssl=1)
Of course, this is more handy when dealing with more complex materials.
I have created a special FoliageSet function that contains several aspects of entire foliage material, including wind effect. This was then fed to a master material, from which all foliage material instances in a level were created. This means I had to do this work only once, and now there can be several hundred different foliage assets that get their values from this one.
![](https://i0.wp.com/www.creativewithjaakko.com/wp-content/uploads/2021/09/materialfunctions.jpg?resize=1055%2C627&ssl=1)
This is what the FoliageSet function contains:
![](https://i0.wp.com/www.creativewithjaakko.com/wp-content/uploads/2021/09/kDiU6JB.jpg?resize=1144%2C576&ssl=1)
It’s messy, I should have tidied it up a bit more, still way better than having all of this in every single material. I bet this is faster too. So let’s take a closer look.
![](https://i0.wp.com/www.creativewithjaakko.com/wp-content/uploads/2021/09/8m2iZrJ.jpg?resize=1143%2C580&ssl=1)
For example the T_Basecolor is a texture parameter, in other words empty slot which shows up in the final Material Instances. So what we are making here is a template for the assets. Parameters we define in material functions will show up in Material Instances that are derived from the master materials.
Here is other example.
![](https://i0.wp.com/www.creativewithjaakko.com/wp-content/uploads/2021/09/EafCpVz.jpg?resize=1144%2C510&ssl=1)
This is a world position offset style wind effect that is cheap to calculate. You can see that this refers to F_TreeWind material function, sets several parameters and a Switch Param and finally feeds into output that is called OutputWPO. So the material functions can have a hierarchy and can be built from blocks like this. This really helps in organization and the right mindset of creating materials modularly.
Please also check adjusting normal map strength tip I posted earlier.
Trackbacks & Pingbacks
[…] you are new to material editor in Unreal check out this small tutorial on using material functions. It is easy and […]
Comments are closed.