Best way to paint same Material with different mask? My question is to have an alternative way if it exists.
So my problem is the following:
As you can see from this image, I have 2 materials, the first in the top row, uses vertex paint, so white and black decide how to mix green and red, so everything is ok here.
In the row below, there is a material practically the same, but which uses a mask (Always black and white) for vertex paint which is absolutely more detailed, as it does not need to have a high subdivision of polygons (As in vertex paint) .
But there is a problem in Texture paint, unlike vertex paint, that is, the possibility of painting the same material on many objects, without these being modified all together, let me explain better,
The vertex paint refers to the colors of the vertices of the object, but is very limited on the final results, due to the triangulation that is very visible, but remains independent (If the object is not an instance)
The texture paint is very nice, but it does not remain independent, so if I paint an object, the other object with the same material will suffer the same fate, therefore I will have 2 objects with the same mask.
I'm trying to approach this to understand which way to go, without having to create a new material, but probably my knowledge stops here.
Basically, I would like to have only one material, with the possibility that it can be masked independently on objects.
I would also like a vertex paint solution, if this were not so &quot;Squared&quot;. I have a lot of confusion right now and I would like to know an answer on this, which will guide me to a &quot;Logical&quot; but intelligent choice, always keeping the single material

Post Bounty Note:
Based on Splize's answer , however, I thought that this method could contrast with the real use of Index pass? but actually it seems a very useful answer, and it works very well. At this point I would like to understand if there are further way that can be taken. Taking into account also a hypothetical more detailed vertex paint, because the vertex paint is much more &quot;comfortable&quot; as it does not require an additional Mask and &quot;Smart Projection&quot; to make the correct mask mapping
You will have to specify some kind of &quot;mask&quot; at some point of process for any object. So I'm not sure if the shared material is key for you.
If you want just be able to change node-tree shared by multiple objects from one place you can use Node Groups. Place all material node-tree into a group (Ctrl+G) only &quot;mask&quot; node and Material Output place out of this group.

Once created, the node group can be placed (Shift+A &gt; Group) everywhere and managed from any of its copies. This way you can completely change node tree into totally different look without touching material with mask specific to object.