How to create a CLOWN PASS for material selection in photoshop?
Dedicate render layer with material override

For this task I usually set up a dedicated render layer.

I render only the emission pass of the surfaces using a material that transform a given random number, one for each object, into a color of the color ramp.

To render all the objects with the same material without touching your original scene, you can use the Material box in the Layer panel of the Render Layers tab.

Here's a possible setup:



Note (1): you need just 1 sample to achieve the final look, so it should not affect much your rendering time.

Note (2): this works "per object", not "per materials". For materials, I would use the Material ID pass, but that's not automated.