Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Multiple material instances impact on performance

Discussion in 'General Graphics' started by Chamfuru-sama, Jan 7, 2019.

  1. Chamfuru-sama

    Chamfuru-sama

    Joined:
    Nov 7, 2016
    Posts:
    4
    Hello!
    I'm working on a project where some assets reuse the same material, kinda normal. However, I was wondering, what (if any) would be the performance impact of having two materials that are the same, just named material one and material two? Would it double the impact, or does unity have some sort of built-in instancing since both materials would fetch the exact same texture file?

    Thanks for your time!
     
  2. joelv

    joelv

    Unity Technologies

    Joined:
    Mar 20, 2015
    Posts:
    203
    Yes both materials would reference the exact same texture so you won't pay any extra memory there.
    What you might pay is a slight cost of storing and building the properties for the new material (all depending on platform and project settings)
     
    Chamfuru-sama likes this.
  3. Chamfuru-sama

    Chamfuru-sama

    Joined:
    Nov 7, 2016
    Posts:
    4
    Thanks for the reply!
     
  4. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    97
    Be careful you also will get a small CPU slowdown because you break rendering batches more often ( you can check that in the frame debugger ). Because two different material instances break the internal rendering batch loop ( even if both materials have the exact same values)

    If you're using a new Scriptable Render Loop ( as Lightweight of HD pipeline ) then you don't have this limitation anymore. You can create tons of different material instances ( even with different values for each material ) and you still have maximum CPU performance. ( you just have to enable "SRP batcher" in this case )
     
    prattmyster, Stenjus2 and Peter_123 like this.
  5. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    507
    Hi, I have a question. For example let say I have 1000 models in my game and all of them use same material with different tilling/offset! (all names changes to instanced) Is this good for performance or bad? Will this use more GPU memory or less?

    Or it's better if I set 100 different materials with totally different textures? Instead of 1000 with same textures only different tilling and offset?
     
    Last edited: Jul 5, 2022
  6. matjumon

    matjumon

    Joined:
    Mar 20, 2019
    Posts:
    15
    The SRP Batcher helps minimize the cost of swapping materials as long as they all use the exact same shader, so using material instances vs completely separate materials really shouldn't change much. That said, using multiple different textures means you have to get more textures on to GPU memory, which will absolutely take up more memory than using a single texture, so you are better off with changing the tiling/offset rather than swapping so many textures.

    Ideally, however, if all your models are identical you might want to look into instancing if things prove too slow for you. :)