Author Topic: Pixel gap / lines that appear at the edges of sprites  (Read 6747 times)

SlaynX

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Pixel gap / lines that appear at the edges of sprites
« on: February 18, 2014, 07:29:04 AM »
I have these weird pixel lines on certain edge of my sprites and this problem becomes more apparent when I tried to build the game into one of my PC. I tried the rest of my available PCs and it worked fine. The mac however has the same problem but not so apparent as the PC i mentioned earlier. The pixel gap/lines becomes worst if I zoom out. So I was wondering if this issue is due to platform to platform or due to different graphics card? Perhaps maybe I missing some setting in NGUI? I've attached the image of the game as well for reference purposes. The room walls are tiles sprite and the top money and fame bars are sliced sprites. The clouds also exhibit such a problem as well. Any ideas?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Pixel gap / lines that appear at the edges of sprites
« Reply #1 on: February 18, 2014, 10:23:44 AM »
When you scale a sprite, pixels from neighbouring sprites may show through on the edges. You can reduce the issue by increasing the padding on your atlas (in the Atlas Maker) when adding your sprites. Also, make sure that the atlas texture is set to "alpha is transparency".

SlaynX

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Pixel gap / lines that appear at the edges of sprites
« Reply #2 on: February 18, 2014, 11:27:14 PM »
I did what you suggested which is to change my atlas texture "alpha is transparency" option to true and it made matter rather worst. I'm also kinda lost on how to update the existing atlas padding as I don't see any update button or whats over option when I reference the existing atlas in the atlas maker. It doesn't seem change the padding even after I change the value. I've attached the result of the change and also the texture setting of my current atlas.

Agent_007

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 5
  • Posts: 27
    • View Profile
Re: Pixel gap / lines that appear at the edges of sprites
« Reply #3 on: February 19, 2014, 05:49:17 AM »
If you use texture compression, that will cause bleeding problems. And texture filtering mode is an another culprit.

There are few solutions.
* Use uncompressed 32 bit textures atlas with point filter mode for those sprites that cannot be smudged at all
* If you have to use another filter mode, then add safe zones to image (repeat same color) and adjust sprite dimensions (x, y, width, height) so the preview only shows "good" part

EDIT:

I also forgot that some change during NGUI 3.0.x changed the atlas thing, so you have to update all textures in atlas if they have transparency in them (assuming that you have update NGUI during your project). So select all of them from Unity and press Update in Atlas maker.
« Last Edit: February 19, 2014, 06:25:11 AM by Agent_007 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Pixel gap / lines that appear at the edges of sprites
« Reply #4 on: February 19, 2014, 12:45:03 PM »
To add to what Agent_007 said, if things start looking worse when you enable "alpha is transparency" then it means that you are using a Premultiply type shader, which is incompatible with the setting. When creating your atlas you have an option to use the premultiply setting. Once you set it, the atlas is "locked in". From all my performance testing there is no reason to use it anymore, which is why it's defaulted to being off. The performance gain from using premultiply shaders was < 1%.