UE4 Intro To Materials - Page 12
- 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
- Lets save the current level and double click to load Maps | BasicMaterials2.
World Aligned Materials
What happens if I want a long stretch of brick wall that follows different shaped and placed geometries. It would take a lot of painstaking tweaking to align all the UV’s. There is a better way in unreal to use world coordinates to place the UVs.
- Now move the camera to Room 7 and press Build to set the lighting in the room.
- Now add StaticMeshes | Supplied | Wall 400x400 and place them next to each other but offset. We want to have the bricks line up properly.
- Assign M_Brick_Clay_Beveled to the new wall pieces. Move them and notice that we would have to zoom in to line up the bricks so the rows spread from one wall piece to another. We can solve this by using World Space then all the objects will align with the texuture automatically. Lets take a look.
- Add a new Material called
- Open the material and add a Texture Sample node adding the T_Brick_Hewn_Stone_D texture:
- Add a World Aligned Texture node to the graph:
- Try to connect the two nodes. Woops we get an error:
- Highlight over the input of the World Aligned Textured node and see that it wants a Texture Object. Add a Texture Object Parameter node and delete the Texture Sample node and call it
WSRockDiffuse. Assign the T_Brick_Hewn_Stone_D texture
- Now connect the output of the Texture Object and plug it into the input of the World Aligned Texture node:
- Connect the XYZ Texture output of the World Aligned Texture node to Base Color in the main material node. Press the Apply button.
- Select all the cube walls in Room 13. Assign M_RockWS to them. You should see that even though the rock textures are very small that they align based on world position.
- Move a wall around and see the UVs adjust. Notice that it is using World Space to map the UV’s so they all line up based on where the material is located. So for something like a brick wall, the bricks will always align.
- If we go back to the material and hover over the Texture Size node it states that it defaults it to world size of
64, 64, 64. UE4’s size is 1 unit per milimeter so 6.4 cm or 2.5 inches is not large enough.
- Add a Constant Vector 3 node set to
128, 128, 128. This will effectively double the size. Connect the output to Texture Size on World Aligned Texture node. Press the Apply button.
- Apply the change and look at it in game:
- Add another Texture Object Parameter, name it
WSRockNormaland assign the normal texture that goes with this diffuse:
- Add a World Aligned Normal node. Connect the Vector 3 to the size to make the normal the same size as the diffuse. Connect the output of the Texture Object Normal to the input. Send the XYZ Texture output to the Normal input on the main material node.
- Multiply a color you want to tint the texture in the diffuse:
- Add a Scalar and set it to
1. Attach it to the Roughness node and press the Apply button.
- Go into the game and move things around and enjoy your seemless textures:
- That’s it for Room 7. Press Save All and update Github by committing and pushing all the changes made. Next up we will be animating the UV’s of a texture.