Cycles: Random color for "loose parts" of the mesh

The cycles object info node can output a random value for each object. I often use this for setting different colors to different objects automatically:

This works nicely if I have separate objects (second row).

If I duplicate a geometry by using an Array Modifier (first row), I’ll (of course) have the same random value everywhere. So I have to apply the modifier and split the geometry (by loose parts) into separate objects to make this work again.

Does anyone know of a way to have a random value (per loose part / array-element) without having to apply the modifier?

Thanks in advance for any ideas on this matter :slight_smile:

I don’t think we can. Although we don’t have ability to set Material Index in the case of the array modifier, we can use this for the solidify modifier. However, nobody seems to know how to use this write in conjunction with Object Info/Material Index read. Solidify seems locked to the slot used in the material, and when trying to read this doesn’t produce anything.

If we could have material index increase per instance and this would be reflected in Object Info/Material Index, then I would have been able to help you using randomized UV lookup which stores a random color. I have yet to see a use of Object Info/Material Index, how can this be set in a way that the material node can be used. Okay, so setting pass index for the material slot produces something, but I don’t see why this would be useful at the material stage. Someone mentioned maybe group instancing and some data block stuff, but that’s way over my head.

Thanks for thinking about this. Using the Material Index is a nice idea. To bad it seems to be inaccessible via the Object Info node - even for Solidify modifiers at the moment. Maybe it is something the Array Modifier could learn in the future. I’ve also been thinking about adding some additional information using Attributes, Vertex Colors, Vertex Groups, UV Maps, … But all this probably involves changing the Blender source code, as the modifier generated geometry seems to be inaccessible via Python. Maybe, I should give this a try - how hard can it be? :wink:

In the end, for the current project (BA Weekend Challenges #690) I applied the modifiers, but thinking about it now, I should probably have used a particle system for the bricks… since Object Info:Random works for particles.