Author Topic: Atlas Algorithm  (Read 6830 times)

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Atlas Algorithm
« on: July 18, 2012, 04:51:47 AM »
Hi !

Long time no see :)

Well, I have a set of sprites that I want to put in an atlas, the problem is that it seems that the algorithm you're using is not the best.
If I use all my sprites with Texture Packer and the "Max Rects" algorithm, everything fit in a 2048x2048 atlas, but in NGUI, it just does not fit and my images end up cut.

So, what is your advise on this ? Make two atlases ? Or maybe you have a magic update coming to improve the atlas algorithm ? :D

Thanks !

PhilipC

  • Guest
Re: Atlas Algorithm
« Reply #1 on: July 18, 2012, 08:50:43 AM »
We use Unity to pack the textures into the atlas (line 92 of UIAtlasMaker) So no we cant change the "algorithm" use to pack textures. Is it maybe that you have your padding set to something high which is causing it? Otherwise yes you might need 2 atlases :(

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: Atlas Algorithm
« Reply #2 on: July 18, 2012, 08:55:42 AM »
Hum, no I'm using a padding of 1px to do that.

I didn't know the methods PackTextures existed ! Maybe we could write a similar one but using another algorithm ?

We just need to add every sprites to a single texture and then retrieve a Rect array, right ?

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: Atlas Algorithm
« Reply #3 on: July 18, 2012, 09:10:43 AM »
I have found something really interesting,

It seems someone on the Unity forum ported the MaxRects algorithm to C# for Unity3D.
It is worth taking a look : http://forum.unity3d.com/threads/130376-MaxRectsBinPack-C-port-useful-for-creating-Texture-Atlases

It should solve the problem because it's using another (best) algorithm, and it should be easy to implement because you just need to call a method written in the post of the forum. It returns an array of Rect, just as the Unity3D default methods.

I've tried implementing it, but I have an error saying that the Texture file format is not supported, that it needs something like ARGB 32bit.

Do you think you could take a look at it ? That would be awesome !

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Atlas Algorithm
« Reply #4 on: July 18, 2012, 10:57:03 AM »
Interesting, I'll have a look at it (or Phil will). Unity's texture packing has issues with long or narrow sprites. If you avoid those, it works really well.

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: Atlas Algorithm
« Reply #5 on: July 18, 2012, 10:58:19 AM »
Yeah but sometimes you need those sprites :)

Let me know if you've been successful ! And thanks.

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: Atlas Algorithm
« Reply #6 on: July 23, 2012, 12:02:33 PM »
Awesome ! Thanks for being so fast including this in the 2.1.1, it's working exactly as expected :)

PhilipC

  • Guest
Re: Atlas Algorithm
« Reply #7 on: July 23, 2012, 01:36:02 PM »
Not exactly as expecting working on a fix for it :) hopefully will be ready shortly.

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: Atlas Algorithm
« Reply #8 on: July 23, 2012, 01:44:08 PM »
Hehe ok !

PhilipC

  • Guest
Re: Atlas Algorithm
« Reply #9 on: July 23, 2012, 03:04:59 PM »
It will go into the next update. Just a fix to ensure the atlas is as small as possible :).

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: Atlas Algorithm
« Reply #10 on: July 23, 2012, 03:09:00 PM »
Nice !