четверг, 9 августа 2012 г.

Stage3D and premultiplied alpha

Hi everyone. Today I want to tell about problem I met when used transparent image in Stage3D.

When I load a simple white circle - a strange artifact occur - ugly black outline.


What is this? Why? The answer is simple - when you save png image in flash or photoshop, the tool premultiplies color values by alpha. For example, we have white color with 50% transparency [1.0, 1.0, 1.0, 0.5]. The resulting color will be saved as [0.5, 0.5, 0.5, 0.5]. Next, Stage3d thinks that we use image with NO premultiplied color values. And it multiplies it again, resulting to final output color as [0.25, 0.25, 0.25, 0.5] - leading to dark color.

The simplest solution is to save images without premultiplying by alpha. But I dont't know such tool (it's lazy to google, huh). Another solution described here good tutorial.

So, in AGAL we have [0.5, 0.5, 0.5, 0.5] color. Next we divide each component by alpha to restore original color, i.e. [1.0, 1.0, 1.0, 0.5]. And finally API do it's work and we have good looking picture.


Комментариев нет:

Отправить комментарий