I recently wanted to create a floor that consisted of multiple concrete blocks. To breakup the look, I wanted each concrete block to be a slightly different color. Instead of creating and assigning separate materials to each block, I added a brightness multiplier attribute to each mesh, and used a shading network to read that value.



I started by selecting one concrete square and opening up the Attributes tab.



Then click the Focus button to set the Attribute Editor focus to this shape.



From the Attributes Menu, select Add Attributes...

Add Attribute


In the long name, type mtoa_constant_color, and set the type to Float.

New Attribute


Then I duplicated the meshes and arranged them to make a floor.

Duplicate Meshes


I selected all the meshes and used this MEL script to randomly assign a value between 0.75 and 1.5 to each mesh.

string $selection[] = `ls -sl`;

for ($member in $selection) {
	float $randomValue = rand(0.75,1.5);
	setAttr ($member + ".mtoa_constant_color") ($randomValue);


Then in the shading network, I used an aiUserData node to read in this attribute. I connected the Out Value of the aiUserData node and the Out Color of the diffuse texture into a ColorMath node set to Multiply. If the custom attribute is greater than 1, then the diffuse texture will be slightly brighter, if it's less than one, then it will be slightly darker. When applied to all of the concrete floor meshes, it provides some nice random breakup between each floor tile. After using the MEL script to assign the random colors to each mesh, I can then go in and manually adjust those values if I find I want a different distribution of light and dark.



Note - the Name parameter on the aiUserData node should be set to color even though the attribute name we added to the mesh was mtoa_constant_color


Arnold 5 Documentation on AiUserData