2D Toolkit Forum

2D Toolkit => Support => Topic started by: habitoti on February 09, 2014, 04:48:15 pm

Title: Atlas Compression
Post by: habitoti on February 09, 2014, 04:48:15 pm
Hi,

a Unity texture can be compressed by a variety of formats (especially ETC for Android, see below). Is there a reason that it's rather limited for the TK2D Atlas when set to "Unity Texture"? I might be completely misled, but from what I read, at least for Android it's strongly recommended to use ETC.

I can change the compression to ETC2 once I created an atlas with uncompressed unity texture setting, but on every new commit it is then switched back to truecolor. It would be great if I could choose that compression upfront already, or if there would be a configurable postprocessing step to apply the desired compression to it.

Regards, habitoti

(http://rombos.s3.amazonaws.com/Misc/Compressions.png)
Title: Re: Atlas Compression
Post by: habitoti on February 09, 2014, 07:42:20 pm
I think I found it myself  8)

I can simply override the compression for deployment to the device. This setting is retained even I re-commit the sprite collection...
Title: Re: Atlas Compression
Post by: unikronsoftware on February 09, 2014, 09:28:20 pm
That should do it. You do realise ETC doesn't support alpha, right? I've been warning to put in a post build callback so you can split up the atlas into 2 ETC textures for alpha support, not got around to it yet. I've put that in the roadmap for tk2d 2.5. Now to get the next 2.4 release done...
Title: Re: Atlas Compression
Post by: habitoti on February 09, 2014, 09:35:13 pm
Yeah, but I have quite a number of rectangular sprites that don't have alpha. Wish ETC2 would be available for GLE2 already -- it's so much better...
Title: Re: Atlas Compression
Post by: habitoti on February 10, 2014, 06:02:58 pm
After digging a bit deeper, it looks like ETC is really the only useful compression for Android deployments (since for all others you might end up with SW decompression, which makes no sense), but it works only on non-alpha atlasses (ETC2 is much better, but only available with GL3 and probably only on very few HW today)
So a great value prop for TK2D would be to support an RGB/Alpha split under the hood of an atlas, plus a shader that recombines them later on. Such atlasses could both be ETC compressed.
Not sure how much work that would be, but Android devs would love you for that!
Title: Re: Atlas Compression
Post by: unikronsoftware on February 11, 2014, 09:46:46 am
That would be trivial to implement. The issue is supporting it seamlessly across the board.
Stuff like this is so annoyingly complicated in Unity - for starters adding the rgb/alpha tex ref to this object will mean those textures get included in other builds too. Once you work around something like that its also really annoying that you've gotta constantly keep on top of it as Unity keep changing behaviours...

I think its realistic to add support for a post build callback, and even maybe have a little plug in that splits up a texture into 2 ETC RGB / A textures. Beyond that point it gets into very very messy territory.
Title: Re: Atlas Compression
Post by: habitoti on February 11, 2014, 10:31:29 am
But wouldn't you just need to create one RGB and one Alpha texture on "commit" in the collection, and there is a special flavor of sprites that is based on such a "twin collection", including the special shader to rejoin both channels again? You just include two textures (both of which can then be ETC compressed), and beyond that it would be compeletely transparent for the developer...how would Unity prevent you from that?
Title: Re: Atlas Compression
Post by: unikronsoftware on February 11, 2014, 10:46:52 am
Doing that would be rather wasteful on all other platforms - the ideal solution is to do that only on android. Its fine if you're only doing android dev, but almost everyone using tk2d does cross platform stuff with it. The point is its not exactly easy to have an android only variant of that material with the 2 textures, automatically.
Title: Re: Atlas Compression
Post by: habitoti on February 11, 2014, 09:44:05 pm
Well, it's not wasteful at all in general. You are just splitting off one layer (24+8 bit vs. 32), so uncompressed it's basically the same total texture space consumption. And next you can define a per-platform compression that has the widest HW implementation adoption (e.g. ETC on Android, PVRTC for iOS etc.), and furthermore non-alpha compressions are usually better (even in SW) and have a broader availability, so there would be lot of applications for such a mode, I believe. I think this would be a big advantage to offer it (nobody _has_ to use it...), not just limited to Android.

Anyway, just my 2 cents  ;)
Title: Re: Atlas Compression
Post by: coshea on November 24, 2014, 12:35:32 pm
+1 vote for this as a possible feature too, would be great :)
Title: Re: Atlas Compression
Post by: EvolveGames on June 10, 2015, 04:00:06 pm
Has this been implemented? (The ETC1+Alpha spliting) I saw it on trello for 2.5 but can't find anything inside Unity.
Would love any news/workaround! Thanks in advance
Title: Re: Atlas Compression
Post by: unikronsoftware on June 12, 2015, 11:31:39 am
No. Not planning to implement this. However, we did add a callback when a sprite collection is built.
tk2dSpriteCollectionBuilder.OnPostBuildSpriteCollection

You can hook into that, do what you want with the output textures there without modifying tk2d source. This happens right at the very end of the build, so you can assume everything is complete by then.