15

I want to create a chain that alternates between two colors every x chain link. This is what I want to model: Chain with alternating color chain links

The best I could do was use the wave texture node, but then I get chain links that are half orange half black: Using wave node to create alternating color

Of course, I could just apply the array modifier and change the texture of every x set of chain links, but I want to have the option of later varying the chain length.

Thanks!

Toni
  • 153
  • 1
  • 5

3 Answers3

20

Array modifier has a UV offset option. If you shift each instance by one in U in the modifier:

enter image description here

then, you can use this information in the shader:

enter image description here

In this example, the step value is 5.

We divide X from the UV by five, take the floor of the division then modulo it by two to alternate the colors.

So that:

enter image description here

lemon
  • 60,295
  • 3
  • 66
  • 136
  • Thanks to all who posted their solution. But now I am facing a new problem. I hadn't UV unwrapped my object before. Now after applying all modifiers and then UV unwrapping, the whole chain turns orange. Can someone explain what went wrong? I am using lemon's methond, btw. – Toni Oct 14 '20 at 12:31
  • Hi, all methods are nearly the same and all are based on the array modifier "Offset U" option. So, simply, none of them will work if you did not use this option before applying the modifier. – lemon Oct 14 '20 at 12:40
18

I like both of the above answers, but I think, (so long as you can trust the user to put integers into the input variables,) because UV's can exceed the 0-1 range, the tree can be simplified:

enter image description here

If you wanted it to be more goof-proof, you could Floor the inputs.

Robin Betts
  • 76,260
  • 8
  • 77
  • 190
8

I really liked Lemon's answer but I also like a little more control.

Nodes

This note network is more complicated but it also gives you more control. There are two value nodes you can change. You can change how often the color changes and if another color stays on for longer. Also remember to change the Array modifier UV Offset to 1 for U.

Change repetition speed

Change color length

Joonas
  • 2,301
  • 6
  • 19
  • +1 for the idea. But if I understand well, this is a way to have a distinct links amount per color? If yes, this can be much more simple node setting. – lemon Sep 27 '20 at 17:42
  • 3
    @lemon Yeah. My idea was to have chains output integer values and continue from there with a sine wave. That was quite unnecessary as mr. Betts demonstrated. – Joonas Sep 27 '20 at 18:22
  • 1
    We should definitely have animated chains out in the real world! – Thomas Weller Sep 29 '20 at 19:51
  • @Thomas Weller Definitely. That would be so cool. – Joonas Sep 29 '20 at 19:54