I'm using Starling 1.6 on a client project.
I'm trying to accomplish an effect where every frame, I display the previous frame but blurred some. Basically I don't want to clear the texture every frame, I want to keep the stuff from last frame, alter the stuff from last frame somewhat (maybe a little blur, maybe fade out a bit), and add new stuff.
I'm using two render textures, and every frame I do the following (RTA is where I draw stuff, RTB is a secondary helper object):
- clear RTB
- attach RTA to an image with a
- draw helper image to RTB
- clear RTA
- attach RTB to helper image with no filter
- draw helper image to RTA
Only problem is, I'm getting black at the edges of the objects which suggests to me that I've got some PMA/nonPMA errors. I found an article (http://www.jhlabs.com/ip/blurring.html), which has some helpful text that describes my problem, but I'm not sure how to do it in Starling:
Imagine you want to blur a shape which is on a transparent background. You've got an empty image, and you draw a shape on it, then blur the image. Hang on - why does the blurry bit look too dark? The reason is that we've blurred each channel separately, but where the alpha channel is zero (the transparent bits), the red, green and blue channels are zero, or black. When you do the blur, the black gets mixed in with the opaque bits and you get a dark shadow. The solution is to premultiply the image alpha before blurring and unpremultiply it afterwards. Of course, if your images are already premultiplied, you're all set.
I've tried different blendModes on the helper image, I've tried defining my own blend mode, I've tried modifying everything I can think of, but I fear that I'm missing something obvious and just not wrapping my head around what's happening at a low level so I'm changing things in the dark. Been wrestling with this for several days now.
Can anyone help? I'd be most appreciative (and my client would as well 🙂 )
Here's some screenshots that were taken at different times. I'm adding a solid-colored square Quad every so often and running the blur every frame.