Author Topic: NGUI for iOS, Texture Atlas compression  (Read 23596 times)

Raimis

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 5
    • View Profile
Re: NGUI for iOS, Texture Atlas compression
« Reply #15 on: August 20, 2015, 11:57:57 AM »
Actually there's one option that's quite popular among ios unity devs. The problem is that unity doesnt support png as native texture format on ios. It has performance penalty because decding is required, but sometimes it's the best way to go. Basically you put your texture as .bytes in your resources folder, load it on runtime as textasset and decode it into the texture.

In our case we have 90 character cards @1024x1024, 30 levels @2048x2048 (hand drawn, nothing much we can do about making them smaller)... the game was 900mb installed with all these things as truecolor textures. Changing characters to bytes saved us 300mb, altering levels will save us another 300 (did that, but haven't checked yet the gains). Last part is that we still have ~10 atlases related to game levels that have other content other than background. I guess it's another 100mb or so. What I am trying to solve now is how to make NGUI reference bytes files rather than image and load image during runtime only. We are ok with the decompression penalty, cause it's easier to show "loading" for part of the second rather than explain to user why his 16gb iphone shows out of memory warning after installing what appears to be casual timewaster.

Would be nice to have this out of the box in NGUI.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI for iOS, Texture Atlas compression
« Reply #16 on: August 22, 2015, 02:26:59 AM »
Fairly simple actually. Use reference atlases, or just remove/replace the texture referenced by the atlas material before doing a build. In the Awake() function in your very first scene, Resources.Load the desired .bytes data, create the texture and update the material's reference.

Raimis

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 5
    • View Profile
Re: NGUI for iOS, Texture Atlas compression
« Reply #17 on: August 24, 2015, 07:50:17 AM »
That's what I did. I have references to atlases and materials and assign material and texture at runtime. Fairly simple indeed. Though this is something that not so many devs know about and this might be a game changer for graphic-heavy games.

dadrester

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: NGUI for iOS, Texture Atlas compression
« Reply #18 on: January 11, 2016, 12:30:30 PM »
"You'd have to resize the textures manually before adding them to an atlas. Atlas accepts final textures in the size that they're meant to be in."

Just wondering if there's a Q&D workaround for this at all?

We have a large atlas for one particularly art heavy menu. The game is being developed for console and handheld and at full rez the handheld has a tendency to run out of VRAM on this particular menu (the main UI atlas is in memory permanently, but this one is loaded and binned as needed).

Because we're work in progress I'm loathed to keep 2 completely separate sets of textures and atlases in the project (given they are likely to get tweaks). I assume the reason scaling the atlas in unity breaks the UI is because coordinates are set by pixel. Just wondering what the implications would be of offering an option to convert the coords to a UV scale 0 to 1? If you know what I mean

Bump :)
« Last Edit: January 11, 2016, 12:56:09 PM by dadrester »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI for iOS, Texture Atlas compression
« Reply #19 on: January 11, 2016, 05:35:15 PM »
Bump what?

pretender

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 155
    • View Profile
Re: NGUI for iOS, Texture Atlas compression
« Reply #20 on: January 12, 2016, 11:39:06 AM »
what is actual workflow in converting textures to bytes and converting back to textures...i am getting the same size but probably doing something wrong!

this could save me some space since there are a lot of textures in the game i am working on! thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI for iOS, Texture Atlas compression
« Reply #21 on: January 13, 2016, 07:16:17 PM »
This is outside NGUI's scope as you are asking about Unity functionality here. Consult Unity's documentation regarding how to create a texture from bytes.

http://docs.unity3d.com/ScriptReference/Texture2D.GetPixels32.html
http://docs.unity3d.com/ScriptReference/Texture2D.SetPixels32.html
http://docs.unity3d.com/ScriptReference/Texture2D.LoadImage.html

dadrester

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: NGUI for iOS, Texture Atlas compression
« Reply #22 on: March 20, 2017, 12:47:37 PM »
Hi,

We're struggling to keep the Vita version of the game in memory so we need to downrez quite a few NGUI atlases. We can't rebuild the atlases as we're multi-platform and we can't use lookup atlases as it would break way too much in the game. Wondering if there's a way to use unity's texture size overrides so that NGUI doesn't break?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI for iOS, Texture Atlas compression
« Reply #23 on: March 21, 2017, 04:40:44 PM »
What's a lookup atlas? Assuming you mean a reference atlas, that won't break anything. You can dupliate your current atlas, make the original a reference and have it point to the duplicate. Everything will work as it did before. You can swap the reference at run time when you first load up the scene in Awake().

You can't change the size of the texture, but you can change its compression to reduce its size as needed.