I'm new to shader programming, so I decided to use Unity's shader graph for that.

I have 256x256 texture atlas(like minecraft) with 4 16x16 block textures aligned on X axis

I can successfully assign texture depending on material ID (which is stored in UV.z) to the first block, but I've big issues with trying to make this work correctly for other blocks in the row(or in the 3 rows, cause 3 dimensions).

First block gets textured correctly, but other blocks(even if they are same material) get textures from other part of the atlas. For some reason texture won't repeat itself. (I assume reason is I need to do it myself somehow)

By current optimization, Vertices and UVs are shared between blocks only if they are of the same direction and same material ID.

My shader graph:

enter image description here


enter image description here

As seen in the result, even though all blocks are same material_ID, only the first one gets atlas aligned properly. Others don't.

How would I make this work with other blocks too using shader graph?

PS: How UVs are assigned:

  public static Vector2 ProjectPositionToUV(Vector3 position, Direction normal)
        switch (normal)
            case Direction.Up:
            case Direction.Down:
                return new Vector2(position.x, position.z);
            case Direction.East:
            case Direction.West:
                return new Vector2(position.z, position.y);
            case Direction.North:
            case Direction.South:
                return new Vector2(position.x, position.y);

        // Fallback for an invalid input direction.
        return Vector2.zero;


 uv.z = data.cubeType;
  • \$\begingroup\$ Looks like you forgot to wrap your UVs in your shader so they cross and re-cross the same small square within your atlas. \$\endgroup\$
    – DMGregory
    Commented Mar 8, 2020 at 16:00
  • \$\begingroup\$ @DMGregory Thanks for reply. Does script need to pass any additional data to shader or this can be done from shader with already available vertex data? \$\endgroup\$
    – Nick
    Commented Mar 8, 2020 at 16:47
  • \$\begingroup\$ That's up to your implementation. \$\endgroup\$
    – DMGregory
    Commented Mar 8, 2020 at 17:49

1 Answer 1


Eventually, I've resolved my problem using Texture Arrays(using UV.z coordinate as material_ID).

My shader:

enter image description here


You must log in to answer this question.

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