Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Options for ETC1 with Transparency

Discussion in 'Android' started by PixelSquad, Nov 17, 2015.

  1. PixelSquad

    PixelSquad

    Joined:
    Sep 4, 2014
    Posts:
    114
    Hi guys,

    Sprite based game. I'm considering using the following options for texture compression with alpha on Android.

    Option 1. Use an Alpha 8 texture. Adds about 1MB per texture. I wrote the following shader:

    Code (csharp):
    1. half4frag (v2fIN) : COLOR
    2. {
    3.   float4ret = tex2D(_MainTex, IN.texcoord) * IN.color;
    4.   ret.a *= tex2D(_AlphaTex, IN.texcoord).a;
    5.   return ret;
    6. }
    Option 2. Use another ETC1 texture for the alpha. This adds about 0.5MB per texture. The quality seems comparable, using the following shader:

    Code (csharp):
    1. half4frag (v2fIN) : COLOR
    2. {
    3.   float4ret = tex2D(_MainTex, IN.texcoord) * IN.color;
    4.   ret.a *= tex2D(_AlphaTex, IN.texcoord).g;
    5.   return ret;
    6. }
    (Note I wrote a little script that copies the alpha channel to the g component in the second case.)

    Despite the wasted channels, the quality looks very similar in both cases, but in option 2 it looks like we're saving 512k per texture (which is important in our case).

    I wonder if anyone has been down this path before and has any thoughts before I dig deeper.....
     
  2. bitter

    bitter

    Unity Technologies

    Joined:
    Jan 11, 2012
    Posts:
    530
    Just in case you missed it. Unity 5 already support split ETC1 for sprites.

    http://docs.unity3d.com/Manual/class-TextureImporterAndroid.html

    "Unity can use ETC1 for textures with Alpha, provided they are placed on some Atlas (by specifying the packing tag) and the build is for Android. You can opt in for this by setting the “Compress using ETC1” checkbox for the texture. Under the hood Unity will split the resulting atlas into two textures, each without alpha and then combine them in the final parts of the render-pipeline."
     
  3. PixelSquad

    PixelSquad

    Joined:
    Sep 4, 2014
    Posts:
    114
    Hi bitter

    I've tried this option before but I encountered two problems:

    1. I didn't find a way to disable mip maps with it (there might be a workaround)
    2. I found the following thread: http://forum.unity3d.com/threads/new-texture-compression-option.353668/

    The question I have is: I'm using my own shaders. Where in the render pipeline does Unity combine the two textures it generates? (In other words, is this feature really working?)

    Many thanks again
     
  4. sandboxed

    sandboxed

    Unity Technologies

    Joined:
    Apr 6, 2015
    Posts:
    95
    Hey @PixelSquad

    It seems that your shader is doing the right thing.
    Alpha textures on an atlas, and enabled ETC1 compression works this way...
    * Atlas is generated with alpha textures
    * Atlas is split into two non-transparent parts, and compresses each with ETC1 compression.
    * Sprites-Default.shader (and your custom shader) can access the two parts by _MainTex, _AlphaTex.

    There were some bugs with preview UI reporting usage of ETC2 instead of ETC1 which have been fixed.
    Also, the ETC1/Alpha feature doesn't work for UI images. We are looking into that.
     
    PixelSquad likes this.
  5. robinbobin

    robinbobin

    Joined:
    Aug 22, 2018
    Posts:
    4
    Does ETC1/Alpha feature could work for non sprites? I mean for mesh renderer with default type texture
     
  6. kaarloew

    kaarloew

    Joined:
    Nov 1, 2018
    Posts:
    360
    It should work for mesh renderer. But it is much easier to drop OpenGL ES 2.0 and use ETC2.