Hi all,
I have a 2D engine in WebGL which is doing blending / compositing when drawing some shapes on top of each other. To get rid of common problems it is working with premultiplied colors, and the matching ONE source blend mode instead of SRC_ALPHA.
The canvas itself is not composited with the dom, there is always a solid background color rendered first, but I also want to export the content of the canvas without the background into a PNG file, calling readPixels and some custom code to encode into a PNG. I realized that if there are semi-transparent pixels I'm getting the typical black "fringe" around objects which I think is because the pixels returned by readPixels are in premultiplied form and PNG expects them to be in straight alpha.
One solution is to run one more render pass on the final Framebuffer which unpremultiplies pixels (divides rgb by the alpha). Is this a good way of dealing with this problem or is there anything better I could do?
I can't really modify the rendering to work in straight alpha colors because that would mess up blending.
thanks,
Andrew