Create multiple material render on a mesh with an array to define them (like a material id texture)

Hello to all,

I have a need but I am not sure of the method to achieve it.
I would like to be able to render a simple mesh with several materials by giving a texture or an array that would define for each pixel, the material it should use depending on its position. I understand that this can be done with groups but that it increases the number of polygons. The idea would be to be able to pass a map which contains for each point of the uv a value (for example 1, 2, 3, 4, or 5) and that at the time of the rendering, the shader uses the material 1, 2, 3, 4 or 5.

This could allow the use of a “material ID” texture that could define the material to use due to the UV position for a simple mesh like a multiple layering alpha blend…

Do you think it’s possible with the actual three JS or do i have to develop a specific ?

Thanks a lot !