Author Topic: Sprite Edges  (Read 14848 times)

FizzPow

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
    • FizzPow Games
Sprite Edges
« on: December 14, 2012, 08:16:37 PM »
The edges of some sprites seem to have some extra dark lines that are not in the original.  I recall having this issue in the past with other sprite systems and it had something to do with using premultiply alpha to fix it.  Is there a way to address this with NGUI, I am not even sure if it's the same issue.

Here's a picture on the left of what this sprite looks like in Unity.  All four edges have extra darkness that shouldn't be there.  I have noticed this on most of my sprites, but some are a lot worse than others.  I am open to other solutions like changes in how we master the artwork if need be.

Edit: I am also using 8 pixel padding to be sure its not bleed from other sprites.



Thanks for any help!
« Last Edit: December 14, 2012, 08:18:10 PM by FizzPow »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sprite Edges
« Reply #1 on: December 15, 2012, 03:40:49 PM »
When you zoom in on a sprite, bilinear filtering tries to enlarge the pixels, which means sampling neighbour pixels. It's always like that if you zoom in. If the sprite is pixel-perfect, the zooming does not happen, and neighbouring pixels don't get sampled.

FizzPow

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
    • FizzPow Games
Re: Sprite Edges
« Reply #2 on: December 15, 2012, 03:43:30 PM »
Hmm, well I zoomed in to amplify the issue, but you can definitely still see it when it's not zoomed.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sprite Edges
« Reply #3 on: December 15, 2012, 03:45:16 PM »
When it's pixel-perfect you shouldn't be able to.

That said, the drop shadow you have is obviously cropped. You might want to leave more space in Photoshop before exporting your image.

FizzPow

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
    • FizzPow Games
Re: Sprite Edges
« Reply #4 on: December 15, 2012, 04:00:49 PM »
Yes, that may be a poor example, but it's not relegated to just this image by any means, and adding more space does not fix anything.  Also, many/most things cannot always be pixel-perfect because I am scaling and animating them.  I know 2D Toolkit doesn't exhibit this behavior, and I believe it's to do with the pre-multiplied alpha it uses.

If you want, I can try to make a sample project showing the same sprites on both engines?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sprite Edges
« Reply #5 on: December 15, 2012, 04:05:01 PM »
It's only a matter of where your sprite is located. If it's next to say, a black sprite, then parts of the black sprite will bleed over to your sprite when you zoom it in, and it doesn't matter what shader you use -- pre-multiply or not.

In your original photoshop image leave some space around the sprite. When adding the sprite to the atlas, turn off "trim alpha". That's it.

FizzPow

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
    • FizzPow Games
Re: Sprite Edges
« Reply #6 on: December 15, 2012, 04:07:18 PM »
I think you misunderstand the problem, this is happening on all edges of sprites, not just the "box" edges next to other sprites.  This happens when its the only sprite on the atlas.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sprite Edges
« Reply #7 on: December 15, 2012, 04:10:23 PM »
Empty space in the atlas = black color, same thing. Try what I suggested -- leave at single pixel border around your sprite in Photoshop. Save it, re-add it to your atlas with "trim alpha" turned off.

FizzPow

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
    • FizzPow Games
Re: Sprite Edges
« Reply #8 on: December 15, 2012, 04:26:34 PM »
I tried that and it made no difference.  There is plenty of alpha around the edges in my clouds for example.

Here's a video I took of animating one of my clouds against something bright, you can see the edges flickering on/off:
https://dl.dropbox.com/u/5111228/ngui-edges/ngui-edges/ngui-edges.html


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sprite Edges
« Reply #9 on: December 15, 2012, 04:29:09 PM »
The alpha around the inner part of the sprite is a completely different issue altogether. You need to use Solidify A filter by Flaming Pear on your image before exporting it in Photoshop. Search this forum for "Solidify" more information.

FizzPow

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
    • FizzPow Games
Re: Sprite Edges
« Reply #10 on: December 15, 2012, 04:54:23 PM »
Ahhh yes, that does indeed fix the issue, thanks!  I am very glad to have a solution, but you may want to investigate how 2D Toolkit is handling this, because this adds another step to our process that would be nice to avoid.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sprite Edges
« Reply #11 on: December 15, 2012, 05:05:32 PM »
The code on how to do it is inside NGUI, but is commented out for now. :)

FizzPow

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
    • FizzPow Games
Re: Sprite Edges
« Reply #12 on: December 15, 2012, 06:08:23 PM »
You mention using Solidify A, but another post I read here:
http://answers.unity3d.com/questions/10302/messy-alpha-problem-white-around-edges.html

says to use Solidify B. Do you know what is best?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sprite Edges
« Reply #13 on: December 15, 2012, 11:11:10 PM »
Probably either one works. I used A.

FizzPow

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
    • FizzPow Games
Re: Sprite Edges
« Reply #14 on: December 15, 2012, 11:13:13 PM »
Yeah both work, I think B might be better since its targeted at the edges, but not sure without doing some more comparisons.

As for the commented code, is that something you plan to continue with at some point?