Hello Guest

Author Topic: Dicing with multiple atlases?  (Read 10053 times)

ENAY

  • Newbie
  • *
  • Posts: 17
    • View Profile
Dicing with multiple atlases?
« on: April 20, 2012, 04:30:37 am »
If there anyway to be able to use dicing but with multiple atlases as well?

For example I have a 450x800 sprite (Android screen size) as my backdrop. Looks ok in Windows or on Mac.

But when I compile on handhelds the sprite goes all pixelated. Looks ok on iPhone4 but earlier iPhones/iPad etc it doesn't look right, big or obscure texture sizes causes the textures to get automatically scaled down and look worse.

If I chop a 256x256 segment out of the backdrop and put that on screen, everything is fine. With your library, you can dice individual sprites into smaller chunks, but only on the same atlas and texture sizes that are smaller than the maximum texture size of the atlas.

I could fix this manually and chop up all my backdrops into 256x256 and create multiple sprites, but it takes time, and then becomes difficult to edit the gfx later since they are all in pieces.

What would be useful is being able to automatically chop up this large image into 256x256 (or however much you specify) and then when you click "Commit" it automatically creates multiple atlases until it has finished.

Is this feature possible, or maybe could be added a future release? Would be very handy for mobile developers not having to worry about texture sizes.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Dicing with multiple atlases?
« Reply #1 on: April 20, 2012, 10:29:37 am »
This was intentionally left out one main reason - sprites could be ordered in any arbitrary order in the atlases, and the draw calls for the final sprite would be pretty much random depending on the order in the atlas and how things ended up in there.

Its hard to support a feature like that, and then get tons of requests/complaints saying performance has dropped for unknown reasons - it will also be really really difficult to debug. I understand the need for not having to worry about texture sizes, but then you'd have to worry about non deterministic performance. I'm not convinced the tradeoff would be worth it.

I can consider it for inclusion if there is sufficient demand for it though.

ENAY

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Dicing with multiple atlases?
« Reply #2 on: April 20, 2012, 12:01:12 pm »
Considering that even the iPhone1 has a maximum texture size of 1024x1024 I am not entirely sure the reason for this sudden drop in quality for even 512x512 textures. I can only assume it is something to do with how Unity compiles to X-Code.
However the fact everything is ok on the latest iPhone, could be a hardware saving thing after all.

Perhaps maybe if you had a new type of sprite "Background Sprite". You could specify the resolution of your target platform and the maximum texture size you would like to have the background segmented at, then maybe it could work. A background sprite would only have a maximum of 1 image only.

Right now, I am still experimenting with various sizes and implementations to see what works best.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Dicing with multiple atlases?
« Reply #3 on: April 20, 2012, 12:44:36 pm »
The background sprite thing is a good idea. I will add it to the TODO.

I missed your question about the texture size - I have no idea why this is happening, but you can verify if it is an issue with Unity by simply dropping that texture onto a cube, and then running on the older iPhone? I expect it to be broken and low res in there too.

ENAY

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Dicing with multiple atlases?
« Reply #4 on: April 23, 2012, 02:50:31 am »
It is the same on a cube, presumably because the problem is texture related and not surface related.

What I have is 98% of my sprites all on the same atlas, the size is 1024x512. However all the sprites look pixelated when I draw them.

So I made a new SpriteCollection and only added one 128x128 sprite. Then I drew them both alongside each other, one from the main sprite collection and then the one that was just the only sprite. There is a considerable difference.

Except on the latest iPhone, which presumably can handle 1024x1024 no problem.

I think the background sprite would a great addition to your library, I look forward to seeing what you come up with.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Dicing with multiple atlases?
« Reply #5 on: April 23, 2012, 09:27:32 am »
max texture sizes are 1024x1024 on iPhone3G and 2048x2048 on 3GS and above. Your problem sounds like it could be something different. Could you send me a repro case demonstrating this issue?

support at unikronsoftware dot com

ENAY

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Dicing with multiple atlases?
« Reply #6 on: April 24, 2012, 02:20:03 am »
Can you compile to iPhone with a Mac?

I am a bit snowed under at work atm but I will try and make something when I have a spare minute.

The easiest way to replicat this yourself is to simply make a camera and 2 sprite collections.
Make the 1st collection with a single 128x128 image in it. Make the 2nd collection with the same 128x128 image in it but also add a second sprite that is something like 1024x1024, basically anything to make a huge atlas.

Now create 2 sprites, one from the 1st collection and one from the 2nd collection, compile to iPhone and look. The sprite bundled together with the big 1024 texture should be blocky and less quality.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Dicing with multiple atlases?
« Reply #7 on: April 24, 2012, 09:04:19 am »
The second atlas should end up at 2048x2048 - thats only supported on the newer devices. What devices are you having problems with?

Yup I can compile to iPhone

ENAY

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Dicing with multiple atlases?
« Reply #8 on: April 27, 2012, 12:42:33 pm »
Hi Unikron,

Well a tiny update on what is going on. We have been redoing all our graphics and now we have a game resolution of 640x960. Whilst I can't say if the problem has occured or gone away, I am thinking it could be to do with pixel aspect ratio after all.

What I have done is coded the game so a single Unity world coordinate is the same as 1 pixel. Therefore the game runs in 640x960 Unity world coordinates so it should be pixel perfect aspect ratio when rendered on a mobile device.

Whilst everything looks ok in the GUI, once I compile to certain devices the pixels are slightly blurry, same sort of issues I was having before. When sprites move across there is a clear pixel twitching effect.

I have ticked the boxes in tk2d for pixel perfect. Have messed with the camera, I even attached your Tk2d pixel perfect helper script into the camera and messed around with the settings in that, and nothing seems to make any difference. Very odd indeed.

I still can't work out whether this is a fault in Unity, your library, or some mistake that I have missed.
The particle system is using Unity's inbuilt particle system instead of your library since it was faster, but these particles all look fine and have no problems with pixelation at all.  ???

The plot thickens.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Dicing with multiple atlases?
« Reply #9 on: April 27, 2012, 01:58:55 pm »
Are you using the tk2dCamera? If you are then it should automatically detect and compensate for different devices (mainly opengl vs d3d)
If not, which devices in particular are you having problems with, and what resolutions are they running at ?

ENAY

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Dicing with multiple atlases?
« Reply #10 on: May 01, 2012, 05:21:53 am »
So I am not using the tk2dCamera actually. It is our own code. The game playing field is 640x960 and the camera is locked to that. So everything looks ok on the iphone 4, presumably because that is the resolution of that device. In Unity there is a view mode "iPhone 4G Tall (640x960)" so that is presumably why that works.
But the ipad is 768x1024 and older iphones are 480x320, which is presumably why they look a bit strange.

I am getting the screen width using Screen.width and Screen.height in Unity but even after scaling to the right resolution, things don't quite look right.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Dicing with multiple atlases?
« Reply #11 on: May 01, 2012, 10:17:59 am »
I'll try to set up a demo scene for this. Drop me an email at (support at unikronsoftware dot com) and I'll send it your way when ready.