Hello Guest

Author Topic: Atlas settings for 2x platform won't work  (Read 10399 times)

Vell

  • Newbie
  • *
  • Posts: 7
    • View Profile
Atlas settings for 2x platform won't work
« on: April 18, 2013, 12:45:50 pm »
In our game for iOS we have long sequences of animation. Some of them created for 2x platform. Since iOS platform only allow textures below 2048x2048, on creating animation atlases I set "Max Size" for atlases 2048 and also set checkbox "Force Square". It's works great for 1x platform, but looks like 2x atlases igone those settings. I've tried "Force Atlas Size" but this produce no result. I'm also tried to set "Multiple Atlases", but looks like it's only affects 1x atlases. Is I'm doing anything wrong or it's probably bug?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Atlas settings for 2x platform won't work
« Reply #1 on: April 18, 2013, 02:28:21 pm »
Your 1x atlases are 2048x2048? Then there isn't a choice is there, your 2x ones will need to be a minimum of 4096x4096...
You could try multiple atlases with 1024x1024 atlases at 1x, so at 2x it will be 2048x2048.

The build code scales the max texture sizes for each platform, so if max size is 2048 at 1x, it will be 4096 at 2x.

Vell

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Atlas settings for 2x platform won't work
« Reply #2 on: April 18, 2013, 03:05:56 pm »
The build code scales the max texture sizes for each platform, so if max size is 2048 at 1x, it will be 4096 at 2x.
Do you have plans do change this? It could save lots of space and also reduce draw calls. BTW thank you for explanation.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Atlas settings for 2x platform won't work
« Reply #3 on: April 18, 2013, 03:29:53 pm »
There are serious implications to forcing the same atlas sizes. So if you fill up your 2048 atlas at 1x, it means it will have to span at 2x. This is bad in more than one way -
1. A lot of features are not available when spanning, so a lot of features will actually stop working at 2x. Fine if you don't use the features though. Eg. dicing and so on.
2. You're going to introduce a serious amount of uncertainty to the draw call count. What works at 1 draw call at 1x might bloat to 100s at 2x because they are all in different atlases, materials.

I won't implement this in a future version, but if you understand the implications and want to implement it yourself, I can tell you what to change. Its only a couple lines to change to disable this, but its there for your safety :)

Vell

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Atlas settings for 2x platform won't work
« Reply #4 on: April 24, 2013, 03:54:52 pm »
Thank you for replies!
But for i've faced another problem. Our source animation sequences for both platforms contains 15k files. I'll explain better:
1. Towers and units in game can rotate, we splitted rotation in 32 angles(32 AnimationClips), units only have one state for each angle - walk, so when units walk we just play animation for specified angle and switch it to another AnimationClip when unit rotates. Towers have two states - idle and attack, idle have 1 frame of animation, and attack (mostly) have 2 frames, and, of course, towers have 32 possible angles too. We have 6 different types of towers in game, and 5 grades for each type. So, as you can see, we have a lots of content (folder with all sequences, backs for levels and others, takes 814mb on HD). When we start creating SpriteCollections it's was pretty hard to use Asset Server and Unity starts beign very laggy, so we decided to remove all source texture(animation sequences, etc.) after creating SpriteCollection. It's all was created for 1x and 2x platform.
2. When all work about content creation was done. We tried to compile project to see it on iPad 3. We faced problem where Unity just crashes when trying to build project. My first thoughts was about tk2d atlases, as I wrote in first post, some of atlases for 2x platform was greater then 2048x2048. BTW I've submitted bug to Unity and recieved following answer:
"You have a lot of resources folders in your project.
We will look into making unity not run out of memory in that case, but it seems like you are not taking advantage of those folders, so please rename them to a different folder name."
In my project I have two resource folders - my levels prefab and tk2d resource folder. We decided temporarily remove 2x support from project. Because we don't had any source images of our content, we decided rebuild all content of project, without adding 2x platform in "Platforms" settings.
3. When we finished rebuilding I've mentioned one weired moment in tk2d resource folder. All assets in this folder disappeared, but as i remember, they was needed only for multiplatform support, so i've desired that's ok if you have only 1x playform ticked.
It's was preface to my problem. Hope you could understand my ridiculous english.
So, right know, we have huge spike on game scene start. It's looks like most of time goes on Texture.AwakeOnLoad execution. As I understand, Texture.AwakeOnLoad is a process where texture data passes to driver (I also asked this on unity 3d forums http://forum.unity3d.com/threads/179587-When-texture-get-loaded-to-GPU-and-what-is-Texture-AwakeFromLoad). I don't recieve answer yet when Texture.AwakeOnLoad really called, but I could say when it called in my project. When we had two platforms, Texture.AwakeOnLoad get called on object instantiating in tk2dSprite.Awake(), but when we rebuilded content, as i mentioned earlier, it's looks like Texture.AwakeOnLoad gets called on scene start for all used texture in scene. Also, execution time of Texture.AwakeFromLoad increased greatly. And, as you can see on screenshot, time of execution very different for atlases with same compression and size (RGBA PVRTC compressed 4bit). I absolutely, totally, misunderstanding what happend to project. I hope you could explain why tk2d Resources fodler is empty, why Texture.AwakeFromLoad execution so slow, and why all my tk2d atlases loaded at scene start and not on instantiating as before.

p.s. I greatly apologize for my english, and if you can't understand some of my phrases please tell me, I'll try to explain better. Thank you!
« Last Edit: April 24, 2013, 03:58:10 pm by Vell »

Vell

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Atlas settings for 2x platform won't work
« Reply #5 on: April 24, 2013, 04:28:21 pm »
BTW my project won't work on device. It's work on Mac with target platform iOS, but on device, when main game scene loaded, it's just get freezed (not switching to scene at all). update and start function on game scene don't get called, but Awake does,  I guess it's also connected with my situation.
« Last Edit: April 24, 2013, 04:35:32 pm by Vell »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Atlas settings for 2x platform won't work
« Reply #6 on: April 25, 2013, 12:01:43 am »
That is an interesting predicament to say the least. I can't say I have tested this with 15k files.

2. This just looks like Unity not coping properly with the volume of textures. I've had to do pretty horrible things to work around things like this - eg. building asset bundles to minimise the build memory usage.

3. If you removed 2x platform, you will not have anything in the resources folder as everything is loaded immediately, instead of deferred. So nothing is actually required to be in the resources folder, which is why all the files are deleted.

All your sprite collections are being loaded at scene start, and if all the sprites are visible at that point, all the textures get loaded at the same time.

So now my questions are:

1. How many atlases are you using in your scene, and how big are the images (dimensions, and approximate file size which Unity tells you in the inspector) of each?

2. Are you running out of memory on iOS? I suggest checking by deleting a bunch of things in your scene and testing again.

There are solutions to this, but we need to find out what is the cause first.

Vell

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Atlas settings for 2x platform won't work
« Reply #7 on: April 25, 2013, 09:07:08 am »
1. 3-5 atlases for enemies (depends on level loaded). Each unit has it's own atlas which dimension 1024x1024 and with RGBA 4bit PVRTC compression atlas size is 0.5mb. Some level contain bosses which atlases dimension is 2048x2048 and size is 2mb. One more atlas for level background image, 1024x1024 and 0.5mb of size, + may by 2-3 atlases for effects with 1024x1024 dimension. And here goes little story about towers atlases:
Before recent changes, we had game object which stores all towers prefabs (for all grades and type, 6 types x 5 grade = 30 prefabs), but since we faced texture loading problem (where Texture.AwakeFromLoad gets called on each atlas, even if atlas just stored in prefab and can't be visible), we changed this to following:
In our game, before you can build tower with higher grade, you must unlock it in upgrade menu, out of game scene. So we decided to not store all of possible towers prefab, because at first levels user simply can't build them. So on game scene Awake(), we get all possible prefabs(I mean path to them is resource folder) and then load all avaible to user prefabs via Resource.Load(). About towers atlases sizes: 1 and 2 grade can fit 1024x1024 and size 0.5mb, 3,4,5 grades fits only in 2048x2048 atlas with 2 mb size.
2. I've tried to run scene with minimal content (6 atases for towers, 1 for units, 1 back) and no result. Awake of game object from game scene gets called, but screen is freezed in prev. scene (unity connected profiler also gets freezed). Also, xCode print "System memory in use before: 5.2mb" after all my Debug.Log() in Awake(). May be it's not connected to my problem, but i haven't any ideas where to find problem or even start finding.

Most weird thing for me right now is why when we had 2 platforms our game worked perfect (if exclude problems when we can't build project with all content included, but on Mac game scene loading time was pretty low), but right now, with only 1 platform, but with all content included, game scene loading time jumped to 5k-8k ms (on Mac). I have little assumption about my problem. It's looks like right now all my used textures in scene loads at start up, but before they are get loaded when first time visible. Also, as you can see on my screenshot, atlas AwakeFromLoad() execution time is 600ms which is pretty high, I guess I would notice that if it has ever happened before.

Thank you for help.
« Last Edit: April 25, 2013, 09:10:11 am by Vell »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Atlas settings for 2x platform won't work
« Reply #8 on: April 25, 2013, 10:18:08 am »
As you figured out - when you have the asset loaded using platform collections, the loading is deferred until after scene load, whereas when it is off, they are all loaded immediately when the scene is loaded, hence the large AwakeFromLoad (I'm guessing).

We need to work out why its freezing. Try this:
Create a new blank scene, add ONE sprite from one sprite collection in there, build & run. See what happens. Keep adding a sprite from each unique collection until hopefully you have everything built in there. Can you get it to crash?

Vell

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Atlas settings for 2x platform won't work
« Reply #9 on: April 25, 2013, 11:00:44 am »
Is there any possibilities to no load immediately all textures?

btw, right now I'm adding sprites to scene as you said. right know I see no crashes, but I'll continue. Right now i have 17 atlases on scene from different collections and scene startup pretty high (2393ms) on Mac. I'm also noticed that some atlases loaded at 600 ms, and other at 0. Can explain this please? For this http://rghost.ru/45539210/image.png atlas Texture.AwakeFromLoad took 750ms and for this http://rghost.ru/45539254/image.png 0ms.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Atlas settings for 2x platform won't work
« Reply #10 on: April 25, 2013, 11:38:14 am »
If you can reproduce this 100% I'd fire off a bug report to the Unity support guys.

There should be no reason one of those takes so much longer than the other, unless the driver is stalling for some reason. I suppose on iOS you could use Instruments to see opengl es driver overhead as well. That could prove or disprove this theory.

Without platform collections, 2D Toolkit is just letting Unity load all the textures the way it normally does, so if its slow there it'll be one for them. Alternatively, if you could load the sprites in manually (eg. load a sprite prefab from a resources folder), then you could control the load order a bit better.

There is the final option to do something like what the platform sprite collection stuff does, basically enabling that code path all the time, but I wouldnt' recommend that if you ran into problems with the resources folder in the first place.

Vell

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Atlas settings for 2x platform won't work
« Reply #11 on: April 25, 2013, 12:45:37 pm »
There is the final option to do something like what the platform sprite collection stuff does, basically enabling that code path all the time, but I wouldnt' recommend that if you ran into problems with the resources folder in the first place.

Could you better explain it? What you mean by "enabling that code path all the time"?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Atlas settings for 2x platform won't work
« Reply #12 on: April 25, 2013, 09:25:52 pm »
There are 2 code paths to how a sprite collection is used.

1. The sprite collection is used explicitly, i.e. all dependencies are explicit, and Unity handles all the loading automatically. This is what is happening right now.

2. When platform collections are enabled, the sprite collection itself is just an empty container containing the GUIDs to the actual sprite collections. On Awake, the appropriate collection is loaded at runtime using Resources.Load. This path is only enabled when platform collections are enabled, and you have more than one collection.

What I meant was, I could probably give you a little hack to make it use path #2 all the time. Seeing you had better results when Resources.Load was used, this might be a better option.