# Get world position of tile in shader graph

Hello,
I’m trying to make a shader that offsets the texture of every tile in a tilemap by a random amount (it would be great if it would be deterministic so that tiles at the same position always have the same offset, but okay if not). For that I wanted to use the position of the tile to sample a noise texture. The position in the Object node is unfortunately that of the tilemap and if I use the Position node, every vertex of my sprite is offset by a different amount. I considered zooming the noise texture so far in, that the vertices all sample roughly the same value, but then neighboring tiles would also have a very similar offset. Is there a way to solve this?

Kubali

Well, maybe someone else will come with something smarter (I am not experienced with 2D), but if your tilemap is not isometric, then I guess you can just round position values to grid, because you know how big your tile is and tiles are aligned to axis.
For simplicity I will assume one tile is 1x1 unit, you can get position of pixel in fragment shader (can be world, but object space might be better) and round down to size of your grid. So if position of pixel is (2.32, 3.87), it will be rounded down to (2, 3) and this is constant value for all pixels on this tile, so it can be used as hash to generate random offset you need.

If you’re only shifting the position a small amount per tile grid cell, you could simply use

``````var matrix = Matrix4x4.TRS(new Vector3(x, y, z),  Quaternion.identity, Vector3.one);
tilemap.SetTransformMatrix(cell, matrix);
``````

When you set your tiles once, you pay the cost 1x instead of in the shader. Clearing the tile will clear the offset.

The Vector3 offset could be whatever, deterministically derived from the Vector3Int cell position via Mathf.PerlinNoise or Xorshift for example.