Search Unity

Multiple Meshes - One texture

Discussion in 'General Graphics' started by GRASBOCK, May 19, 2015.

  1. GRASBOCK

    GRASBOCK

    Joined:
    Feb 20, 2015
    Posts:
    5
    I'm curious,
    Does performance get affected if I use too many Materials or Textures in one Scene?
    My Point is that I wonder if i would get a better performance having multiple Meshes with one big Texture that holds all the UVs for each of them, even if a few parts on the UV are not used ...
    Or is it more efficient to create a texture for each single Mesh but therefore use a lot of different Materials with each one its own Texture.
    I once heard that too many materials would affect performance, so I want to know if thats true.
    Thanks in advance!
     
  2. phil_lira

    phil_lira

    Unity Technologies

    Joined:
    Dec 17, 2014
    Posts:
    428
    Hi,

    GPU can render more triangles if you send batched data to it. So, if your scene has 100.000 triangles for instance, issueing 10 drawcalls of 10.000 tris is faster than issueing 100 calls of 1.000 tris. In general the least number of drawcalls you have the better.

    Now how meshes get to map to drawcalls depends on a few things.

    1) A Material is a container for a shader and it's properties. Textures are shader properties and they do not affect drawcalls. The impact in performance of having more textures is that your shader will take more time to fetch and sample textures. So there's a performance impact, but not related to drawcalls.

    2) If you have a mesh with N materials that will be broken until N drawcalls, as there's no way to issue a drawcall with two different materials. (technically there is if the materials have the same shader but different properties, but for simplicity assume you can't)

    3) Unity tries to batch meshes together to reduce the number of drawcalls. If you mark a gameobject that contains a mesh renderer as static then unity will try to batch them together (static batching) as long as they have the same material. That's done in loading time, so no performance impact during gameplay. There's also dynamic batching. Unity will try to batch non static meshes at runtime for you. You can turn that on/off in player settings.

    4) If you have meshes with different materials because they have different texture properties you can create a texture atlas and use the same material to render both. Sprite manager can automate the process of creating texture atlases for you.

    I hope that helps. That's basically all you need to know about batching. :D
    Phil,
     
    hippocoder, GRASBOCK and hopeful like this.
  3. GRASBOCK

    GRASBOCK

    Joined:
    Feb 20, 2015
    Posts:
    5
    Thanks for your Reply!
    Thats Interesting, i have never heard of drawcalls before.
    So basically if I have less materials there would be less impact on realtime performance.

    And i have another Question, Does that fetching that you mentioned in (1.) only appear in loading time?
    or will it happen on runtime?
    Does a bigger Texture like lets say 10kx10k make a difference?
    I mean i could get all Texture data of lets say every Object that i need in the game put on one Texture to reduce the amount of fetching to do.

    I will have a look on atlases later (new to me too).
     
  4. phil_lira

    phil_lira

    Unity Technologies

    Joined:
    Dec 17, 2014
    Posts:
    428
    No, a fetch occurs each time you need to sample a texture in shader. If the required info is not on a texture cache it will be required to fetch from memory. The fetched memory location depends on the architecture, but the key point is that it will use more bandwidth if you have large uncompressed textures.

    To keep simple the advice on textures are to not use more texure size that you need. You should be targeting no more than 2048x2048 atlases on mobile.

    Use compression to reduce bandwidth and for non atlases use mipmaps to improve both quality and be more cache friendly.
     
    Last edited: May 21, 2015
  5. antislash

    antislash

    Joined:
    Apr 23, 2015
    Posts:
    646
    Hi, i also wanted to know precisely the difference, so, i made a test 1 year ago
    okay it was on cryengine but i guess unity could give the same difference
    spreadint 100 000 objects, ince woth 10 materials and 10 small textures, and the other with one material holding a big texture, the results are very clear.

    one material one big texture
    9688_BRUSHES_monomat.jpg
    10 materials, 10 small textures 9688_BRUSHES_multimat.jpg

    same test with 315 000 vegetation assets
    monomat.jpg
    multimat.jpg
     
  6. CodeMonke234

    CodeMonke234

    Joined:
    Oct 13, 2010
    Posts:
    181
    Regarding hardware texture usage - each gpu supports a certain number of texture units
    e.g ios A7 and A8 have 32
    see https://developer.apple.com/library...html#//apple_ref/doc/uid/TP40013599-CH106-SW1

    while the gtx 980 has 128!!!!
    see http://international.download.nvidi...nal/pdfs/GeForce_GTX_980_Whitepaper_FINAL.PDF

    You can bind and load up to that number of textures (also limited by gpu memory).
    Shaders share references to these bound textures.

    Theoretically, multiple meshes with one big texture would be better than a bunch of small textures....because you can avoid the texture bind.
     
  7. viktor_unity159

    viktor_unity159

    Joined:
    Jun 17, 2018
    Posts:
    3
    alright, and now the same test with instancing enabled, any difference?
     
unityunity