0
$\begingroup$

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.

$\endgroup$
  • 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$ – Jaroslav Jerryno Novotny Feb 6 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 at 10:12
  • $\begingroup$ A Python script could assign a random material from a pool to each face. $\endgroup$ – rob Feb 7 at 11:41
1
$\begingroup$

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:
        mesh.vertex_colors.new('Rnd_face')     

    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)

$\endgroup$

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.