On Patreon, some of you guys messaged me asking if I could create a tutorial on the best method to implement a material system where we can mask specific color data (for example, red) and apply animated materials to certain vertex colors. A real-life usage scenario would be having a vegetation atlas where you don’t want trunks to move, want leaves to move heavily, and have the grass on the surface move lightly, all using the same material. So, I decided to write this tutorial for you. The logic discussed here can be applied to moving water, tents, or any other moving surface that can use a vertex painting mask input (e.g., Simple Layer Water Material, SimpleGrassWind, etc.).
Simpler doesn’t always mean more performant. In some of my older tutorials, I talked about texture atlases and trimsheets. The reason we rely on such methods is that we aim to create as few materials as possible when making our assets. Why? Because every material we create and assign comes with a draw call, which is one of the most important aspects of any video game when it comes to achieving great performance. If you’re interested in optimization methods in UE5, let me know on Patreon so I can create a dedicated tutorial for it. But in this tutorial, I’ll be discussing vertex masking methods in Unreal.
Before we begin:
I have a ‘space pool’ asset in this area, and I created some cubes where I’ll apply a water texture and use the ‘SimpleGrassWind’ node to animate the water. Later, I will configure Unreal to animate the green-marked areas while leaving the red-painted areas untouched.
I have isolated my cubes (the ones to which I applied my water texture) and painted them green in ‘Vertex Paint’ mode:
Then, I painted the parts that I don’t want to animate in red.
Here are the hex code references for pure red, green, and blue to paint your vertices with:
Important Node: In this case, if something is pure green, the animation will be fully applied to it. The shades of green will determine the intensity of the effect. For example, if you paint your mesh a color that falls between red and green, that vertex-painted area won’t be affected by the ‘SimpleGrassWind’ node as much as the vertex painted pure green.
Troubleshooting: If you can’t paint in the vertex paint node, make sure that your normals are facing the correct direction.
Your advertisement can be placed here for $200 permanently. Suggested resolutions: 1800x663 or 1400x1400. Contact us.
There isn’t an option called ‘Fill Color,’ but such functionality exists and is a bit hidden in Blender. For example, I want to paint some cubes pure green:
Switch to ‘Edit Mode’ and select the vertices you wish to fill with a color:
Then switch to ‘Vertex Painting’ mode and activate the ‘Vertex Selection’ tool:
Set the color you want to use for vertex painting, then select ‘Paint > Set Vertex Colors’:
Result:
Important note: When you select multiple unconnected meshes and try to implement this method, it works only for the first selected mesh. I thought this limitation was worth mentioning!
To ensure that the vertex color information of your mesh is imported correctly, you can double-click on your mesh inside Unreal’s Content Browser, then in the upcoming window, can click on ‘Show’ and then ‘Vert Colors’ option:
This is usually caused by one of the following things:
I’ll be using an example from one of my old projects to show you how the masking is implemented. To mask the color, you need to take the Vertex Color node (I want to animate the green parts), multiply it with the ‘SimpleGrassWind’ node (or a similar one), and connect it to the ‘World Position Offset’ pin of the master shader node.
I believe this tutorial should answer all of the questions you might have. However, if you encounter any problems, please feel free to contact me. If you have suggestions for more tutorials or would like to see more from me (I try to write as detailed tutorials as possible, and it takes quite a lot of time, so I’d appreciate your support), you can reach out to me on Patreon. Until then, happy game developing!