Author Topic: Issues with SD HD atlas switching  (Read 2947 times)

n3k0san

  • Guest
Issues with SD HD atlas switching
« on: November 07, 2013, 02:26:31 PM »
Hello

I'm having some issues with atlas switching with the latest version of NGUI. (3.0.4)
UISprite's are not resized.
My SD atlas has pixelsize 1, HD has pixelsize 2. Everything else besides UISprite elements are resized 2 times while switching atlas to HD.

Now if I add this on line 493 in UISprite.cs it works, but if I use a button (UIImageButton) it multiplies it 4 times (2 times for the actual UISprite and I assume it's called again for the parent)

  1.         protected void SimpleFill (BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
  2.         {
  3.                 Vector2 uv0 = new Vector2(mOuterUV.xMin, mOuterUV.yMin);
  4.                 Vector2 uv1 = new Vector2(mOuterUV.xMax, mOuterUV.yMax);
  5.  
  6.                 Vector4 v = drawingDimensions[b] * atlas.pixelSize[/b];

In BOLD is what I added.
This only seems to be the case for Simple UISprites... For example fonts and sliced sprites are ok...

Can you please have a look on this bug?

I could create a second HD atlas with a pixelsize of 1 and all images resized 2 times, but that would be overkill.

Thanks

n3k0san

  • Guest
Re: Issues with SD HD atlas switching
« Reply #1 on: November 07, 2013, 02:37:58 PM »
BTW, there's another bug on the UIImageButton component. No matter what I set in the Dimensions field for the child image, once I hit play, the initial size of the image is used (the one from the atlas). So it's not keeping my custom dimensions. This was not the case before. I had this issue in 3.0.2 also

UncleAcid

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 51
    • View Profile
Re: Issues with SD HD atlas switching
« Reply #2 on: November 07, 2013, 04:56:48 PM »
Your HD atlas would have already double sized images so setting pixel size to 2 gives you quadruple sized sprites.

SD -> HD atlas switching is intended for use with a Fixed Size UIRoot (where everything stays the same size on screen, only the pixel density increases), using a PixelPerfect UIRoot with atlas switching requires you to manually Broadcast/Call MakePixelPerfect for your UI and manually calculating some values in other widgets (ex. UIGrid.cellWidth, UIGrid.cellHeight).

As for the UIImageButton, as I recall it corrects the sizes of the images after setting them (to properly handle things like a hover image with a glow that is larger than the base button). So it makes sense that it would overwrite your custom set dimensions.

n3k0san

  • Guest
Re: Issues with SD HD atlas switching
« Reply #3 on: November 08, 2013, 04:23:25 AM »
I'm using an atlas reference, which use the same material and texture, so hd images are not double the size.
That's why I have to set the pixelsize to 2 in the HD atlas (since I first created the SD atlas).

The UI root was tested with fixedsize and fixed size for mobiles too.
Neither works

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Issues with SD HD atlas switching
« Reply #4 on: November 08, 2013, 10:50:30 AM »
PixelSize should be 0.5 for the HD atlas, not 2. You're doing the opposite of what you should be doing.

The higher the resolution, the lower the pixel size should be.

n3k0san

  • Guest
Re: Issues with SD HD atlas switching
« Reply #5 on: November 08, 2013, 04:20:52 PM »
Hi Aren

Well it does not matter that much, does it? You said it yourself in your video, that if we actually start with the SD atlas, we'd have to multiply the HD 2 times.
If we start with the HD, we multiply the SD with 0.5

Nonetheless, the issue still remains. UISprites are not multiplied by atlas.pixelSize

I guess I'll just end up creating 2 different psd files with 2 different GUI's for both SD and HD and just hide/show the proper gameobject, or load it from Resources as a prefab.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Issues with SD HD atlas switching
« Reply #6 on: November 09, 2013, 07:17:46 AM »
But that's the thing... the coordinates shouldn't change. That's intended. In the code you posted, you alter the drawn coordinates, which is not right. As I said, the only thing that should change is the pixel density. If the widget was 400x300 before, it should remain 400x300 after the atlas gets switched.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Issues with SD HD atlas switching
« Reply #7 on: November 09, 2013, 10:36:54 AM »
So...

In raw sizes, the HD atlas sprites should be double the size of the SD atlas sprites. A sprite that's 50x50px in the SD atlas, is 100x100 is the HD.

If we keep a fixed size of 500, and position the sprite at 0,0 then that sprite from the SD atlas should take up 1/10th of the screen height.
Changing to HD atlas, with no further modifications, makes the new sprite take up 1/5th (double the size, since it's 100px high).
So to offset that, we change the atlas to have a pixel size of 0.5f, such that it will still take up the same space on the screen 1/10th even though it has 4 times the information in it.

You could do it the other way around and design with your HD atlas in mind, keep that at pixel size 1, but then SD atlas needs to have pixel size of 2.

Like ArenMook said, you're doing the opposite of what you're supposed to be doing. The higher definition atlas, needs a lower pixel size, since you're cramming more pixels into the same virtual space.

n3k0san

  • Guest
Re: Issues with SD HD atlas switching
« Reply #8 on: November 30, 2013, 02:11:37 PM »
Hey guys, thanks for all the clarifications.

Thanks to your help I managed to get it working perfectly.

I restarted by creating my HD atlas first, so now I don't have any issue.

Thanks once again