Author Topic: Weird lines on edges of sprites sometimes (especially with anti-aliasing)  (Read 11876 times)

DoctorWhy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 35
    • View Profile
Every so often, weird lines will appear on the edges of certain sprites.  Sometimes, pressing "Make Pixel Perfect" will make the lines go away, and others, it does absolutely nothing. For instance, the BottomEdge.png and TopEdge.png images below.

And this is especially apparent when I turn on anti-aliasing, but it then happens with every single sprite (see the NoAA.png and AA.png below).

I figure this can be graphics card dependent, as the AA problem happens on one machine, but not another (both are Windows 7). But the first two images happen on all machines I have tested on.

What do I need to do to fix this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Means you created your atlas with pixel padding changed to 0. Change it back to 1 and re-add your sprites.

DoctorWhy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 35
    • View Profile
That worked to fix the X (even while AA), but that didn't fix the image with the words even when not AA, and the other images while AA.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Your images must also be pixel-perfect. Are they? Select the UIRoot and hit Alt+Shift+P.

DoctorWhy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 35
    • View Profile
Yes they are (that screwed up my labels, actually as well, but I think I saw a post about this)

DoctorWhy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 35
    • View Profile
Ok, so I found out the problem with the image of the text (I moved the parent based on the position of something, which happened to place it at .25, which caused the pixel perfect not to work, so I am guessing pixel perfect isn't based on the world position, but instead, the local position?)

But it doesn't explain how AA is screwing it up so badly on images that are not a problem when not AA.

EDIT: BTW, just in case it matters, I have a built in Intel HD 4000 graphics. My screen resolution is 1600X900, but even if I drag it over to my other 1080p monitor connected through HDMI, it still has the issue when AA.
« Last Edit: February 18, 2013, 07:30:16 PM by DoctorWhy »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Always local, never world. The position of all objects must use whole integers (excluding UIRoot), and scale must be (1, 1, 1) -- excluding widgets themselves which should be pixel-perfect.

Also keep in mind... your UIRoot must be set to pixel-perfect mode.

DoctorWhy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 35
    • View Profile
That is all the case (now). But the anti-aliasing still screws up nearly every sprite.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
If everything is correct, then this wouldn't happen -- so you are still missing something. Look at your atlas. Open it in Photoshop or any other editor and find the sprite using the pixel coordinates you see when you select this sprite in the atlas in Unity. Is there a 1 pixel border? Is the texture set to ARGB32 (truecolor)? I've covered all the causes.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
If the sprite is centered and an Odd size (65x65 for example) it will have a half-pixel on each side that will blend weirdly. Try offsetting the sprite with 0.5f on Y.

As a test, try to set the pivot to TopLeft and see if that fixes the line.

DoctorWhy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 35
    • View Profile
Re: Weird lines on edges of sprites sometimes (especially with anti-aliasing)
« Reply #10 on: February 20, 2013, 01:38:42 PM »
If the sprite is centered and an Odd size (65x65 for example) it will have a half-pixel on each side that will blend weirdly. Try offsetting the sprite with 0.5f on Y.

As a test, try to set the pivot to TopLeft and see if that fixes the line.

It is 70x70.  The pivot is the top left. I tried offsetting my 0.5, but the line (though sometimes thicker or thinner) still exists.

If everything is correct, then this wouldn't happen -- so you are still missing something. Look at your atlas. Open it in Photoshop or any other editor and find the sprite using the pixel coordinates you see when you select this sprite in the atlas in Unity. Is there a 1 pixel border? Is the texture set to ARGB32 (truecolor)? I've covered all the causes.

But it is happening, and as far as I can tell, everything is correct.  And since this happens on my computer, but the exact same project looks great on another, I think it is a graphics card issue.  The pictures are below. They have 1 pixel.  I even gave them a 5 pixel padding and it still didn't change anything. They are all RGBA 32bit (Whenever I edit the atlas, it automatically gets changed to RGBA 32bit, even if set to ARGB 32bit).

DoctorWhy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 35
    • View Profile
Re: Weird lines on edges of sprites sometimes (especially with anti-aliasing)
« Reply #11 on: February 20, 2013, 02:21:30 PM »
I just noticed that AA doesn't only screw up the top and bottom borders. It also scews the image ever so slightly.  First image is without anti-aliasing, and the second is with. Look at the letters. They are images, so it isn't a text thing.
« Last Edit: February 20, 2013, 02:23:02 PM by DoctorWhy »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Weird lines on edges of sprites sometimes (especially with anti-aliasing)
« Reply #12 on: February 20, 2013, 08:34:39 PM »
Sounds like the Intel card you have does something questionable with its AA.