UE4 Intro To Materials - Page 7
- Part 1 - Getting Setup
- Part 2 - Our First Material
- Part 3 - Material Instances
- Part 4 - Masked and Transluscent Materials
- Part 5 - Illumination
- Part 6 - More Material Concepts
- Part 7 - A Practical Master Material
- In our Metallic and Roughness, we don’t have to use a single number. We can use a gray scale mask so that each pixel can project number between 0 (black) and 1 (white). Lets look at masks in materials on metallic. Open the Content Browser and select the Textures folder:
- Press the Import button and go to the folder Files Neede For Walkthrough and select CircleMask_D.tga.
- Rename the file and add
T_in front of the new file to end up with
T_CircleMask_D. Go to the Materials Folder and create a new Material called
- Open the Material and add a Texture Sample node and selected the new texture we just created T_CircleMask_D.
- Add a Constant 3 node and select a strong color. I picked a very bright green.
- Lets add these two nodes together. Put an Add node and hook the texture up with the Constant 3. The addition will keep the white white, but make the black the green that was created. Connect the output of the addition mode to the Base Color node and look at the result on the sphere:
- Add a constant node set to
0and plug it into the Roughness pin. Connect the Texture Sample to the Metalic node. Now every where it is white it will be reflective and every where it is black it will not. You can see the result on the sphere.
- Go into the game and move the camnera to Room 3. Change to Place mode and select the Basic menu items. Drag a Cube into the game window. Name the cube
Reflecting Cubeand move it to the Room 3 folder.
- Assign the material we just created. Go to World Outliner | Lighting | Sphere Reflection Capture volume and make sure the Influence Radius is set to
2000and center it on the level.
- You might find some black reflections. Go to Skylight and change Mobility to
- Run the game and go around the cube to look at the reflections.
- Now what if we wanted the opposite? What if want the green dot to be reflective and the rest of the surface be matte? We could go to photoshop and invert the image, but we can do this in the material. Open the M_Metallic and add a OneMinus node:
- Connect the output of the Texture Sample to the 1-x node and put that output in Metallic. Select the cube to preview and now you can see that it only reflects inside the green dots.
- To see what the 1-X node does, right click and select Start Previewing Node. See how it just inverts the image:
- Go into the game and play it and look at the cube. The metallic effect is now reversed:
- We have only dealt with opaque materials. We can also have holes cut in the materials with transulcency. There are two types of approaches. The faster in terms of performance is an opacity mask. This means that a pixel can be completely transparent. But there are no partial transparencies. The pixel is opaque or is clear. Lets take a look. Create a new Material in the Materials folder and call it
- Double click the new Material and add a Texture Sample node. Add the T_CircleMask_D texture and you should see:
- Connect the output of the Texture Sample node and connect it to the Opacity Mask mode. This does nothing and it is grayed out. We will fix this shortly.
- Add a Constant 3 vector and pick a nice bright color. I picked orange:
- Now the Opacity mask is supposed to be clear where there is an alpha (black pixel) and opaque where white. Right now we just have a solid Orange surface.
- There are different blend modes available in the shaders. To read more about it go to this section in their manual. Now select the Blend Mode drop down menu and pick Masked:
- Now switch to a cube and you will see that the black areas of the map cut into the cube.
- Now go to the game and press the alt button and drag another copy of the cube. Assign the M_OpacityMastk material.
- You might have noticed that there is no inside of the box. The entire inside is clear. Why is that? In 3-D modelling the light is only reflected where normals are placed. Typically in closed surfaces like cubes there are only normals on one side. Double click the cube static mesh (in the World Outliner) and click on Normals. You should see green lines pointing outwards:
- In the Details panel of your Material there is a Two Sided radio button. This allows you to let the material know that you want to project light on both sides of each face of the object. Look how much better it looks!
- Check out the box in game. Now it looks more like we expect it to. Next up lets make a mask with semi translucent surfaces.