Switch on int for materials (scalars/grayscale textures)

Hi,
I’d like to help anyone who needs a switch on int node but for materials.
The scenario is this - you have 1 or more textures that each channel is separate grayscale texture (for example you use the RGBA channels to store variations of a mask).

Here’s how to use it:

You need to create two material functions

  • MF_MultiSwitch: This is the function that should be called in the material.

  • MF_alphaBlend: This material function will be used in in the MF_multiSwitch to filter whether to allow the current scalar texture to pass through or not.

264698-mf-alphablend.jpg

Note: this can also be used with whole textures (RGBA), you just need to change the inputs for the material function to be vector3 or vector4 depending whether you like to use the alpha channel or not.

You can find the project zipped here

4 Likes

Thanks a lot for this! Dunno why there isn’t a switch node already, this is very useful. Is there any reason MF_MultiSwitch has the input nodes all out of order like that? Shouldn’t it be in increasing order to match the scalar hardCoded params?

1 Like

This is exactly what I need!!! THANK YOU SO SO MUCH!
At first I got it wrong because I didn’t change the inputs to be vector3…
I am very grateful you are golden!!!

Thank you!!!

Thanks!
Just a note, this is not the most performent way to do it from my knowledge, you use LERP, but optimally IF would be used.

Hello, I can’t find the attached project zipped file?