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:
Atlas:
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;
}
And
uv.z = data.cubeType;