That’s an image from UDK documents.
Typically the masks are the outputs from Erosion node. You put each one of them in a separate channel (RGBA). And then using each channel you tell what texture to be painted where. That’s exactly what is happening above.
This link is for UDK not UE4 but almost all of it is the same and works for UE4 too. So many good information.
https://udn.epicgames.com/Three/TerrainAdvancedTextures.html