Hello Guest

Author Topic: Generating multiple atlases for retina/non retina automatically  (Read 8671 times)

ehudros

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Generating multiple atlases for retina/non retina automatically
« on: December 23, 2013, 02:12:21 pm »
Hi everyone,
Just started evaluating 2dTK and Unity as alternative to Adobe Air/Starling and I have a couple of questions regarding atlases.
I'm used to working with multiple atlases (generated using texture packer) and choosing the correct ones in runtime. I see that 2dtk has a platforms option in the Sprite Collection settings window, but it seems to expect the source png's to be already scaled down. Is there a way I can feed it just one size of assets (the largest) and have 2dtk create 2 atlases (one with the original png size and one scaled down by half for lower res. devices)?
I haven't seen much references to multiple atlases as a performance enhancing approach - am I missing something here? Do most Unity developers not use that approach and have some kind of alternative method?
« Last Edit: December 25, 2013, 08:07:29 am by ehudros »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Generating multiple atlases for retina/non retina automatically
« Reply #1 on: December 24, 2013, 12:00:31 pm »
There is an undocumented feature to automatically scale down textures, but it does look pretty ropey as do most automatic downscaling atlas generators. It could look better, eg. by using bicubic filtering, but in our workflow we tend to generate sprites from vector graphics (or we use pixel gfx, where we only upscale), and the quality from downscaling vector graphics vs re-exporting is rather horrendous to say the least, especially when going from 4x - 1x.

You can also use mipmaps if you're not too bothered about getting the best image quality possible - thats just one checkbox in tk2d, and you can use the unity QualitySettings class to control how many mipmaps to drop.

ehudros

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Generating multiple atlases for retina/non retina automatically
« Reply #2 on: December 25, 2013, 08:08:32 am »
Hmm... I've used Texture Packer to downscale non vector graphics by 50 percent (2048 -> 1024, or 4x to 2x) and it is usually nearly unnoticeable.
Does that undocumented feature support such downscaling via the settings menu? How do I make use of it?
Currently I'm using the mipmaping feature with the 4x texture on devices that I'd rather use a 2x texture on (meaning anything that isn't ipad retina) but it doesn't look as crisp as I'd like it to (and know is achievable through a texture downscale).

PS - the forum returns an http 406 error if a percentage sign is used anywhere in a message (I'm guessing as part of sql injection prevention).
« Last Edit: December 25, 2013, 08:12:09 am by ehudros »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Generating multiple atlases for retina/non retina automatically
« Reply #3 on: December 26, 2013, 12:18:10 pm »
4x -> 2x isn't usually that bad, its 4x -> 1x that usually looks horrible.
Mipmapping is no different to a downscale, I suspect its down to the filter Unity uses to create the lower mipmaps, vs what texture packer uses.

In sprite collection settings, set Texture Settings > Rescale to 0.5, 0.25 to see if its good enough for you. If it is, a simple code change can enable this automatically with platform collections.





That http406 thing is new, I'll get in touch with the host to find out whats going on.
Edit: Should be sorted now.
« Last Edit: December 26, 2013, 02:27:03 pm by unikronsoftware »

ehudros

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Generating multiple atlases for retina/non retina automatically
« Reply #4 on: December 28, 2013, 06:17:53 pm »
Gave rescaling through the editor a try (4x -> 2x) and it looked just fine. I've changed tk2dSpriteCollectionPlatformBuilder.cs so it will use the original files and scale them down for 2x:
line 58: string platformTexture = FindFileInPath(directory, filename, ext, extensions); (basically force it to use the original  file and remove the @2x that was added)

line 97: added proxy.globalTextureRescale = scale;

Do these changes make sense? Is there anything you think I might have broken in the process?

EDIT - I've changed the current platform in the 2dtk preferences menu from 4x to 2x and everything now looks zoomed in by a factor of 2 (both in the editor and when I play it). If I switch to 1x it's zoomed in by a factor of 4. I'm using a 2dtk camera set to "fit visible" with a native resolution of 2048x1536 and preview set to 1024x768. The scene only looks right when I use the 4x atlas. Does it have something to do with the changes I've made or am I missing something regarding the way the 2d camera works? As far as I could understand, changing to a different atlas should affect anything other than the visual quality of assets (meaning all sprites should remain the same size).

I'm guessing this is a side effect of my tinkering? Or am I missing something with the
« Last Edit: December 28, 2013, 07:49:34 pm by ehudros »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Generating multiple atlases for retina/non retina automatically
« Reply #5 on: December 28, 2013, 07:50:22 pm »
No that should be it really. We never put it in because we weren't happy with the scaling results and at one point planned to integrate more scaling options. By all means use it if it works for you :)

ehudros

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Generating multiple atlases for retina/non retina automatically
« Reply #6 on: December 28, 2013, 08:36:40 pm »
I've edited my post above with an issue I've encountrred when using 2x/1x assets. Any idea what could be causing that?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Generating multiple atlases for retina/non retina automatically
« Reply #7 on: December 28, 2013, 08:59:52 pm »
The way this works is -
GlobalTextureRescale rescales the the texture, but keeps the sprite the same size.

Platform sprites are always the same physical size. This is done by setting
spriteCollection.globalScale in *platformbuilder.cs. So if going from 1x -> 2x it the 2x sprites are scaled by 1.0f / scale.

In this case, as the rescaled sprites are already the correct physical size, that won't be necessary.

ehudros

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Generating multiple atlases for retina/non retina automatically
« Reply #8 on: December 28, 2013, 09:11:04 pm »
Yep, commenting out line 120 (proxy.globalScale = 1.0f / scale;) did the trick.
Thanks!