Hi guys,
I'm making a modular floor. There are 4 different floor types that should look like this (I use uniform colors for simplicity)
Also I've got a texture atlas like this
I see 2 ways to implement this, but I cannot understand, what is better
1. Create 4 meshes with different UV offset
2. Create 1 mesh and 4 materials with texture offset (e.g. X:-0.5, Y:0)
What is preferable? Are there other ways?
Replies
I can share some insight myself though.
4 Materials:
- each material is a new draw call and this means you gain very little from doing so
4 Meshes:
- each mesh is a new draw call and this means you gain very little from doing so - until you combine all meshes to one big mesh (you could do so as a offline pre-processing step or during runtime)
Whatever you do: With this texture layout you get a problem with color bleeding and pixel interpolation esp. when using mipmaps and when viewing the tiles from flat angles. I use a custom shader which does a bit of custom trixery to hide this as good as possible. Also in my case I "merge" all my tiles (as output from a marching cube algorithm) and use only one material which, in my case, uses world space triplanar projection instead of custom uvs but this doesn't make a big difference for this discussion.
Edit:
There is the option to used instanced objects / materials. In this case you might want to use one texture, one material, one mesh. But if someone has more insight in this topic I'm eager to hear!
https://docs.unity3d.com/ScriptReference/Mesh.CombineMeshes.html
That's a good idea to use instanced material. If I got it right, I need to create a new shader and declare "_TextureOffset" propery.
Like it was made here
https://docs.unity3d.com/Manual/GPUInstancing.html
in the "Adding per-instance data" section
About color bleeding. Will it be enough, if I just add padding between tiles in the texture atlas?
Could you tell more about instanced objects? I'm not sure if I undertand it correctly.
Instanced objects are just instanced prefabs and if they use a material capable of instancing they will be batched during rendering as good as possible
What I do not know so far if the batching can occur when the material properties are different within the same material, but it should be ok as they can be stored in an array (if different textures work then values should too), althought I cant confirm. (like a hitflash glow that goes down on hit objects per example, or damage slider)