7
$\begingroup$

I wanted to assign the colours from my ColorRamp to my objects array. I tried to "apply" the Array Mod but it did not change. It appears my Object Index is just set to "1". Where can I get the index number of my Array? It will likely work if I "apply" and "break apart" my array but I have other objects on my scene it would likely affect my "Object Index". I prefer not to apply my array and especially not to break apart my object. Any idea on how I can get the Array Index instead?

Array Mod with Color Ramp

This is closest to how I wanted it to look. I used Texture Coordinate to achieve this but what I wanted is to map each Array element into my colorRamp. Anyone knows how to do that?

My temporary solution

$\endgroup$

5 Answers 5

7
$\begingroup$

you can try this node setup:

enter image description here

if you don't want that "split color" in one cube, just adjust the z-rotation value a bit like this:

enter image description here

$\endgroup$
5
  • $\begingroup$ Yeah, I was editing my post when you posted that. Thanks for the answer, but I was looking for something that I could assign per array element if that's even possible. $\endgroup$
    – Sophia
    Aug 7, 2021 at 7:31
  • 1
    $\begingroup$ Oh wow, gradient texture, why didn't I thought of that 🤣 been using the old arctan2 for most of my projects. $\endgroup$
    – Sophia
    Aug 7, 2021 at 7:32
  • $\begingroup$ AFAIK it is not possible. It is - but then you have to apply your array modifier and do a separation of the objects (which you didn't want). But you could also give GN a try....which can do a lot more... ;) $\endgroup$
    – Chris
    Aug 7, 2021 at 7:34
  • 1
    $\begingroup$ Ah well, thanks for assuring me that it isn't possible without the caveats. I'll have to take your answer. Thanks for that 😁👍 $\endgroup$
    – Sophia
    Aug 7, 2021 at 7:45
  • $\begingroup$ you are welcome $\endgroup$
    – Chris
    Aug 7, 2021 at 7:58
9
$\begingroup$

(The 'Object Index' output of the Object Info node does not mean the index of the object in an array. It refers to the 'Pass Index' number that can be found in the 'Object' tab > 'Relations' panel of the shaded object.)

If you want to get a number-per-element of an array into a shader tree, you can use the 'UV offset' field in the Array modifier:

enter image description here

Above, the UV's U is offset by 1 per element of the array. This means element 0's U goes from 0->1, element 1's U goes from 1->2, and so on.

We can take the Floor of that in a shader tree:

enter image description here

This means element 0 has the number 0, element 1 has the number 1, and so on, to use for whatever per-element property you like. Here, the number has been divided by the number of elements, to give a 0-1 range for a Color Ramp.

$\endgroup$
1
  • 3
    $\begingroup$ Well done!!!!!!!! $\endgroup$
    – Chris
    Aug 7, 2021 at 9:29
5
$\begingroup$

Worse than Chris'es and Robin's answers so I won't bother explaining and just post for completeness:

$\endgroup$
2
  • $\begingroup$ +1 for completeness🤗‼️ $\endgroup$
    – Chris
    Aug 7, 2021 at 9:36
  • 2
    $\begingroup$ +1 for the spectacular display of dashed arrows! $\endgroup$
    – Robin Betts
    Aug 7, 2021 at 9:44
3
$\begingroup$

and because you all forgot geometry nodes, which is a shame, here the geometry nodes solution:

enter image description here

$\endgroup$
2
$\begingroup$

As an alternate answer, this is what I end up using. Note that in my project, I'm facing the Y-axis. If you are doing it on the x-Axis, just swap separate XYZ to y, you will also need to play around with the parameters of the mapping part.

My temporary solution

On my project, the Y rotation adjustment is to make the colour start at the top instead of at the left.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .