# Location for mapping node in percentage

friends.

Is there any way to change the location of a gradient texture with "mapping node" using distance in percentage instead of distance in meters? For example, I need the gradient texture to be always in the center of the object (x and y coordinates). Even when the array modifier is applied to the object. And this material is used by several objects of different sizes.

Something like on this picture:

NOW

MUST BE

• Eevee
• NOT as a postprocessing effect.
• Have you tried the Generated coordinates ? Jun 29, 2021 at 8:35
• yes :) I tried many other things Jun 29, 2021 at 8:38
• Maybe if you used geometry nodes instead of an array modifier, and then you could use a python driver to control the material… Jun 29, 2021 at 11:31
• There are flaws with my method, I'll try again. Jun 29, 2021 at 20:42

I find that this is possible given certain constraints.

If you are not using the Array Modifier to scale the object.

AND

If your object's coordinates do not intersect each other over the axis you're wanting to use.

For example, in my test scene I have an array of 5 cubes that do not share any space on any axis of the coordinate grid.

This way we can make it repeat without overwriting a portion of the previous object. You only need to clear the object on the axis you want to use for the shader.

I found a pretty robust way to do this is to use an Object Offset for the Array Modifier.

We can start with two Texture Coordinate nodes to reference both the Cube and the Empty, and Subtract their Object Coordinates. We then need to Vector Math -> Divide this result by 2 in theory, but in practice it's better to divide by some value slightly larger than 2. I used 2.0001 which is truncated to 2.000 in the UI, but it's important to know because it solves some floating point precision stuff that can pop up.

And it generates this intense white color, which is at first glance not very useful to us, but now we can use either the Vector Math -> Modulo OR Wrap node to make the Cube's Generated Coordinates repeat over the distance between the Cube and the Empty on each axis. Maybe someone with an advanced math degree can take this even further.

SO... to answer the actual question, finally, it's all of that, and then your subtract operation.

• Different sizes is a different beast. Jun 30, 2021 at 6:54