Author Topic: Alpha 8 UITextures to save space?  (Read 3254 times)

catlard

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 24
    • View Profile
Alpha 8 UITextures to save space?
« on: July 02, 2014, 12:53:23 AM »
Hi!

I'm working on an app for android and iOS. Memory and texture sizes are a problem -- whenever the app goes into the background, it has to restart, because Android kills the process (it takes up too much memory), so I'm looking at alternate ways of storing the textures in memory. I came upon an idea.

I'm working with an NGUI UITexture, for example, that is 1024 x 238. At RGB24, it's 1.7mb. If I switch the compression to Alpha 8, it shrinks down to 446kb. Huge drop! It's ok, too, because the texture is only white and alpha. So technically, no data has really been lost. However, The white that was in the image is now black -- and I can't seem to figure out a way to tint it (back to white), in NGUI. So, two questions:

1) How do you tint a UITexture that is in alpha 8 format? Is this possible?
2) Is this really going to save on the texture's size in memory, on a device? How would I check that? (Sorry, not NGUI question).

Cheers,

Simon
« Last Edit: July 02, 2014, 01:24:31 AM by catlard »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Alpha 8 UITextures to save space?
« Reply #1 on: July 02, 2014, 05:45:40 AM »
Alpha8 texture only has the alpha channel, and no RGB at all -- so what is returned from RGB channels is undefined. NGUI's shaders expect the color channel to be there, so if you're using alpha-only textures you will want to write a custom shader. Should be fairly simple -- just remove the part in the Unlit - Transparent Colored shader that uses the texture color:
  1.                         fixed4 frag (v2f IN) : COLOR
  2.                         {
  3.                                 fixed4 col = tex2D(_MainTex, IN.texcoord) * IN.color; // <-- this right here
  4.                                 return col;
  5.                         }
After:
  1.                         fixed4 frag (v2f IN) : COLOR
  2.                         {
  3.                                 fixed4 col = IN.color;
  4.                                 col.a *= tex2D(_MainTex, IN.texcoord).a;
  5.                                 return col;
  6.                         }

catlard

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 24
    • View Profile
Re: Alpha 8 UITextures to save space?
« Reply #2 on: July 11, 2014, 05:54:49 PM »
Thanks! That was exactly what I was looking for.

Cheers,

Simon