Unreal Engine 4 Materials Tutorial

In this Unreal Engine 4 materials tutorial, you will learn how to modify textures in the material editor, create material instances and update material instances during gameplay. By Tommy Tran.

Leave a rating/review
Save for later
Share

Unreal Engine 4 Materials Tutorial

Like the real world, games contain a variety of objects — each with their own appearance. In Unreal Engine, materials define these appearances. What color is it? How shiny is it? Is it transparent? These are all defined within a material.

Materials are used for pretty much any visual element in Unreal Engine. You can apply materials to various things such as meshes, particles and UI elements.

In this tutorial, you will learn how to:

  • Manipulate textures to change their brightness and color
  • Use material instances to quickly create variations
  • Use dynamic material instances to change the color of the avatar as the player collects items

In this tutorial, you will be navigating the material and Blueprint editors. If you are not familiar with them, please read our Getting Started and Blueprints tutorials.

Getting Started

Download the starter project and unzip it. To open the project, go to the project folder and open BananaCollector.uproject.

Note: If you get a message saying that the project was created with an earlier version of the Unreal editor, that’s OK (the engine is updated frequently). You can either choose the option to open a copy, or the option to convert in place.

You will see a small area containing bananas. Press Play to control a red cube using the W, A, S and D keys. You can collect bananas by moving into them.

To start, you will modify the banana material to change its brightness. Navigate to the Materials folder and double-click on M_Banana to open it in the material editor.

To adjust the brightness of the banana, you need to manipulate its texture.

Manipulating Textures

At its most basic, a texture is an image, and an image is a collection of pixels. In a colored image, the color of a pixel is determined by its red (R), green (G) and blue (B) channels.

Below is an example of a 2×2 image with each pixel’s RGB values labelled.

Note: In Unreal Engine, the range of the RGB channels is 0.0 to 1.0. However, in most other applications, the range of the RGB channels is 0 to 255. These are just different ways of displaying the same information and does not mean Unreal Engine’s color range is smaller.

Texture manipulation works by performing an operation on every pixel of the texture. Operations can be something as simple as adding a value to the channels.

Below is an example of clamping each channel to a range of 0.4 to 1.0. Doing this raises the minimum value of each channel which makes each color lighter.

Here’s how you would do it in the material editor:

Next, you will use the Multiply node to adjust the brightness of a texture.

The Multiply Node

The Multiply node does as its name suggests: it multiplies one input by another input.

Using multiplication, you can change a pixel’s brightness without affecting its hue or saturation. Below is an example of decreasing the brightness by half by multiplying each channel by 0.5.

By performing this operation on every pixel, you can change the brightness of the entire texture.

Although not covered in this tutorial, you can use the Multiply node in conjunction with a mask texture. Using a mask, you can specify which areas of the base texture should be darker. This is an example of masking a stone texture using a tiles texture:

Masking works because the greyscale represents the 0 (black) to 1 (white) range.

White areas have full brightness because the channels are multiplied by 1. Grey areas are darker because the channels are multiplied by values less than 1. Black areas have no brightness because the channels are multiplied by 0.

Now, it’s time to use the Multiply node.

Adjusting Texture Brightness

Break the link between the Texture Sample node and the Base Color pin. You can do this by right-clicking either pin and selecting Break Link(s). Alternatively, you can hold the Alt key and left-click on the wire.

Create a Multiply and a Constant node. You can create these quickly by holding the M key (for the Multiply node) or the 1 key (for the Constant node) and then left-clicking an empty space in the graph. Afterwards, link everything like so:

This setup will iterate over every pixel and multiply each channel by the Constant node’s value. Finally, the resulting texture is then outputted as the Base Color.

Right now, the resulting texture will be black because the multiplier is set to zero (multiplying by zero results in zero). To change the value of the multiplier, select the Constant node and go to the Details panel. Set the Value field to 5.

Click Apply and then go back to the main editor. You will see that the bananas are a lot brighter now.

Let’s spice it up by adding some different colored bananas. Although you could create a new material for each color, an easier way is to create a material instance.

About Material Instances

A material instance is a copy of a material. Any changes made in the base material are also made in the material instance.

Material instances are great because you can make changes to them without recompiling. When you clicked Apply in the material, you may have noticed a notification stating that the shaders were compiling.

This process only takes a few seconds on basic materials. However, on complex materials, the compile times can increase dramatically.

It’s a good idea to use material instances when you:

  • Have a complex material and want to quickly make changes
  • Want to create variations of a base material. These can be anything such as changing the color, brightness or even the texture itself.

Below is a scene using material instances to create color variations. All the instances share the same base material.

Before you create an instance, you need to create parameters in the base material. These will show up in your material instance and will allow you to adjust properties of your material.

Tommy Tran

Contributors

Tommy Tran

Author

Over 300 content creators. Join our team.