Author Topic: Atlas issues, Image artifacts on truecolor sprites for iOS  (Read 7182 times)

chirhotec

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Atlas issues, Image artifacts on truecolor sprites for iOS
« on: December 17, 2013, 11:54:54 PM »
I'm working with Unity 4.3 and NGUI v3.0.3f3, on a GUI-centric social game for iOS, and am suddenly running into a lot of issues with Atlases and Sprites. I'm putting these issues in one thread because I'm not sure if they're related.

Atlas Generation:

First, I'm getting an issue where Atlas Maker isn't generating the Atlases properly. I select the sprites (about 45 of them), give it a name and hit "Create". It seems to run, and generates the GameObject, Material and the atlas image file (1024x512). However, when viewing the object in the Atlas Maker its not showing any of the sprites in the list. If I press the available "View Sprites" button, it opens an empty "Select a Sprite" window.

Now, if I reselect the desired sprites, they'll show up again in the Atlas Maker with the green "Add" text lit up. Hitting "Replace" starts to process; however, the "Updating" dialog hangs (at 100% with the text "Updating the atlas, please wait..."), and I have to manually kill Unity (though the OSX 'Force Quit Applications' doesn't show Unity as unresponsive, I can't really do anything or access any of the menus). The console shows an error, which I've included an image of as "Replace_Atlas_Error.png" (sorry for the image, I would have Copy/Pasted, but Unity wouldn't let me copy it at that point)

I am able to create the Atlas if I include less sprites at a time (I think it crapped out around ~20 for the initial atlas creation).

Sprite Artifacts

Moving on, lets say I create some Atlases with just a few images. When they are generated, for some reason Unity is automatically applying "Override for iPhone" on the atlas image settings, with the Format set to "16 bits". That of course looks horrible (http://www.tasharen.com/forum/index.php?topic=1497.0). However, if I change the Format to Truecolor or disable the iPhone override, the resulting sprites all have really horribly image artifacts on them.

I've attached an image (Texture_Sprite_Atlas_Compare.png) showing the crisp looking graphic rendered with a UITexture, what it looks like when the Atlas is first generated (set to 16bits), and what it looks like when I set it back to Truecolor.

A few more interesting things I just noticed that may be of help:
- The Unity Inspector's image preview of the .png shows the same artifacts, even though the .png itself doesn't have any artifacts.
- The Unity Inspector's image preview of the UISprite shows a proper looking image


Texture -> Sprite Automatically being replaced

Doing these tests led me to find another issue. During the test I had the UITexture object that displayed the reference "2" image. When I generated an Atlas that included the 2, the UITexture was automatically replaced with a UISprite (not what I was wanting, but I could see that being a feature). Problem is, the Sprite didn't actually show up, despite the Atlas and Sprite objects being set in the inspector. I've attached another image, in case it helps (Texture_To_Sprite_Autoreplace.png)


Sorry for the lengthy post, but if anyone has any suggestions I'd really appreciate it!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Atlas issues, Image artifacts on truecolor sprites for iOS
« Reply #1 on: December 18, 2013, 10:25:06 AM »
Please don't post about issues unless you've updated to the latest version of NGUI. Chances are high that they have already been fixed.

UITextures get replaced with sprites when those sprites get added to an atlas. It's an intentional feature, letting you create your entire UI layout using raw textures, then select the UIRoot and add them to an atlas.

When importing your textures, set the texture's "Alpha is Transparency" checkbox, and make sure that your atlas doesn't have "PMA Shader" checked (old version, new version has this flat out removed).

helmesjo

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 116
    • View Profile
Re: Atlas issues, Image artifacts on truecolor sprites for iOS
« Reply #2 on: April 23, 2014, 03:32:10 AM »
Sorry for bringing this back to life, but is there anyway of disabling the "Replace UITexture with UISprite"-feature? Or do I have to keep special copies for the textures used specifically on UITextures to avoid this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Atlas issues, Image artifacts on truecolor sprites for iOS
« Reply #3 on: April 23, 2014, 06:18:09 AM »
It falls under one of those "why would you ever need this" categories for me. Why would you duplicate memory by keeping both UITexture and the UISprite? Once a texture gets added to an atlas, it makes no sense to still keep it. This feature was added so that fewer people would shoot themselves in the foot by accidentally using both.

In any case, the function that does it is in NGUIEditorTools. It's called "UpgradeTexturesToSprites".

helmesjo

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 116
    • View Profile
Re: Atlas issues, Image artifacts on truecolor sprites for iOS
« Reply #4 on: April 23, 2014, 10:49:43 AM »
It falls under one of those "why would you ever need this" categories for me. Why would you duplicate memory by keeping both UITexture and the UISprite? Once a texture gets added to an atlas, it makes no sense to still keep it. This feature was added so that fewer people would shoot themselves in the foot by accidentally using both.

In any case, the function that does it is in NGUIEditorTools. It's called "UpgradeTexturesToSprites".

Because the texture in question has a gradient-shader, that's why :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Atlas issues, Image artifacts on truecolor sprites for iOS
« Reply #5 on: April 24, 2014, 01:12:57 AM »
Sure, but then why add it to an atlas? You can draw this texture using a simple UITexture. Why add it to an atlas and thus duplicate memory?

helmesjo

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 116
    • View Profile
Re: Atlas issues, Image artifacts on truecolor sprites for iOS
« Reply #6 on: April 28, 2014, 01:00:35 AM »
Sure, but then why add it to an atlas? You can draw this texture using a simple UITexture. Why add it to an atlas and thus duplicate memory?

Huh? Think you misunderstood. The texture I'm talking about is just a pure white pixel, used in different places where I need a tinted background. In most cases, it is rendered as a sprite, thus added to an atlas. But in the case of some backgrounds where I need a gradient, I use the same raw texture/white pixel for convenience. So every time I update the atlas, these UITextures gets replaced with UISprites which is kind of annoying after some time.

See? :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Atlas issues, Image artifacts on truecolor sprites for iOS
« Reply #7 on: April 29, 2014, 12:38:55 PM »
Just rename the texture to something else and it won't be replacing anything.

helmesjo

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 116
    • View Profile
Re: Atlas issues, Image artifacts on truecolor sprites for iOS
« Reply #8 on: April 30, 2014, 02:10:33 AM »
Just rename the texture to something else and it won't be replacing anything.

Yeah as I wrote in my first post, that's what I'm currently doing. Just enlightened you that one does not always want to replace UITextures with UISprites and so maybe it should be optional!

Cheers!