Author Topic: Atlas Switching script  (Read 50735 times)

n8

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
Re: Atlas Switching script
« Reply #15 on: December 28, 2012, 10:52:04 AM »
Nicki is correct, you should clear out the original atlas in the editor before building to be certain that you are not loading then reloading an atlas into memory.

FizzPow

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
    • FizzPow Games
Re: Atlas Switching script
« Reply #16 on: December 28, 2012, 11:30:43 AM »
I see, any idea how I might automate this process?  I have 4 Font References, and 3 Atlas References to clear.

n8

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
Re: Atlas Switching script
« Reply #17 on: December 28, 2012, 11:50:22 AM »
not to criticize your design, but 4 font and 3 atlas references seems a bit high.  Are those references just for different resolutions or are they actually being used in your UI?  if they are just the different resolutions, then you should only have one atlas reference and have all of your ui components using that one, and one font reference where all fonts are using that one.  Then you should only have to clear out those two reference objects before building. 

If you have 4 fonts and 3 separate atlases in your UI, then I would seriously recommend redesigning your UI to stream line down to one of each.  each atlas requires a draw call and extra memory usage, so I would do my best to minimize the need for extra atlases and fonts, especially if you are wanting to run well on older devices (3gs and lower, most android phones).

As far as automation, I am not intimately familiar with tweaking Unity's build process.  My first thought would be to write a standard Editor script that would let you just push a button and clear those references before firing off a build.  I am not really sure how to make that whole process completely automated.

FizzPow

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
    • FizzPow Games
Re: Atlas Switching script
« Reply #18 on: December 28, 2012, 11:59:42 AM »
We just ran out of space on 4096x4096 Atlases (iPadHD), so have to use more than one.  We have lots of art, and some big pieces for backgrounds, not hard to do.

As for the fonts, I am using 4 of them without an atlas and using command-line tools of Glyph Designer to auto generate SD/HD/SHD.  I suppose after I create them, I could go and create an atlas out of the 4 each time for all 3 resolutions, just such a pain. And would have to re-create every time I tweak a font.

Since our lowest target is the 3GS, and the assets are scaled down to 1024x1024 for that device, there is hardly a memory concern at the moment.  I have profiled in XCode.  Also 5-7 draw calls seem to have absolutely no effect on performance, still maxing 60.  I only saw draw call issues on 3G and lower devices in the past.

An editor script is what I was thinking, but would be even better if it could be triggered automatically on a Build & Run somehow.

Edit: Not sure if this is the best way, but it looks like I could create my own Build item and do some stuff pre-build using this:
http://docs.unity3d.com/Documentation/ScriptReference/BuildPipeline.BuildPlayer.html
« Last Edit: December 28, 2012, 12:06:31 PM by FizzPow »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Atlas Switching script
« Reply #19 on: December 28, 2012, 12:12:55 PM »
"Big pieces for backgrounds" <-- red flag! Don't put them in atlases. Keep backgrounds as separate textures and use UITexture to display them.

FizzPow

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
    • FizzPow Games
Re: Atlas Switching script
« Reply #20 on: December 28, 2012, 12:17:42 PM »
Understood, but they are not full size backgrounds, just somewhat big pieces that are layered in the background.  Ours is a 2D app/game FYI, not using this just for UI.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Atlas Switching script
« Reply #21 on: December 28, 2012, 12:35:14 PM »
Yup, no need to have them in the atlas regardless. Big pieces in general should rarely end up in atlases.

FizzPow

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
    • FizzPow Games
Re: Atlas Switching script
« Reply #22 on: December 28, 2012, 12:35:59 PM »
What is the benefit to moving them out of the atlas?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Atlas Switching script
« Reply #23 on: December 28, 2012, 12:36:51 PM »
Save atlas space.

FizzPow

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
    • FizzPow Games
Re: Atlas Switching script
« Reply #24 on: December 28, 2012, 12:38:10 PM »
I guess I just don't understand why it matters to have to use multiple atlases vs a bunch of UITextures. 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Atlas Switching script
« Reply #25 on: December 28, 2012, 12:39:54 PM »
When you add large things to an atlas, there will always be some wasted space left over because of how things can't quite fit perfectly right. Using a UITexture for big things, there is no such wasted space on those textures.

FizzPow

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
    • FizzPow Games
Re: Atlas Switching script
« Reply #26 on: December 28, 2012, 12:42:48 PM »
But if my big sprites are not POT shaped, isn't it wasting a lot more memory on the device and creating more draw calls?

n8

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
Re: Atlas Switching script
« Reply #27 on: December 28, 2012, 12:46:16 PM »
isn't what the "UV rectangle" is for on the UITexture script?  make the texture POT and then put the background in that filing whatever space it needs, then set the "UV rectangle to the size of your useable image.  I guess either way you are going to have some wasted space it seems

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Atlas Switching script
« Reply #28 on: December 28, 2012, 12:50:38 PM »
I guess it depends on whether the device supports NPOT textures or not. Keep in mind you can also use compression on the background textures if they are not in an atlas. That too may save texture space. Either way, it's best to have one atlas for your UI elements and keep things that don't need to be in the atlas -- outside it. Just my suggestion.

FizzPow

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
    • FizzPow Games
Re: Atlas Switching script
« Reply #29 on: December 28, 2012, 12:56:27 PM »
I understand your suggestion, but it seems more suited to a different kind of game.  Compression is not an option, it looks horrible.  All our sprites are 2D vector art and need to be very sharp, just like UI.  I could consider moving 1-2 pieces out of the Atlas, but that will still not save us from needing multiple atlases.  Also, it creates a burden of having to create SD/HD/SHD versions of all the UITextures as well and then dynamically changing the UITextures somehow as well.