I've been looking around a little but could not find a definitive answer for this: Can I setup my nodes in a way that allows for randomly selecting one out of multiple image textures using an array?

I am modeling a race track and would like to randomly choose different ads for the hoardings.

  • $\begingroup$ You can set the Pass Index in Object Properties -> Relations to a different number for each Mesh and then use the Object Info -> Object Index node and then use a collection Mix Shaders using the that as the Factor. This will end up a big mess the more Image Textures you want to include. The Object Index can be Math->Multiplied with Object Info -> Random to get more randomness. Python for setting the Pass Index blenderartists.org/t/object-index-not-working/637448/4 $\endgroup$ – rob Mar 20 '19 at 14:17
  • $\begingroup$ Even better example using random Pass Index blog.gregzaal.com/2013/07/28/cif-3-object-index $\endgroup$ – rob Mar 20 '19 at 14:19
  • $\begingroup$ Thanks! Have to look into this, looks very interesting.. $\endgroup$ – oeri Mar 20 '19 at 15:43
  • $\begingroup$ You can use an array as a particle emitter, as shown here, which lets you treat a particle system as if it was an array (of the emitting objects) The your 'array' could all be different shapes and sizes, if you wanted. $\endgroup$ – Robin Betts Mar 22 '19 at 21:59
  • $\begingroup$ Thank you, great idea! $\endgroup$ – oeri Mar 24 '19 at 14:48

You cant set a different texture for array's duplicates.

However, you can shift their UVs:

demo pic

As you can see here, I have a texture of 1/3 ratio. Each third has a different pattern.
My array is set to make three different duplicates, and to shift their UVs of a third (1/3= 0,333...) on the V axis.

The result is quite usable.
All you have to do is a texture file containing your different textures aligned on one axis, adapt your UV to one area of the picture, and set your array's number of duplicates and U/V offset accordingly.

| improve this answer | |

I thought about what others had done with the Pass Index and then threw it all out the window and tried with plain Random.

Cleaner version of Nodes further down.

I created it as Node Group so I could experiment. Here there are 5 different Image Texture nodes connected to Diffuse BSDF Shaders and each Shader is attached to a Mix Shader. Random image Node group

The Random value coming in has a value between 0.0 - 1.0. The framed logic picks out five ranges and uses them to determine the Image Texture shown (0.0 - 0.2 is explicit).

The Mix Shaders are controlled by Boolean logic. The Greater Than and Less Than Math Nodes output 1 for True and 0 for False. The Minimum Math Nodes act as And gate and only let 1 through when both inputs are 1.

Outside the Node Group I am simply pumping in the Object -> Random Material using Random image Node group And the Result. result of 5 random images

It is a bit over the top and to extend it will require tweaking the values to match the number of images required.

Cleaner version of Nodes.

And an even cleaner way or structuring those Nodes, reducing unnecessary Nodes. Uses Colours, but an Shader can be used. Node structure

Truth table Truth table

Small blog post I did on it. random blender textures through the magic of logic gates

| improve this answer | |
  • $\begingroup$ Awesome, thank you! $\endgroup$ – oeri Mar 24 '19 at 14:50

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.