UE4 Intro To Materials - Page 8
- 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
Translucent Blend Mode
- Some objects like glass need to be translucent. Now in games we want to try and limit how many we use. This material is very expensive computationally and should be used with discretion. Create a new material called
M_Translucentand place it in your Materials folder.
- Go to the Textures folder and add CircleMask_T to the game and rename it to
- Open the M_Translucent material and add a Texture Sample node:
- Assign the newly dowloaded Texture called T_CircleMask_T Now for the mask we see the gray. This will be partially opaque. The white rings will be completly opaque and the black will be transparent like in the previous mask. Now it is greyed out so we need to change the blend mode. We cannot hook the pin up to Opacity as the blend type is wrong.
- Change the Blend Mode in the Details panel to Tranlucent and hook the output of the texture to the Opacity pin in the shader.
- Now go into the game and test it out. Add another cube to the scene and bind the latest Material we just created. Lets add some color and make the inside of the cube visible:
- Play the game to look at it. Lets add a color to it and also fix the same two sided problem we had on the previous mask.
- Lets add some color and add Two Sided to the modes panel. Add a Constant Vector 3 node, select a nice color and hook it up to the Base Color node. Make sure Two Sided is checked under Material in the Details panel:
- Go back to the game and it looks better. But it doesn’t cast a shadow.
- There are two things we need to do to fix this. Go back to the Material and change the Lighting Mode to
Surface Translucency Volume.
- Then go into the game and select the cube you previously created. Go into the details panel. Go to the Lighting section and there is a downward arrow under Shadows. Click this to expand the selection.
- Look for the Radio Button that has Volumetric Translucent Shadow and make sure it is selected.
- Go into the game and play it and look at the cube. We have a nice soft shadow next to the hard ones!
- Lets Save All, Build the lighting and open GitHub Desktop. Commit the last set of changes and push them to the server. We are now done with room 3!
Now for some objects in the game, they will also be a light source. Think of the sun, a lamp, a TV set etc… So our materials can handle light blooms and glow to create the illusion that it is illumiating in game. To really sell this effect we also need to add a game light to actually light the scene. We will do this but we will work the entire pipeline from a final FBX to a model in the scene.
Importing a Model
- Look at your Files Needed for Walkthrough | SpotlightModel model folder. We have a .fbx file which is the 3-D model. Then we see the .png files which are all of our texture maps. The _D is diffuse, .N is normal, the .I is illumination (which we will be introducing here), _Rough is the roughness, and there is a new one _AO. This stands for ambient occlusion). This is a “technique used to calculate how exposed each point in a scene is to ambient lighting.” - Wikipedia
- Now go the Textures folder and press the Import Button. Import only the .png files for now:
- Your folder should now look like:
- Import the Import | SpotlightModel | Spolight.fbx into this folder.
- If it gives you a material you can delete it. You should end up with a bracket and lamp mesh. They are separate meshes so we can rotate the lamp at different angles:
- Now is a good time to hit the Save All button to lock in our work. Notice that the new assets all have an Asterix next to their icon. This means they are not saved. Once we press Save All these go away. The game does crash so it is important to save often so you don’t lose any work.
Rename the files to
- Lets go to the Materials folder and create a new Material called
- Open up M_BrushedSteel Add a Constant Vector 3 node with
.915as the RGB values:
- Add a Constant node with a setting of
1and plug it into the Metallic node:
- Repeat this for Roughness but make the roughness
.4and connecxt the node.
- Double click the Spotlight_bracket Static Mesh. Assign the material you just created:
- Go to Room 4 and drag both meshes (with both selected) into the game. You can press F for focus to get the camera close to where they go in the scene. Move them to be close to the wall. Rotate the lamp part to point at the wall so we can have a light shine on it.