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

Performance: Load and use JPG or PNG dynamically

Discussion in 'UGUI & TextMesh Pro' started by xenotime, Apr 9, 2015.

  1. xenotime

    xenotime

    Joined:
    Apr 27, 2010
    Posts:
    12
    Hi everybody !

    I am looking for the best way to load and display, from external files, a large number of individual images with variable aspect ratio.

    So I loaded each image in a Texture2D and I tested the following solutions:

    1) Use the textures directly with RawImage component
    2) Use Sprite (Sprite.Create) with Image component (same performance but better because it has the "Preserve Aspect Checkbox" which is very useful)
    3) Create an atlas (with PackTextures) and use the atlas and UVs with RawImage component (currently the best parformances)

    Is there a more efficient solution yet (the benefits of the "2" and "3")?
    Is it possible to dynamically generate an atlas for use with Sprites?

    Thank you in advance for your answers.
     
  2. Freezy

    Freezy

    Joined:
    Jul 15, 2012
    Posts:
    234
    If you can determine certain shared attributes you could batch similar textures together.
    Also you could sort the textures on the number of bytes they need (alpha, no alpha).

    Once you have a texture atlas, you are pretty much at maximum optimization (optionally you could create sprites from the atlas, simply pass a Rect of the area you wish to use).
    Depending on the target platform, you might be able to use mipmaps as well.

    You could lower the resolution of the textures (no use in loading 4k HD textures on a 640x480 screen, especially when it never fills the entire screen. You could always load from the source again to gain a higher res if/when needed).