Generating mattes using the ID Mask node
There will be many instances during CG compositing where a few specific meshes in the image would require a mask pass. This provides control to modify specific pixels. To obtain these mattes, the ID Mask node can be used along with the information stored in Object Index or Material Index passes.
When given a value for the index, the ID Mask node creates a mask for the meshes that have the same value assigned as their Pass Index value, as shown in the following screenshot. All these Pass Index values of meshes can be obtained using the Object Index pass. The Object or Material Index pass has to be connected to the ID value socket of the ID Mask node, for the node to pick the Index values. The generated mask information can be used as an input for the Fac sockets available to many Blender nodes to affect only the required mesh.
In the following screenshot, assigning Pass Index to one of the three cubes and enabling the Object Index pass is explained....