6 Replies Latest reply on Apr 14, 2010 10:17 PM by Triynko

    Shader as Blendmode not working?

      When I made a blendmode (with the foreground and background image4 sources),
      I noted that no matters what coordinates I use on sampleNearest, the result on Pixel Bender differs from Flash.

      for example
      result = sampleNearest( background, outCoord()*2.0 );
      on Pixel Bender the return a "resized" background, but on flash for some reason I don't understand

      sampleNearest( background, outCoord()*2.0 ); is returning the value of sampleNearest( background, outCoord());

      or, another example

      result = sampleNearest (background, float2(0.0,0.0) );
      on Pixel Bender returns a solid color image (from pixel 0,0) , but on flash again, nothing happens.

      I did something wrong?
        • 1. Re: Shader as Blendmode not working?
          Kevin Goldsmith Level 3
          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.
          • 2. Re: Shader as Blendmode not working?
            PatricioFoieri Level 1
            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.

            • 3. Shader as Blendmode not working?
              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!
              • 4. Re: Shader as Blendmode not working?
                BrianRonan Level 1
                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.
                • 5. Re: Shader as Blendmode not working?

                  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.



                  • 6. Re: Shader as Blendmode not working?

                    Wow.  That blows (me away).  It totally sucks (the usefulness out of pixel shaders in Flash).