Hello Guest

Author Topic: Blurry Texture with Premultiplied Alpha Texture  (Read 9308 times)

MetalGreg

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
Blurry Texture with Premultiplied Alpha Texture
« on: May 20, 2012, 03:29:29 pm »
Hello, 2D ToolKit is an awesome addon to Unity, great work !

I had some alpha transparency troubles at the bounds of some of my sprites, so i decided to go for a premultiplied alpha atlas, wich saves me a lot of time rather than playing with Photoshop export for hours.

It works great in 960*640, however i noticed that my sprites get blurry in 480*320.
It seem sprites need specific sprite positioning sometimes its depending on where they are on the screen, to not get blurry.

For example:
  • My Sprite_A(1) at X200 Y200 is blurry.
  • My Sprite_A(2)  at X200.7f Y200.7f  is ok.
  • Somewhere else on the screen you could get the opposite result.

It also does the same inside and outside of the tk2d camera.

Do you know how i can prevent that to happen ?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Blurry Texture with Premultiplied Alpha Texture
« Reply #1 on: May 20, 2012, 03:53:22 pm »
Do you 1/2 the size of sprites in 480x320? (Using the resolution override thing?)

MetalGreg

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Blurry Texture with Premultiplied Alpha Texture
« Reply #2 on: May 20, 2012, 04:01:49 pm »
Yes, and i use to stay in the tk2dCamera.
Quote
[Resolution Overide]
Size: 1
     Element 0
     X: 480
     Y: 320
     Scale: 0.5

MetalGreg

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Blurry Texture with Premultiplied Alpha Texture
« Reply #3 on: May 20, 2012, 04:21:59 pm »
Updates:
  • Sprite width and height are made of even numbers.
  • Quality Setting is set to maximum and the result is the same, even when i build and run the game
  • This result is actually the same with non premultiplied alpha textures
  • I usually set my altla is set to [overide Standalone] -2048 -TrueColor to avoid artefacts
  • Figured out that my sprites get blury when position.x or position.y are even numbers.
    So in this case i shall use intergers odds numbers to position my sprites, to get them pixel perfect
  • This actually depend on the sprite size, but there is definitly something with positioning with evens and odds numbers
« Last Edit: May 20, 2012, 06:21:07 pm by MetalGreg »

MetalGreg

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Blurry Texture with Premultiplied Alpha Texture
« Reply #4 on: May 20, 2012, 06:44:29 pm »
I just figured out my lake of logic on this little "problem"  ; )
« Last Edit: May 20, 2012, 10:12:12 pm by MetalGreg »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Blurry Texture with Premultiplied Alpha Texture
« Reply #5 on: May 21, 2012, 12:17:19 am »
Sorry I must've missed your other posts to this thread. Glad you managed to figure it out.

The reason it has something to do with even / odd numbers is this:
When at full resolution, each full world position = 1 pixel, everything positioned on a round world unit draws correctly.

When at half resolution, each full world position = 0.5 pixel, so everything which is positioned on an odd number will be positioned at a 0.5 pixel boundary, i.e. will appear blurry.


MetalGreg

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Blurry Texture with Premultiplied Alpha Texture
« Reply #6 on: May 22, 2012, 05:42:54 pm »
Could you tell us more about Premultiplied Alpha atlas ?

What is it designed for ? When to use it ?

What would be the difference regarding performance on the iPhone?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Blurry Texture with Premultiplied Alpha Texture
« Reply #7 on: May 22, 2012, 05:49:43 pm »
Could you tell us more about Premultiplied Alpha atlas ?

What is it designed for ? When to use it ?

What would be the difference regarding performance on the iPhone?

Here is a good article about premultiplied alpha
http://blogs.msdn.com/b/shawnhar/archive/2009/11/06/premultiplied-alpha.aspx

One thing it conveniently works around is artefacts from upscaling badly alpha-ed images. The color channel in an alpha cutout image should be dilated, otherwise you white / black bleeding in, and premultipled alpha gets rid of a lot of these artefacts.

Anther bonus is the ability to do alpha blend + additive in the same draw call. 2D Toolkit lets you tag a sprite as being additive in the editor when premultiplied alpha is enabled.

The article doesn't go through the downsides to it - the main downside being reduced color precision in blended regions. In most cases, it really doesn't make any visible difference. It will if you have a lot of semi-transparent areas in your images, so take care when using it in that kind of scenario.

There is no performance difference on iPhone.