(If somebody thinks I wrote something wrong just point it out, I wanna learn… This is my first post here. I searched for this answer before I posted this question here)
In Unity I’m working on making my own Voxel Engine for a game. I recently optimised it by implementing Greedy Meshing into it… but when it comes to the texture/UV part I just can’t wrap my head around it how can I do it efficiently. Right now each mesh gets assigned one Material, that contains all the blocks in the game. When I set the UVs I give a ID to it, and then divide it with the size of the grid.
Example with grid size 10:
Dirt Id:1, Uv:
0.1f,0.1f;
0.2f,0.1f;
0.1f,0.2f;
0.2f,0.2f;
My question is, how can I make the UV repeatable/tilable? I can set the Sprite of the Texture to repeat… but if I set the UV to any higher it will repeat every block instead of just the one I want. Can I do this with one Material assigned to the Mesh, or do I have to bite the bullet and make a separate Material to every single block? Or maybe can I do it somehow with one Material if I make the Sprite Mode into Multiple and slice it?
Thank you for your answers in advance.
void AddGreedyTexture(long textureID, int xTiling, int yTiling)
{
float y = textureID / VoxelData.TextureAtlasSizeInBlocks;
float x = textureID - (y * VoxelData.TextureAtlasSizeInBlocks);
x *= VoxelData.NormalizedBlockTextureSize;
y *= VoxelData.NormalizedBlockTextureSize;
y = 1f - y - VoxelData.NormalizedBlockTextureSize;
greedyuvs.Add(new Vector2(x, y));
greedyuvs.Add(new Vector2(x, y + yTiling + VoxelData.NormalizedBlockTextureSize));
greedyuvs.Add(new Vector2(x + xTiling + VoxelData.NormalizedBlockTextureSize, y));
greedyuvs.Add(new Vector2(x + xTiling + VoxelData.NormalizedBlockTextureSize, y + yTiling + VoxelData.NormalizedBlockTextureSize));
Debug.Log(x + " - " + y);
}