INTRODUCTION
In this lesson, we will learn the basics of materials in Unreal Engine. We will tackle how to make reusable materials and material instances, use different types of input data, and cover essential nodes for material creation. The goal is to have a good understanding by the end of this lesson to create basic materials for Environment Artists.
LESSON OVERVIEW
WHAT ARE MATERIALS?
What are materials in Unreal?
Materials in the Unreal engine can be seen as simplified, user-friendly shaders; a shader is a script that tells the Graphics card how to display our 3D models and textures.The material pipeline in Unreal engine allows us to create these shaders without the need to code, and it takes care of complex parts such as light interaction through presets.
We work primarily through nodes in this pipeline, making it very artist-friendly.
A speed run about how shaders work with our meshes. After modeling an Object in our 3D software, we import it into our engine, where our model exists out of polygons and triangles.The engine will divide each quad into triangles if you do not do it on export. The mesh’s vertices are then loaded into our shader, including the custom data they may contain (such as normals, vertex coloring, etc.).This data is then taken, and we can modify it to what we want, called the Vertex stage (Vertex shader).Then, we take the results of the Vertex stage and cut our triangle into little squares; this is called rasterization.
From there, we move onto the Fragment stage (fragment shader) and color and modify the data in each little square (pixel); this is a one-way process, meaning that we can't modify data from the vertex part in the fragment.
All of this is handled in Unreal Engine when we work with the material editor. Still, it is helpful to understand that a specific order in Unreal Engine will handle our data to understand future errors we might get.
Out of the box, we have a lot of presets in Unreal regarding complex parts of material creation; to master our material creation skills, we will need to understand the presets and options to make good decisions so our materials turn out to be great.
What is a Shading model?
Shading models are presets in regards to how our material interacts with light. Each shading model handles light differently, and some even completely turn off the interaction with light. When we talk about the standard shading model, we talk about the Default lit model, which interacts with light in our scene in a usual way.
Besides default lit, there are two very commonly used shading models in Unlit, which do not use any lights nor specularity, resulting in a very flat surface; this could be used to create your lighting setups, such as cell shading. Another frequently used shading model is the two-sided foliage model, which uses foliage (plants, flowers, trees, etc.) to allow light to pass through both sides of the surface.
There are many more shading models that are created for specific cases such as (Hair, Cloth, Eye, etc.) and most of these require a particular setup.
Blend modes:
The Blend modes control how the material is blended with other objects on screen; this will allow us to enable transparency, mask out parts of our surface, or lighten or darken the pixels behind our object. This way we can create different materials such as glass, ripped fabric or use it to create fog cards.
In the editor, you will see the section called domain type; this refers to what type of shader we are making. In these lessons, we will only cover surface materials, but other domains, such as decals and post-processing, will allow us to create materials for non-3D Objects.
When we are in the surface domain, we will have access to the following blend modes:
Opaque: No blending of the material; displays the surface based on the distance in the scene.
Masked: Masks out all surfaces with an opacity mask value lower than 0.5; otherwise, they are displayed as opaque.
Translucency: Allows for surfaces to be transparent, which is controlled by the opacity.
Additive: Adds the material’s color on top of the color found behind it.
Modulate: Subtracts the color from the surface found behind.
Creating our first Material
Now we have gathered a good understanding of the main settings; we can continue making our first material in Unreal engine. To create a material, we right-click in the content browser and select “Material”. We will name this material “M_ourmaterial.” This follows the naming convention that Unreal suggests. This is recommended to quickly distinguish whether we are working with a material or a material instance.
(To rename objects, click once on the object in the content folder and press F2.)
We can open materials by double-clicking them. This will open the node editor for us; in the node interface, we will see one large node displayed: the Root node. The Root node contains our material inputs, such as (Base Color, Roughness, and Metallic) these inputs will be active (shown in white) and deactivated (gray) depending on the shading model and blend mode. When selecting the Root node, the base settings for the material will be opened in the detail viewport (Which can be found under the preview viewport). Here, you will find all the core settings explained in the first chapter.
By default, our shading model is set to “Default lit” and the blend mode to “Opaque”; for now, we will leave them as is. The default Base color is set to black, so we will adjust this by adding a Base color, which we can do by right-clicking on the background of the node editor; this will prompt the search menu. In this menu, we will search for a Constant3Vector and select it by clicking or pressing enter when highlighted. This will create a Vector 3, a set of 3 floating-point numbers (0.0, 0.0, 0.0).
If we double-click on Constant3, it will open a Color pick menu where we can set the color. Once we have set the color, we can connect the upper pin to the Base Color Input; doing this prompts the debug view to update.**Additionally, we will add two constant1’s for both the roughness and Metallic, finishing our basic material.
Alternatively, you can use the shortcuts for constant, which are ( “1” + left mouse, “2” + left mouse, “3” + left mouse, and “4” + left mouse). Make sure to click on an empty space in the node viewer.
MATERIALS INSTANCES AND PARAMETERS
What are materials Instances?
Material Instances can be seen as a child of our Master material (parent); this material instance has the same parameters that are exposed as the parent material but allows us to give them different values. This way, we can re-use the same material setup but input different values or textures. This gives us additional performance benefits and lets us quickly create a library of all necessary material variations.
Creating parameters
To convert variables into Parameters, we right-click our Data Type (for example, Constant3) and click “Convert Parameter”, this will prompt us to name our variable through the node or in the details panel. The parameter must be part of an active stream to show inside the Material Instance. This means the parameter node influenced one of the Master Node Input slots.
Creating a material instance
We can create a Material Instance by right-clicking our master material and selecting “Create Material Instance.” from there, we can open our Material instance, and it will display our Parameter. For each Parameter type, different settings will be exposed in the detail panel; since most parameters are sliders, we often have a Min and Max value that we can set; once we set these values, the slider will be limited to these values. Setting a minimum and maximum is optional, but it is a good habit to ensure we have numbers that make sense.
Next to these values, we have a section called Material Expression that contains a group drop-down menu; with this group, we can bundle our parameters under groups that will be collapsible.To add a group, click in the middle of the group field and type a custom name; the dropdown menu will then recognize this name in other parameters.In addition to grouping, we can change the order of display of our parameters; this can be done through the sort priority, which will display parameters with a lower value above parameters with a higher value.
When working in a team, we may run into material instances with many parameters; sometimes, these parameters can be challenging to explain. In this case, we have the Desc field, which stands for description. In this field, we can explain the workings of our parameter; this text will be visible when we hover over the parameter name in the Material Instance.
Common parameters types
Now we have a good understanding of how to set a parameter, we can look at the common parameters/data types next to the constants that we covered in the previous section:
Texture Sampler & Texture object
For the Texture sampler, we will have the following options on the setting Sampler source:
- from Texture source: Will create a unique sampler slot per texture
- shared: wrap - Will share the sampler slot and make the UV tile if above 1 or below 0 (tiling)
- shared: clamp - Will share the sampler slot, and if the UV is above 1, repeat the border pixel (useful when you want to scale but not tile)
Per material, we are allowed a maximum of 16 samplers. Therefore, we recommend setting the source to shared-wrap for each sampler.
Inside the base setting of the texture sampler, we can adjust the texture to sample; we can drag our texture from the content browser into this field or use the search function in the detail panel by clicking on the dropdown menu.Underneath the Texture field*, we have the setting sampler type; this needs to match the type set on the texture itself.*
For Albedo & Color information, we want to keep this on color; for normal textures, we can select the designated normal type. For Packed textures, we choose linear colors or masks.
Sometimes, we want to create a single texture parameter and use the texture in multiple samplers; this is where a Texture object node can come in handy. You can switch an existing sampler to a texture object by right-clicking the sampler and choosing “convert to texture object” or searching through the node search menu.This is what the Texture Input (Tex) on the Sampler is used for; as for texture objects, we can convert them to parameters if we need them exposed.
-Static switch Parameter: It acts as a switch with a “true” and “false” input, and this is ideal when you have specific functionality you want to enable as a feature. Alternatively, the Static bool Param can be combined with a switch node.
-Component Mask: When we want to select specific channels (masks), we can use the component to extract the channels that we wish to; this node can also be converted to a parameter.(Example: This can be very handy if we want to switch through a noise stored in the R channel to another in the G channel.)
-Constants: As mentioned earlier in Chapter 2, we can convert constants to parameters; it is essential to know that there are only two types of conversions: constant1 = (1.0) and constant4 = (1.0,1.0,1.0,1.0). If you only want to convert a constant 2, we must choose between two constants or use a “constant 4” and use the other two channels for something else.
Quick Tip: Most input slots can be converted to parameters by right-clicking and “Convert to parameter”.
COMMONLY USED FUNCTIONS
In this lesson, we will talk about commonly used functions that are very helpful in making basic materials. We will cover important settings and tricks with these functions to excel in our skill in material creation:
-Saturate / Clamp:When we want our values clamped between an x and y range, we can use the “clamp” node; the clamp node allows us to choose whether to clamp the min value or the max value and lets us select the values. Alternatively, in scenarios where we need to clamp between 0-1, the saturate provides the same functionality as the clamp node at a very minuscule performance cost.
-SmoothstepSometimes, we want to offset our minimum and maximum values to select specific noise parts without cutting away information. The Smoothstep function is a helpful node that allows us to do this.We can somewhat compare it to the level function found in programs like Photoshop and Substance Designer.
-LerpWe shortened from “Linear interpolation,” a fancy word for blending between 2 values according to a blend value. We mainly use this node whenever we want to blend two values. It’s important to saturate/clamp our blend value to 0-1. 0 means we use value “A” fully, and “1” means we will use value B entirely, where 0.5 will be a 50/50 blend between the two values. Connecting multiple Lerp nodes to create a three- or four-way blend is possible.
-Frac / Floor / Ceil / RoundAll of the four mentioned nodes have to do with manipulating numbers; they are instrumental and can be used to achieve different effects in combination with UV’s and parameters:
Frac is shortened for fraction; frac will eliminate the digit before the comma and keep the decimal numbers. This is great when we have to tile UV’s in a custom setup or create a looping sequence. (1.2 = 0.2) (1.8 = 0.8).
Round is handy if we want to round to the nearest whole number based on the decimal number.(1.2=1) and (1.8=2).
Floor takes a value and rounds it down to the nearest whole number,(1.2=1) and (1.8=1) .
Whereas Ceil does the opposite and rounds up to the nearest whole number,(1.2=2) and (1.8=2).
-UV CoordinateWhenever we want to get the UV Coordinates, we use this node; it has an input to refer to the UV set we want to get. We can manipulate the UV coordinates with simple math operations such as “Multiply” and “Add/Subtract” to scale and offset our Textures.
-TimeIf we want to animate a texture, we can use the time node to reference the time. This can be used together with a UV node to make textures scroll.
-Absolute world positionThis node retrieves the position of our vertices in world space, which could be used to create custom UV’s.
MATERIAL COMPLEXITY
This chapter will discuss using the material complexity view and the statistic panel to gain insight into our material performance. Tracking the performance of materials accurately is a big topic in itself, as many variables and statistics may differ per platform. In our viewport, we can choose different debug modes; some might already be very well known to us, such as Unlit and Lighting Only.In the section Performance*, we can find Material complexity; this debug viewing mode indicates how many shader instructions are used for the material displayed. This should be used as an indication as it is not always accurate, but in the grand scheme, it is an excellent tool for finding performance-heavy materials.
The objects will be colored from green and red to white, where green indicates a low-budget material and white suggests a costly material. This mode can also be accessed by its shortcut alt+8.
Next to material complexity, we also have the stats dialog when we open a material; this will tell us more information, such as the number of individual texture samplers and the total instructions for the material's use. This way, we can adjust our materials and have a general indication of the performance cost of our materials.
EXERCISES
Materials I - Checker Pattern Creation
Materials I - Checker Pattern Creation
OVERVIEW
1. Utilize the Multiply ,UV and fraction nodes to create a checker pattern. 2. Add parameters for Scale and Offset. 3. Add the ability to colorize the white and black squares individually.
EXAMPLES
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.
Materials I - Waterfall Texture Creation
Materials I - Waterfall Texture Creation
OVERVIEW
EXAMPLES
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.
PROGRAMS USED
Placeholder for programs text
Materials I - Create a Material with 3 Textures
Materials I - Create a Material with 3 Textures
OVERVIEW
EXAMPLES
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.