# Keep texture centered while scaling

Ok. In Blender Cycles, I have an Image Texture node connected with a Mapping node and the scale and offset is set so that the image is centered to the object's face(s). However, when I change the scale later in an animation it scales the image from the corner, thus I have to change the offset with the scaling to keep it center on the face(s). Is there some way of scaling the image from the center, so that I don't have to change the offset as well?

The problem you're experiencing is that the Texture space coordinates are in the range 0 to 1 on the X and Y axes and the scaling takes place from the origin - ie, 0,0. To address this you need to shift the coordinates so that the origin is in the centre of the image (0.5,0.5) before scaling. You can achieve this by splitting the Vector into its separate elements using a Separate XYZ node, manipulating the coordinates using Math nodes and re-combining as shown :

The Subtract node re-maps the range from 0 to 1 into -0.5 to 0.5 so the origin (0) is in the centre of the image. The Multiply can be adjusted to get the desired scaling (highlighted in the image). The Add re-maps the range back to 0 to 1.

Setting the Multiply nodes to '2' will give you a half-sized image. Swapping the Multiply for a Divide or using '0.5' will give the opposite effect.

EDIT : My expectation was that the above method would be quite efficient - since the nodes are performing mathematically simple calculations. However, in my particular test case this was adding 10% onto render times.

There are other methods to create the same effect. The most efficient method I have found so far is to use Mapping nodes in place of the Subtract, Multiply and Add - this also removes the need for the Separate and Combine operations :

The Mapping nodes perform the same operations as before - offset by 0.5, scale, offset back by 0.5. This does improve efficiency.

Additionally, since the Mapping node performs the Offset, Rotation, Scale as separate operations in turn, the first two Mapping nodes can actually be combined into the following :

ie, Offset by 0.5 and Scale, offset back by 0.5.

In my test case this was only 2-3% less efficient than no scaling - a significant improvement over using separate Math nodes.

• That sure is quite the Stack. ;) Thanks, though a little slow, but works quite nicely. – Edward Jan 16 '17 at 12:39

You can use Vector Math node like this: