I'd like to have random (different) color for each face of object. Objects has different shapes, but there are mostly flat so solution should be not based on normal direction. I tried various ways including vector transform without any luck. Is there any OSL solution for that?

edit: looking for node (material) solution for that.

  • 4
    $\begingroup$ Mark all edges as seams, unwrap object into UV space, scale faces to single points (using individual origins as scaling pivot), apply noise texture. $\endgroup$ Feb 6, 2019 at 22:49
  • 1
    $\begingroup$ So there is not node based solution for that? Your solution works fine but it's not suitable for my workflow (thousands of objects) $\endgroup$
    – Destrosvet
    Feb 7, 2019 at 10:12
  • $\begingroup$ A Python script could assign a random material from a pool to each face. $\endgroup$
    – rob
    Feb 7, 2019 at 11:41

1 Answer 1


Would a vertex color layer do?

If you select all the objects you want to treat this way, and run this script:

import bpy
import random

for obj in bpy.context.selected_objects:

    mesh = obj.data
    if not 'Rnd_face' in mesh.vertex_colors:

    color_layer = mesh.vertex_colors['Rnd_face']

    for poly in mesh.polygons:
        rgba = [random.random() for _ in range(3)] + [1.0]
        for idx in poly.loop_indices:
            color_layer.data[idx].color = rgba

..and assign a material which accesses the vertex color layer through an Attribute node..

enter image description here

here, on a bunch of subdivided planes ...

enter image description here

(you could use the per-face values in all sorts of other ways, in the node tree)

  • $\begingroup$ There is some changes in API (2.8X) so mesh.vertex_colors.new() require keyword argument - so fix for that line mesh.vertex_colors.new(name='Rnd_face') $\endgroup$
    – Destrosvet
    Mar 15, 2020 at 9:53
  • $\begingroup$ @Destrosvet Thank you very much! When / if you have sufficient rep. please feel free to edit answers where you see this kind of thing. $\endgroup$ Mar 15, 2020 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.