# How to use random value and vector?

I have a geometry node to edit UV
And I want to add a random number for the X coordinate
But when I add it, UV breaks down
But when I enter the number manually everything works fine.

Full node

I don't understand what am I doing wrong?

I need this to create different leaves in a mesh from Planes

• Why wouldn't the UV break down if you're randomly moving coordinates? Perhaps you don't know that $1$ is a lot in UV space, because the $0$ is supposed to mark the beginning of the texture, and $1$ its end (so you're moving from the beginning to the end of the texture). Commented Jun 28 at 8:45
• I might agree with @MarkusvonBroady that 0 to 1 is probably a much too wide range... but to judge on that I would have to understand (or you should explain in your question) what your actual goal is. Because how you have set up the nodetree it looks as if you wanted to distort the UV map (but this fails because you probably have just a default plane there with only four corner vertices, but Geometry Nodes need geometry to store values, i.e. more subdivisions). Or, and this is what the screenshots suggest, you actually want to show random parts of the color grid (undistorted). Commented Jun 28 at 9:13

The Random Value node generates a value for each vertex in the mesh. If you want to have the same value for each point, you should plug a singular value into the ID socket, which by default gets the ID of the element.

If you want to get a value for each face, you can evaluate ID on face domain (in this case you should store UV on Face Corner):

• For "each face" implies that there are more faces... but the first screenshot in the question looks clearly like there is only one face. That's why I asked in the comments for clarification what exactly is the goal and mentioned that depending on the desired outcome more resolution might be needed. Commented Jun 28 at 10:57

You already accepted the other answer, but just to show how I understood the question: I thought you had a bunch of instanced planes, all using the same material with an image texture of a 3 × 3 grid of leaves.

Then I thought you want each instance to show a different part of the image texture, i.e. one of the 9 leaves variations. Since the planes are instances, you have to realize them to get the index of each face.

Important: In the following setups, each Random Value node gets the index value of the faces plugged into the ID input which comes from a Evaluate on Domain node set to Face. This is not only necessary for getting random values per index, but without the face index each vertex would get a different random value, which will distort the UVs.

Now this index is used to create a random integer between 0 and 2. I choose those values because the image has three rows and three columns of leaves, think of them as indexed with 0, 1, 2.

I use two Random Value nodes with different seeds to create integers, because I want to get random values for rows and columns (i.e. X and Y values in a Combine XYZ node). If I use only one value for X, I could only get leaves from a single row (or column if I only used them for Y values). Using the same random value for X and Y would result in getting only the three diagonal leaves (0, 0), (1, 1) or (2, 2).

After adding them to the original UVMap vector I scale them by 1/3 to get the correct offsets since each column and row has 1/3 of the full UVMap's width and height.

Here is the result, I did not create a bunch of leaves like your example but instanced them on a grid so that you can see the variations better:

If you now also want to rotate those images randomly, you can take another Random Value node set to Float with a Min value of 0 and a Max value of 2*pi for example and plug it into the Angle input of a Vector Rotate node set to Z Axis. The original UVMap data from the Named Attribute goes into the Vector input of the Vector Rotate node. The result goes into the Vector Math > Add node. The order is important, the rotation has to be first on the original map, then comes the addition and then the scaling. A different order will mess up the UVs.