Search Unity

Material optimization

Discussion in 'General Graphics' started by JakartaIlI, Apr 15, 2021.

  1. JakartaIlI

    JakartaIlI

    Joined:
    Feb 6, 2015
    Posts:
    30
    I have 4 materials on model,
    all 4 material have same shader,

    Is there a need to make a common atlas for materials in one or does unity do it automatically?
     

    Attached Files:

  2. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,631
    Unity does not atlas them automatically, as far as I know. There are lots of different products on the asset store that provide this feature (I think there may be some free ones too). There are also free scripts floating around if you google it.

    It's not too difficult to write a basic mesh combine/texture atlasing script using these two built-in functions:
    https://docs.unity3d.com/ScriptReference/Mesh.CombineMeshes.html
    https://docs.unity3d.com/ScriptReference/Texture2D.PackTextures.html
    The tricky part is that you need to calculate new uv coordinates for the meshes so that they use the part of the atlas that contains their original texture.

    Edit: two other things:
    1) I think the step of combining meshes in a script may be unnecessary for static meshes because of Unity's static batching. I think it should automatically combine any static meshes with the same material

    2)In addition to scripting, you could also use your 3D modeling software to atlas textures. 3D modelling software is generally better-suited for this type of thing anyway because it gives you an interface to control how the textures are packed.
     
    Last edited: Apr 16, 2021
    JakartaIlI likes this.
  3. JakartaIlI

    JakartaIlI

    Joined:
    Feb 6, 2015
    Posts:
    30
    Тhank you very much!