Home Unity

Modular floor. Fewer meshes or fewer materials?

Offline / Send Message
rocketjump4d triangle
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?


  • rollin
    Offline / Send Message
    rollin interpolator
    I have to say I'm interested in this as well.

    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.

    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!
  • rocketjump4d
    Offline / Send Message
    rocketjump4d triangle
    Thanks for the reply, rollin!

    rollin said:
    until you combine all meshes to one big mesh (you could do so as a offline pre-processing step or during runtime)

    Did you speak something about this?

    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
    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.
  • rollin
    Offline / Send Message
    rollin interpolator
    No, padding will not improve blending. The filtering happens in the driver / hardware level of the gpu and it doesn't care about your uvs. It's simply not possible as far as I know. 

    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
  • rocketjump4d
    Offline / Send Message
    rocketjump4d triangle
    Got it, thanks
  • Polynaught
    Offline / Send Message
    Polynaught polycounter lvl 7
    Static batching should take care of your floor meshes with different uvs. At least that's what I used in the past - not sure what may have changed over the last 12 months.
    So make the floor tiles static, enable static batching in the player settings and enjoy reduced draw calls.
  • Shrike
    Offline / Send Message
    Shrike interpolator
    You will need to batch the meshes with an asset. It can work very well and all meshes which are batched are only one draw call if within the same material. So using more meshes is not an issue at all, unless your game somehow denies this, but it does even work with new spawned in objects. This batching however needs to be localized otherwise if you put your entire scene in one you can not occlusion cull if I understand it correctly. But you will 100% rely on such batching to get good performance within Unity, the automatic batching is by far not enough.

    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)
Sign In or Register to comment.