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?

Thanks!

Random_Monkeys.blend (930.2 KB)

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

Daz_Harris

12m

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.

1 Like

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!

:sleepy:

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.

1 Like

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.

1 Like

How can you set different materials for each instance as a whole without realizing instances? I couldn`t make it work, it will change material at the face level.

Hi there,

What is it exactly you would like to achieve?

If you have a bunch of objects e.g. rocks, then you add randomness as above, in the Material, and use the Geo node editor to change the physics e.g. object rotation.

If you have multiple materials, then you may want to create a collection e.g. of different stones (brown, gray, crunchy, shiny, etc…) and instance the collection, again Material controls texture randomness (also displacement if you want), while geo nodes control physical object attributes, e.g. rotation, size, etc…

I am not sure if you can randomize whole BSDF Shaders in one material (which to pick, e.g. set Randomness into Fac of a Mix Shader node maybe? :thinking:), but even if you could, you may be better off with a collection, some different Materials assigned.

If you tell us, what the exact aim is, I’m sure we can figure something out :blush:

Hello,
Thanks! Year you are right! At that moemnt i didnt know too much about Blender workflow and GN but now what you say it makes sense to have a collection with objects of different colors and then redistribute it using the nodes. Then having access to face level materials is important for non instance objects and other effects.
Another way is if you count the number of faces and use it in the random number generator to assign materials as series which fit and cover each object.

Kind of late to the topic lol but you can use the Mesh island node and use the island index attached to a wrap node with the min at 0 and the max at your max number of materials, you can then use compare nodes into the selection of various set materials like so:

3 Likes