This confused me as well when I did my first blend mode experiments in Flash. I had to ask Tinic eventually because I was seeing the same behaviour. The answer is that in Flash when you use Pixel Bender as a blend mode, the coordinate input to the sample calls is always outCoord(), no matter what you specify. The reason for this is that if we were doing a convolution (sampling different input pixels), we wouldn't be a blend, we'd be a filter.
It's a bit of an unsatisfying answer, but if you think about it, it makes sense I hope.
Thank you, it's a bit confusing but makes sense.
I guess redrawing a movieclip on a bitmapData and using it as a filter will do the work.
Hi. I noticed the same behavior while working on a filter. Glad to see that I wasn't just going crazy.
However, this design seems to have its limitations. For example, I was hoping to create a blend mode in which the background is blurred in areas in which the foreground is semi-transparent--sort of like how Windows Vista Aero displays windows. I have this up and running in the toolkit, but of course it fails in Flash since sampleNearest doesn't behave as expected. Are these kinds of filters possible using some workaround? Or is there an obvious solution that I'm not seeing?
And on a more general note, is the behavior of Pixel Bender in Flash going to be moving closer to the behavior in the Toolkit in future updates to the Flash player (not to mention the question of GPU support)? There seem to be a pretty significant number of differences as of right now (no loops, no functions beyond evaluatePixel, this unexpected sampleNearest behavior, etc.). Probably I won't be able to get a definitive answer to that last question, but no harm in asking right? :)
Thanks for all the assistance!
You can always get around the limitation by using the ShaderJob object directly with the two objects as inputs instead of applying a blend mode. This is going to require some more work to setup, but it definitely doesn't have the same limitation with the sampling.
I designed a shader that warps the source image in order to create, specifically, a magnifying glass effect. I have several items (movieclips) on the stage and want to warp all of them. The ideal way for this to work is to take everything that has already been rendered and apply my distortion filter. However this behavior by flash is preventing my shader from working correctly. It works great in Pixel Bender with two image sources.
I noticed two things when the shader as blendmode.
1) sampleNearest() always use (what should be) outCoord(), but
2) outCoord() always returns zero (0,0).
After reading this post, I now understand that the purpose of a Blend Mode shader is to perform a "straight down" effect on the pixels.
To accomplish my magnifying glass effect, I placed all my items in a movie clip and then applied my shader as a filter to the top level movie clip, and it works great!
I know this is quite a delayed response to the original post, but I hope someone else will find this information helpful.
img-01.png 137.1 K
Wow. That blows (me away). It totally sucks (the usefulness out of pixel shaders in Flash).