Materials: Select Texture by Color-Mask?

I want to dynamically fill areas of a material with a selection of textures based on the color of a grayscale map. I need some kind of “select” function that uses the pixel from the grayscale (0, 1, 2, 3 for example) and selects texture 1,2,3,4 accordingly as the “output-sampler”.

All I can think of is using 4 channels instead of a grayscale and use each channel as a multiplier for each of the 4 textures’ pixel color. But that would require more “mask-channels” and would result in lots of unnecessary blending, because I only ever need one of the textures at 100% for a specific point of the material.

Is that possible?

You should do 4 lerps using 4 channels of your color map. That would give you 4 masks. Making multiple greyscale masks out of one RGB texture would be possible using conditionals. At least that is the first that comes to mind, but the performance will suffer. Stick with 4 grayscale masks to be fair.