Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Texture size and performance

Discussion in 'Editor & General Support' started by antoine-agthe, Apr 5, 2013.

  1. antoine-agthe

    antoine-agthe

    Joined:
    Nov 1, 2012
    Posts:
    15
    I developed a useful texture packer for sprite-based 2D games, that makes it possible to pack in many textures without exceeding the maximum size of a single texture.
    That works perfectly, but now, I have a question about performance.

    Considering 2048x2048 as the maximum texture size for most Android devices, I can pack my sprites to create :
    • around 181 atlases with 512x512 size
    • around 45 atlases with 1024x1024 size
    • or around 12 atlases with 2048x2048 size

    In my case, I'm sure that Unity3D will internally bind a new texture each time it will draw a sprite.
    My sprites are frames of many animations, and all the frames of all the animations are mixed in all atlases.

    So my question is simple : Does the size of a texture have an impact on texture binding performance ?

    If it doesn't, I'll prefer big atlases to maintain a small amount of assets.

    Otherwise I'll certainly choose to generate 181 small atlases, but I'll have another question : is the performance proportional to the texture size ?
     
  2. WheresMommy

    WheresMommy

    Joined:
    Oct 4, 2012
    Posts:
    890
    The make it simple and in general. The bigger your texture sizes, the bigger the ram amount it has to use for it. The trick is always to use less texture size but doing a good photoshop job do get the most detail out of it you need to see. So try to optimize your textures so you wont get 12 x 2048px atlases, as there are not that much mobile devices out there which can handle that big size of texture with good performance. I dont know your game you use your packer on, but 181 x 512px atlases is a lot of atlases. But if you use e.g. one atlas per level and one for the ui, you should keep the size small. otherwise unity has to load all atlases in each level, even if it does not need every texture inside.
     
  3. antoine-agthe

    antoine-agthe

    Joined:
    Nov 1, 2012
    Posts:
    15
    My game consists one a single level in which animated objects can spawn quite randomly, so I need all the animations to be loaded on VRAM because the gameplay is nervous and I don't wanna have any lag due to texture loading when the game runs (especially on mobile, I think).

    The game already runs on targeted mobiles, with the same amount of VRAM used.
    I use ETC1 compressed format, so my atlases takes between 23 and 24 MB VRAM (12x2MB, or 45x512KB, or 180x128KB).
    My previous system is not that much optimized than my new one, and old textures are not so precise.
    So that seems to be OK for the VRAM,

    Considering that I cannot change the amount for VRAM used without making my game slowing down during texture loading/unloading, I just wanna know if it's better to use a small amount of big atlases, or a big amount of small atlases.

    That's why I think about Texture Binding in OpenGL. Is texture binding slower when binding a big texture ?
     
  4. WheresMommy

    WheresMommy

    Joined:
    Oct 4, 2012
    Posts:
    890
    Than I would go for big atlases, because each atlas returns a draw call, so you can optimize at least the draw calls which can be a performance issue on mobiles. I don't think its slower, because it is already loaded then.
     
  5. antoine-agthe

    antoine-agthe

    Joined:
    Nov 1, 2012
    Posts:
    15
    I need to give specific properties for each "keyframe", of each animation, of each animated sprite, for each rendered frame.
    Unity3D is not able to dynamically batch in that case.

    Try to change at runtime material properties of several instances of the same prefab, and you'll see automatically extra draw calls, even if materials use the same textures and shaders.

    I didn't try to change the UV-mapping of each sprite every frames but I'm sure it will be slower than setting up shader properties.

    My only doubt is about performance of texture binding regarding the texture size.