• Unity
  • eliminating allocations when repacking atlases & PMA issues

hi, I've been getting along with the spine repacking feature for equipping/unequipping stuff - it's a pretty cool system that i've almost got working perfectly.

I noticed that this feature is not well suited for mobile, though - the repacking feature allocates tons of textures (even with caching), so I've been trying to eliminate these things by rewriting parts of the library to re-use textures, etc.

The last problem I've ran into is PMA related issues when we call Spine.Attachment.GetRemappedClone(sprite, sourceMaterial). I really want to avoid having this method create a new texture with PMA, so what can I do to avoid the types of issues outlined in this guide (Premultiplied Alpha Guide) ?

The sprites i'm currently passing in are "Straight Alpha", but I've tried redoing the sprites to have PMA, and I've tried all the different included spine shaders, but I haven't unlocked the secret combo. Maybe there's a secret sauce here?

I think the last ditch effort would be to just precalculate the PMA for a sprite and save that data to a text file/byte array. then read that at runtime (instead of the sprite). i'm not sure how well that would work across various platforms.

Related Discussions
...

There's really not much you can do to avoid the issues mentioned in the guide without using PMA. So you definitely want to generate a PMA atlas.

I'm unsure what you mean by "I haven't unlocked the secret combo.".

yeah i've noticed that.

I think the right set of settings for straight alpha is to use the Spine/Straight Alpha/Skeleton Fill, it seems to work.

I think when i wrote my first post, i was trying that shader, but i was getting bad results because of the way i was reading the pixel array. I was trying to use Texture2D.GetRawTextureData to read & write pixels without allocation, but for some reason it was only returning like every other column of pixels at the time, result in a really crazy looking texture. In hindsight, I was probably not calling GetRawTextureData correctly. I may have been using <Color> instead of <Color32>

Anyways, will probably try precomputing PMA and bundling the data as a text file eventually.