0 Replies Latest reply on Sep 13, 2011 7:16 PM by EdAlive

    Alpha channel problem with Pixel Bender blendShaders

    EdAlive

      I'm using Pixel Blender to try and create a blend shader for a Flex 4.0 app.

      It looks like this:

       

      <languageVersion : 1.0;>
      kernel PixelReverse
      <   namespace : "com.abc.def.filters";
          vendor : "EdAlive";
          version : 1;
      >
      {
          input image4 foreground;
          input image4 background;
          output pixel4 dst;
        
          void
          evaluatePixel()
          {
              pixel4 fgPixel = sampleNearest(foreground, outCoord());
              pixel4 bgPixel = sampleNearest(background, outCoord());
              if((bgPixel.r == 0.0) && (bgPixel.g == 0.0) && (bgPixel.b == 0.0) && (bgPixel.a == 0.0)){
                  bgPixel.r = bgPixel.g = bgPixel.b = 1.0;
              }
              dst.r = 1.0 - abs(fgPixel.r - bgPixel.r);
              dst.g = 1.0 - abs(fgPixel.g - bgPixel.g);
              dst.b = 1.0 - abs(fgPixel.b - bgPixel.b);
              dst.a = fgPixel.a;
          }
      }

       

      It looks correct in the Pixel Bender preview window.

      When I use it in a Flex project with proper 32 bit png images, the filter seems to work correctly, except it sets any partial alpha value on the images to fully opaque (like a 1 bit alpha channel).

       

      Because the image preview looks correct in Pixel Bender, I'm assuming it's a problem with the bitmap data that Flex is passing to the blend shader filter.

       

      I tried changing the filter to simply output a copy of the foreground firstly, and the background second, to test.

      When returning a copy of the foreground, the imags weren't visible on stage, either because the pixels were transparent or because it was really returning the background pixels, camouflaging the images.

      When returning a copy of the background, the images were just black rectangles.

       

      The images are being place on stage programmatically inside an mx Module, and having their depth property set.

      They also have draggable behaviour, where the current drag object is layered above all else during the drag.

      I'm actually using a subclass of mx.controls.Image, but am simply setting the source property with preloaded bitmap data, so I'm am fairly sure the subclass is not a factor.

       

      I hope this is enough information for someone to be able to provide some help.

      Thanks