I’m working on a voxel-based project and wanted to optimize generated chunks. I have already taken a look in the thread and learned a lot from people’s experiences whom are trying to do the same.
There is one thing that people talked about and implemented which I don’t know how they did in Unity.
Suppose we have 2x2 quads laying together like this:
(Black lines are not part of the texture. They are to indicate boundries of quads)
They are using same material with same texture. Now that I want to merge this 2x2 quads togather and want to generate a single quad like this:
How is it possible that I can define these newly obtained 4 vertices to repeat the same material’s texture 4 times without changing material tilling/offset. If I map the newly 4 vertices as I have mapped the smaller ones I would end up with a single streched texture like this:
People in the thread were mentioning about usage of sub-meshes but I can’t see how it would help in this situation since it is only a different set of triangles to apply with a different material as far as I know.
Welcome to this awesome world of vertex splitting and UV math.
You need to represent one tiling as separate quad with its own vertices as part of one mesh. This is common technique used when normals are not continuous across surface in the obj import, for example.
Turns out it is possible to do by mapping UVs of vertices between 0-X (X means how many times you want that tile to repeat it self in that coordinate).
With an example:
Suppose we have a material with texture: (tilling x,y: 1 / Offset x,y: 0)
If we want this texture to repeat it self as many times as we want in either axis by only using 4 vertices, we map UVs as:
(2 times in X and 2 times in Y axis for this example)
The main idea is we don’t use UV’s between 0.0 and 1.0. That being said, this method enforces you to use 1 texture per material. Which prevents you from using Texture Atlas.
I don’t know if there is a way to use both a TextureAtlas and make this kind of tilling with 4 vertices. Although the method I mentioned above will help you decrease your vertices count if a lot of faces are using same textures but it comes with a side effect of enforcing you to use 1 material per texture (ends up increasing your draw calls).