Geometry nodes: randomize material on each instance?

Hi folks,

Please take a look at the image below (blend file also attached).

I’m trying to randomize the material that each instance receives in geometry nodes.

Anyone have any idea on the best way to do this?


Random_Monkeys.blend (930.2 KB)

Hi, use set material index and plug a random integer in it



Thanks man, i tried that but it does nothing, i’m probably doing it wrong.

Do i swap the “set material” for “set material index”? … or…?

And for setting each material’s index, i do that in: material properties > pass index, right?

Sorry, i’m a noob!

Make sure to limit the random value to the max number of materials you’re using (otherwise there would be too many occurrences of the last material). The problem I have is that each face gets a separate material and not the whole instance. I’d like to know if there’s a solution for this.
As a workaround you can duplicate the instances you want to use and each would use a different material. Then instead of using object instances, you would use collection instances with random object from it.

Thanks cdog but i really don’t understand that node tree!.. but anyway, i tried to implement it in my scene but it just doesn’t work!


If anyone could modify my blend file (attached to the first post) to get it working, i’d be eternally grateful!

Problem solved, i now realize you can also set the random color in the shader nodes!

Although i’m still curious why the “set material index” node doesn’t seem to do anything (see pic below and attached blend file).

I’m probably doing something wrong. I’m in Eevee and i gave each material it’s own ID in: material properties > settings > pass index.

Rand_COL.blend (833.3 KB)

I don’t know how to do it with the setup you have there but if you use an object info node and get an object from the scene… The material index in this case appears to reference the position (slot) in which the material resides. So you are referencing the material index of an object (the instance) with two materials, the second is 1. Check out this blend, for 3.1

3_1_material-index.blend (916.2 KB)

Many thanks, that works, and i found a workaround to use your method to bring in the material but still actually create the instance mesh in the nodes (see pic and blend file).

But i still can’t apply a random color to each instance in the geometry nodes.

Any ideas?

3_1_material-index_EDIT.blend (938.5 KB)

Yeah, sorry, other than changing it in the shader nodes as you mentioned above I can’t seem to figure it out.

Right, that works, but only for solid colors, there’s got to be a way to apply random materials to objects in geo nodes!

Try realizing instances right before the material assignment

Sorry, i was being an idiot, you can apply any material you want, not just solid colors, via the material index, no need to realize the instances.

You can use the same principle on whole node tree sections with greater than math nodes. Just check if the random number is greater than a certain value, and if it is send it down a different node tree section.