Search Unity

Using custom texture atlas and separate alpha textures

Discussion in 'UGUI & TextMesh Pro' started by Spellbound, Aug 25, 2014.

  1. Spellbound

    Spellbound

    Joined:
    Sep 9, 2011
    Posts:
    51
    Hi,

    We have been working on projects with our own GUI library for some years now and would like to make the switch to uGUI. There are a few things that seem quite limited right now, regarding the way we must specify textures (sprites).

    Unity's atlases and alpha separation

    We use separate texture sheets for color and alpha channel to get high quality ETC color compression (5,6,5). Since Unity's internal atlas system does not support separating the alpha and no shader shipped with Unity supports sampling a separate alpha texture, we use Texture Packer to build separate color and alpha atlases externally, create quads with proper UVs using our libs and render with custom shaders.

    How can we apply this workflow to the new uGUI elements, that mostly require a simple sprite as texture source?

    Can we write custom uGUI elements like an image or checkbox with state graphics, that take 2 texture inputs (color and alpha), uv0 coordinates (representing the sprite position in the atlas) and a custom material?

    We would like to take advantage of all the new stuff, like anchors, click handling, canvas, masking but still be able to use custom build texture sheets.

    Any information how to handle this would be great. We work a lot on mobile advertising games where the client demands high graphics quality and that alpha separation trick so long was the best solution in regard to performance and application size. Uncompressed RGBA32 was simply crashing on some test devices (Unity 4.5.3), so that's no solution.

    Thanks,
    Dirk
     
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Hi, yes you can do this but it will be work on your end (we don't intend to offer first party support for such a custom workflow). This will become much easier once we open source the UI but until that stage you can take a look at the Image class here:
    https://gist.github.com/stramit/d2e1a94cdf3dbe08caac
    and the graphic:
    https://gist.github.com/stramit/1726f520d152895aed97

    What you want to do is extend Graphic and much like image you want to generate vertices / UV's ect. For the default material we do:
    Code (csharp):
    1.  
    2. static public Material defaultGraphicMaterial
    3.     {
    4.         get
    5.         {
    6.             if (s_DefaultUI == null)
    7.             {
    8.                 Shader shader = Shader.Find("UI/Default");
    9.                 s_DefaultUI = new Material(shader);
    10.                 s_DefaultUI.hideFlags = HideFlags.DontSave;
    11.                 s_DefaultUI.name = "Default UI Material";
    12.             }
    13.             return s_DefaultUI;
    14.         }
    15.     }
    16.  
    And you will want to replace it with some custom material that knows to use 2 textures.

    This is just some pointers to get you started.
     
  3. Spellbound

    Spellbound

    Joined:
    Sep 9, 2011
    Posts:
    51
    Thanks for the info! Good to know we'll be able to access and modify the code directly. I guess we'll wait then until the UI goes open source and we can see the whole scope.