2D Toolkit Forum

2D Toolkit => Support => Topic started by: MetalGreg on May 20, 2012, 03:29:29 pm

Title: Blurry Texture with Premultiplied Alpha Texture
Post by: MetalGreg 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:

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

Do you know how i can prevent that to happen ?
Title: Re: Blurry Texture with Premultiplied Alpha Texture
Post by: unikronsoftware on May 20, 2012, 03:53:22 pm
Do you 1/2 the size of sprites in 480x320? (Using the resolution override thing?)
Title: Re: Blurry Texture with Premultiplied Alpha Texture
Post by: MetalGreg 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
Title: Re: Blurry Texture with Premultiplied Alpha Texture
Post by: MetalGreg on May 20, 2012, 04:21:59 pm
Updates:
Title: Re: Blurry Texture with Premultiplied Alpha Texture
Post by: MetalGreg on May 20, 2012, 06:44:29 pm
I just figured out my lake of logic on this little "problem"  ; )
Title: Re: Blurry Texture with Premultiplied Alpha Texture
Post by: unikronsoftware 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.

Title: Re: Blurry Texture with Premultiplied Alpha Texture
Post by: MetalGreg 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?
Title: Re: Blurry Texture with Premultiplied Alpha Texture
Post by: unikronsoftware 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.