Assign 2 different Materials on multiple Objects


I’m new in Blender.

I have tousands of LEDs and want show randomly the status ON (with emission) and OFF.
I dont wonna make it with the random thing on the Object info Node.
I wonna assign 2 different Material to the objects (Material for ON and OFF). How I do this ? Something with the Material Index ?


Do you need it just a static random, or animated random?

A static random, no animation needed.

Any reason why you don’t want to use Object:Random?

i have no reasons for that, if there is an other solution with nodes you can show me.

I dont kow what is all possible with nodes.

I thought that was the best solution.

Here’s what I’d do… there are other ways to get some randomness, but the principle would be the same.

1 Like

Cool I do a combination of Option 1 + 2 .
Exactly what I want.
btw is there a Node, where i can see the Output Value of a Node ?

The random Number for example from the Object Node.

No. The random value is generated at render time, so in the NodeEditor you cannot access it.
Basically, it’s a number between 0 and 1.
Plugging the ‘random’ output to the ‘Surface’ input of the ‘Material Output’, you can see in the viewport which value comes out.

you mean see in the way of grayscale not the number ?

If you render it, you can use the color picker to see what value is there…

Why do you want to see what value is it?

if i see the value of the output of a node i can better understand how it works

Both ‘options’ I posted above spit out some value between 0.0 and 1.0.
Each object will get randomly a number in this interval.

The problem of trying to ‘see’ what number comes out of some node is a logic problem!
Example: You have 1000 objects each with a random number… That means 1000 random numbers in a single instance. Which number do you want to see???

ok I understand.

thx a lot.

If you really, really want to see what number/value/color comes out from any node, then you need to use OSL, and printf the values into the console.
Note that this will flood your console with tons of numbers, as each sample will print something, and a simple render with 16px*16px at 32samples will output 8192 values…

shader peekf(float finput=0, output float foutput=0)
    printf("the float value for this sample is %f\n", finput);
    foutput = finput;   

Also note that you need to setup the environment OSL_OPTIONS="optimize=0", or osl will simply jump over any printf call.

1 Like