SciFi Bunk: Material Instancing
This tutorial was provided by community member Liam Tart (PogoP), and is published here with permission.
Thank you, Liam!
This tutorial will explain how master materials and material instancing can be used to quickly and efficiently build a set of tileable materials that can be applied to meshes in your scene. By texturing your meshes using tileable materials, you do not have to rely on baking from a high poly model and you can rapidly change the look and feel of your environment.
This tutorial has been written alongside the production of the Sci-fi Bunk Room scene on the Unreal Launcher Learn tab, so it is recommended to download that in order to show this use of material instancing in practice.
This tutorial will show you how to set up an efficient master material that can be instanced to make a variety of different material types, such as various metals and plastics, which can then be applied to different material IDs on your mesh. This master material will also use a number of switches to enable you to turn specific functions on/off depending on the material in question, such as parallax and detail normal maps.
Before starting this tutorial, it is recommend you read the 材质 docs to get a basic understanding of how materials and material instancing work. This tutorial will show how to apply these concepts to a working environment.
The end goal of setting up this master material is to create a material that can be instanced and give access to a number of parameters that will allow us to tweak our materials quickly. You can put whatever options and features you like into your master material, but as a base, it is useful to allow the option to input specific albedo, roughness, metallic, and normal maps, and also have fine control over these features by adding in an albedo tint, and a roughness and metallic value.
The screenshot below shows just how much flexibility this will give your environments, allowing you to quickly change the way your scene looks by tweaking a few values.
Master Material Setup
We will start by creating your master material. This is what all of the materials in your scene will be instanced from, so it needs to be set up correctly and efficiently as it likely get quite complex. One advantage to using a master material is that if you want to add more features to your materials later on, you need only apply it to the master material and it will propagate down to the instances.
Here is an example showing the final master material setup. All of the input textures and constants in this material are parameterized to allow access in the instanced material. To do this, you can right click on the value or map and click Convert to parameter, and then you can assign it a name. This will allow you to change it quickly in the material instance.
Also, the Static Switch parameter is extensively used in this material, which allows you to choose between using certain setups such as detail normal maps, parallax etc. This will make your final material instance cheaper as you are able to switch off un-needed features. More about this can be read here: Parameter Expressions
In this section, you want to be able to choose between using a specific albedo map or a simple color value, which will allow you to rapidly prototype materials by specifying a simple value to get the correct albedo. You can then bring that value through to Photoshop as a base for your final albedo map. This will also apply to the Roughness Setup section of this tutorial.
As stated previously, this setup allows you to choose between using an albedo map or a color value for your base color. You choose between the two by using the static switch parameter called UseDiffuseMap? in your instanced material. If this is set to true, you can then use the input a specific albedo texture, and this is multiplied with a DiffTint constant value which allows you to tint the color of the specified albedo map. If you do not use an albedo map, you can define the albedo value using DiffuseValue.
To the left of the DiffMap texture input, you can see that a node has been plugged into the UV slot. This connects to the Parallax part of the master material. You could add a UV tiling setup into this as well, which would allow you to control the tiling of your material in UE4 rather than in your 3d modeling package.
The following example shows the flexibility of this system. On the left, the material is using a single color for the albedo map. In the middle, it is using just an albedo map. On the right, it is using an albedo map that has been tinted orange. This shows how you can use the same maps to get a lot of variety in the engine.
This is very simple and lets you choose between using a metallic map or a single value to define your materials' metallic properties.
This is useful because it allows you to choose between using a single value, which would be good for a tiling metal material for example, but also gives you the option to specify a metallic map if you want certain parts of your material to be non-metal whilst others are metallic.
The following example shows this in action. The material on the left uses a metallic value of 0, the middle a value of 1, and the one on the right uses a specific metallic map.
Similar to the albedo setup, this allows you to choose between using a roughness map or a single value to define your overall roughness. This is great for quickly assigning roughness values to materials and then later taking this value through to Photoshop to create a unique roughness map for your material.
The following example shows this working. The material on the left uses a roughness value of 1, the middle uses a roughness value of 0, and the one on the right uses a specific roughness map.
The UseDetailRoughness? static switch lets you use a detail roughness map which is plugged into the DetailTiling constant which is multiplied with a TexCoord, to allow you to tile your detail roughness map. This value also plugs into the detail normal map. This is useful for materials that require a texture that can only be viewed up close and can have a very high tiling rate.
The following example shows this in action. The material on the left does not use a detail roughness/normal map, the one in the middle uses a detail map with a tiling rate of 1, and the one on the right uses a tiling rate of 4.
This setup uses a static switch parameter to choose between using an occlusion map or a single value. Most materials will use an occlusion value of 1 which is a simple white color, however this gives you the option to use a specific ambient occlusion map if your material requires it, for example if this material is for a uniquely unwrapped model that has darker areas where light may not reach.
This setup lets you choose between using an emissive on your material or not (by default it is set to false to increase performance). There is also another static switch used which lets you choose to specify a specific emissive map. If you choose to not use a specific emissive map, you can use the EmissiveScale parameter to set your emissive value. However, this EmissiveScale parameter will also be used if you do specify an EmissiveMap, allowing you greater control of the brightness of your material.
The following example shows how this emissive setup works. The material on the left has an emissive scale set to 0, the middle set to 1, and the one on the right is set to 2.
The normal map setup is fairly simple even if it may look slightly more complex. By default, this material will default to a flat normal map texture, though you could add a switch to turn the normal map off and use a constant value instead, which may save on texture memory.
This setup also allows you to combine a normal map with a detail normal map. The DetailTiling constant is multiplied with a TexCoord which allows you to control the tiling rate. The DetailNormalStrength lets you control the strength of the detail normal map.
This parallax setup lets you use a BumpOffset node which gives your materials an illusion of depth if a heightmap is applied. More about this can be read here (Bump Offset ).
This setup is plugged into the UV slots of all the aforementioned sections, meaning if parallax is enabled then all your maps will receive the effect.
The following example shows how the Parallax effect works. On the left, Parallax is disabled, and on the right, Parallax is set to 0.007. It's a fairly subtle effect but may work well depending on the material in question.
Now that your master material is setup, you can right click on your master material and crate a material instance.
You can then name this material and organize it in whichever folder you like. I'd recommend setting up folders per material type, ie, a folder for all your metals, a folder for plastics, etc.
You can now double click on your newly created material instance and you will see the following:
As you can see, all of the parameterized values and static switches that we set up in the master material are visible here in the material instance. Enabling switches such as UseDiffuseMap? will enable you to input your own diffuse/albedo map, and will also enable certain parameters tied to this, such as the diffuse multiply option in this case.
Here is my material setup for the Sci-fi Bunk scene. You can see that I have created a library of tiling materials with various colors and material properties, which can easily be applied to meshes in the scene.
Application to Meshes
Now that you have a material library set up, you can easily apply these tiling materials to your meshes. As you can see in the following image, this mesh doesn't use any uniquely baked normal maps, but instead relies on tiling materials to build up a believable surface. When you have an entire library of meshes built this way, you can see the advantages to using material instances, as you are able to tweak one single value and it will propagate throughout your scene. For example, if I wanted to change the wood texture used in this scene, I'd only have to change it once in the wood material instance, and my entire scene would update. This is far quicker than having to re-texture several unique diffuse maps.
Now that your base master material and material library is set up, you can easily expand your master material and give it more features. For example, in this material setup, there is no option for vertex painting. You could add a basic lerp function combined with vertex paint to allow you to, for example, paint dirt on to your material surfaces. More information on this can be read here: 2路混合材质 .
That should be all you need to get a basic master material setup for your scene. Remember to check out the Sci-fi Bunk Room scene to see exactly how this can be applied. Good luck!