7
$\begingroup$

Is it possible to have a per object random value between 0-1 that can be used to mix two colors in Blender Internal?

I am used to using the Object Info node in Cycles to accomplish this effect, however I have been unable to find an equivalent in Blender Internal without using third party addons.

$\endgroup$
  • 1
    $\begingroup$ You could hijack the object color property; set each object's object color randomly with python, then get that into the node tree with a shadeless material that has object color enabled. $\endgroup$ – gandalf3 Apr 3 '17 at 20:41
  • $\begingroup$ hmm, not a bad idea $\endgroup$ – VRM Apr 3 '17 at 21:15
  • $\begingroup$ @gandalf3 I ended up using your suggestion, thanks $\endgroup$ – VRM Apr 4 '17 at 22:18
3
$\begingroup$

This is relatively simple to do, pick your add on: Animation Nodes or Sverchok, and per Object color is easily done via Color props of an Object. You can use AN Object Attribute Out or SV Object Set nodes to change Object Color.

enter image description here

Turn on Object Color in Material, and change give different color per Object, easily visualized and will render in BI.

$\endgroup$
  • 1
    $\begingroup$ My apologies, I did not specify this originally. I can't use add-ons not included in Blender. $\endgroup$ – VRM Apr 3 '17 at 22:22
  • $\begingroup$ Ah... that's pity. $\endgroup$ – Blender Sushi Guy Apr 4 '17 at 1:45
  • $\begingroup$ Python, drivers, or expression is the way to go then.... but why only Add-On inside Blender? Very limiting. $\endgroup$ – Blender Sushi Guy Apr 4 '17 at 1:52
  • $\begingroup$ I know it's limiting, but it is required for the context I am using this project in. $\endgroup$ – VRM Apr 4 '17 at 14:43
1
$\begingroup$

The solution I ended up using is to give each object a random black and white object color with a simple script, and then to render those colors out as a separate render-layer to be used as a mix factor.

The code:

import bpy
import random

#set sel to selected objects
sel = bpy.context.selected_objects

#for each object in the selected group, assign a random object color
for ob in sel:
   n = random.random()
   ob.color = (n, n, n, 1)    #this sets all color channels to "n" resulting in b/w color

This results in each object having a random (not necessarily unique) object color.


I then made a new shadeless material that derived the color from the object color:

And made a new render-layer with it as the override material:

This resulted in a perfect mask that I could use to mix elements and colors in the compositor with:

random color mask

$\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.