Friday, 10 October 2014

About textures and materials (Part 3)

Right now I've been talking about textures and mentioning materials several times, but what are exactly materials in UE4? Materials are in fact what we call in other engines "shaders" which are usually small pieces of code that tell the GPU how to handle the textures, how to react to current lightning and how it looks like. Theses shaders are usually programmed in their own language which is HLSL on DirectX environments and GLSL on OpenGL platforms.
Designers and artist don't find this very user friendly so they invented a graphic solution to quickly make shaders with only boxes and cables.

Even if we are not touching code in the end, making materials has some math involved applied to colors and textures, and it's good to still know what a vector is, and what happens when you multiply something by 0.

When making very simple material, this could be your average setup.

Material network 1

Assuming that your textures have been correctly done in Photoshop, this may be ok for most of your materials, but you normally want to have some control on certain things besides the specular and the roughness.
The first tweak I usually add is a way to control the intensity of my normal maps.

Material network 2

We multiply both Red and Green channels by a parameter so we can easily tweak the strength of our material normal texture, and even flip it if we multiply it by a negative number .

In this example, I packed the ambient occlusion in the alpha of my color texture, so lets plug it in AO and add something extra to have some control.

Material network 3

Using a power expression, I can increase the contrast of the AO input using a single parameter. If by any chance I don't like the AO on my material, I can turn the image completely white by setting the AO contrast parameter to 0.

Now, lets add some mask to roughness, metalicness and specularity. In theses case I'm going to use a liner interpolation (lerp for short) to adjust the intensity of the mask. Since the material is starting to get crowded, I will use some comment boxes to keep things clear.

Material network 4

Actually, we are doing lerps to black, but what if we want to do a lerp to white? We can add some switch parameter which will help us to do some tweaking in our material instance. If you didn't notice yet, this is going to be a master material, this means, we will be able to make instances from this one using different input parameter and/or textures. Anyway, lets add those switches.

Material network 4

Now, to finish, we will add a very simple parallax effect. For this we will need a displacement map which for this example, it is packed in the alpha channel of our normal texture. The parallax technique we are going to use is pretty simple but effective, and is known as iterative parallax. I learned about it thanks to this guys blog. Please check it out if you are interested in the subject since he shares some good gems about Unreal Engine.

Material network 5

The height ratio parameter it's pretty sensitive and only values between 0.2 and 0.05 should be used. Also you may notice some texture shimmering, that can be solved adding more iterations at performance cost.

Right now we are done with the master material. To make profit from the parameters we have to make a material instance using this material as parent.

Material instancing

This way we can make several types of material using only one and switching the textures and the values to proper ones.

You may download here this material right here (to install, just unzip the content inside any existing UE4 project)

And well, I guess that's enought for today. Thanks for reading! :D


Post a Comment