5 Replies Latest reply on Feb 8, 2011 11:38 AM by unique_screenname_here

    simple blur filter works on gpu/cpu but not flash

    Dave Wolfe Level 1

      I'm trying to make a new blend mode for Flash that will blur the pixels behind the source image.  The filter works correctly when testing with the cpu and gpu, but in Flash the blur effect does not work, it simply crossfades the source image  and background image.  Can anyone explain why this won't work in Flash?

       

       

       

      Here is the code for the blend mode:

      <languageVersion : 1.0;>
      
      kernel NewFilter
      <   namespace : "dave";
          vendor : "dave";
          version : 1;
          description : "Blurs pixels behind the source image.";
      >
      {
          parameter float percent 
          <   
              minValue:       0.0;
              maxValue:       1.0;
              defaultValue:   0.25;
          >;
      
          input image4 src;
          input image4 bg;
          output pixel4 dst;
      
          void
          evaluatePixel()
          {
              float2 coord = outCoord();
              pixel4 px = sampleNearest(src, coord);
              float4 ox = float4(0.0, 0.0, 0.0, 0.0);
              float denom = 0.0;
              float2 sp = pixelSize(bg);
              
              // grab 48 surrounding pixels from bg and average them.  Pixel #24 in follwing matrix is coord location.
              //     00 01 02 03 04 05 06
              //     07 08 09 10 11 12 13
              //     14 15 16 17 18 19 20
              //     21 22 23 24 25 26 27
              //     28 29 30 31 32 33 34
              //     35 36 37 38 39 40 41
              //     42 43 44 45 46 47 48
              
              // 00
              ox += sampleNearest(bg, coord + float2(-sp.x * 3.0, -sp.y * 3.0));
              denom++;
              // 01
              ox += sampleNearest(bg, coord + float2(-sp.x * 2.0, -sp.y * 3.0));
              denom++;
              // 02
              ox += sampleNearest(bg, coord + float2(-sp.x, -sp.y * 3.0));
              denom++;
              // 03
              ox += sampleNearest(bg, coord + float2(0.0, -sp.y * 3.0));
              denom++;
              // 04
              ox += sampleNearest(bg, coord + float2(sp.x, -sp.y * 3.0));
              denom++;
              // 05
              ox += sampleNearest(bg, coord + float2(sp.x * 2.0, -sp.y * 3.0));
              denom++;
              // 06
              ox += sampleNearest(bg, coord + float2(sp.x * 3.0, -sp.y * 3.0));
              denom++;
              
              
              // 07
              ox += sampleNearest(bg, coord + float2(-sp.x * 3.0, -sp.y * 2.0));
              denom++;
              // 08
              ox += sampleNearest(bg, coord + float2(-sp.x * 2.0, -sp.y * 2.0));
              denom++;
              // 09
              ox += sampleNearest(bg, coord + float2(-sp.x, -sp.y * 2.0));
              denom++;
              // 10
              ox += sampleNearest(bg, coord + float2(0.0, -sp.y * 2.0));
              denom++;
              // 11
              ox += sampleNearest(bg, coord + float2(sp.x, -sp.y * 2.0));
              denom++;
              // 12
              ox += sampleNearest(bg, coord + float2(sp.x * 2.0, -sp.y * 2.0));
              denom++;
              // 13
              ox += sampleNearest(bg, coord + float2(sp.x * 3.0, -sp.y * 2.0));
              denom++;
              
             
              // 14
              ox += sampleNearest(bg, coord + float2(-sp.x * 3.0, -sp.y));
              denom++;
              // 15
              ox += sampleNearest(bg, coord + float2(-sp.x * 2.0, -sp.y));
              denom++;
              // 16
              ox += sampleNearest(bg, coord + float2(-sp.x, -sp.y));
              denom++;
              // 17
              ox += sampleNearest(bg, coord + float2(0.0, -sp.y));
              denom++;
              // 18
              ox += sampleNearest(bg, coord + float2(sp.x, -sp.y));
              denom++;
              // 19
              ox += sampleNearest(bg, coord + float2(sp.x * 2.0, -sp.y));
              denom++;
              // 20
              ox += sampleNearest(bg, coord + float2(sp.x * 3.0, -sp.y));
              denom++;
             
              // 21
              ox += sampleNearest(bg, coord + float2(-sp.x * 3.0, 0.0));
              denom++;
              // 22
              ox += sampleNearest(bg, coord + float2(-sp.x * 2.0, 0.0));
              denom++;
              // 23
              ox += sampleNearest(bg, coord + float2(-sp.x, 0.0));
              denom++;
              // 24
              ox += sampleNearest(bg, coord);
              denom++;
              // 25
              ox += sampleNearest(bg, coord + float2(sp.x, 0.0));
              denom++;
              // 26
              ox += sampleNearest(bg, coord + float2(sp.x * 2.0, 0.0));
              denom++;
              // 27
              ox += sampleNearest(bg, coord + float2(sp.x * 3.0 ,0.0));
              denom++;
              
              
              // 28
              ox += sampleNearest(bg, coord + float2(-sp.x * 3.0, sp.y));
              denom++;
              // 29
              ox += sampleNearest(bg, coord + float2(-sp.x * 2.0, sp.y));
              denom++;
              // 30
              ox += sampleNearest(bg, coord + float2(-sp.x, sp.y));
              denom++;
              // 31
              ox += sampleNearest(bg, coord + float2(0.0, sp.y));
              denom++;
              // 32
              ox += sampleNearest(bg, coord + float2(sp.x, sp.y));
              denom++;
              // 33
              ox += sampleNearest(bg, coord + float2(sp.x * 2.0, sp.y));
              denom++;
              // 34
              ox += sampleNearest(bg, coord + float2(sp.x * 3.0, sp.y));
              denom++;
              
              
              // 35
              ox += sampleNearest(bg, coord + float2(-sp.x * 3.0, sp.y * 2.0));
              denom++;
              // 36
              ox += sampleNearest(bg, coord + float2(-sp.x * 2.0, sp.y * 2.0));
              denom++;
              // 37
              ox += sampleNearest(bg, coord + float2(-sp.x, sp.y * 2.0));
              denom++;
              // 38
              ox += sampleNearest(bg, coord + float2(0.0, sp.y * 2.0));
              denom++;
              // 39
              ox += sampleNearest(bg, coord + float2(sp.x, sp.y * 2.0));
              denom++;
              // 40
              ox += sampleNearest(bg, coord + float2(sp.x * 2.0, sp.y * 2.0));
              denom++;
              // 41
              ox += sampleNearest(bg, coord + float2(sp.x * 3.0, sp.y * 2.0));
              denom++;
              
              
              // 42
              ox += sampleNearest(bg, coord + float2(-sp.x * 3.0, sp.y * 3.0));
              denom++;
              // 43
              ox += sampleNearest(bg, coord + float2(-sp.x * 2.0, sp.y * 3.0));
              denom++;
              // 44
              ox += sampleNearest(bg, coord + float2(-sp.x, sp.y * 3.0));
              denom++;
              // 45
              ox += sampleNearest(bg, coord + float2(0.0, sp.y * 3.0));
              denom++;
              // 46
              ox += sampleNearest(bg, coord + float2(sp.x, sp.y * 3.0));
              denom++;
              // 47
              ox += sampleNearest(bg, coord + float2(sp.x * 2.0, sp.y * 3.0));
              denom++;
              // 48
              ox += sampleNearest(bg, coord + float2(sp.x * 3.0, sp.y * 3.0));
              denom++;
              
              
              ox = ox/denom;
              
              dst = mix(px, ox, percent);
          }
      }