3 Replies Latest reply on Oct 6, 2010 3:52 PM by Kevin Goldsmith

    PB Displacement filter really slow with big images

    am0ose

      hello;

           I am trying to make a Pixel bender displacement filter that will handle displacements bigger than 128 pixels, for flash. Right now flash only uses one 8 bit color channel to represent a displacement,  which can not be bigger than 128 pixels. I am trying to make a pixel bender kernel that will take 3 color channels( 24 bit) as a displacement, which should be able to handle displacements as big as 8388608. That is obviously bigger than I need.

           The problem i am finding is that when the image or the displacement maps are too big it runs really slow. With images the size 3072x768,  it runs at 3 frames per second on an intel based mac.

           The question is , does anybody know how to optimise this code?

       

      the code:

       

      <languageVersion : 1.0;>

       

      kernel DisplacementMap

      <

      namespace : "dood";

      vendor : "m0ose";

      version : 1;

      description : "Displacement by bitmap map 16 bit. X and Y are seperate bitmaps  ";

      >

      {

       

      parameter   float       scale

          <

              minValue        : -10.0;

              maxValue        :  10.0;

              defaultValue    :  1.0;

          >;

      parameter float offsetX

          <

              minValue        : -1000.0;

              maxValue        :  1000.0;

              defaultValue    : 0.0;

          >;

      parameter float offsetY

          <

                  minValue        : -1000.0;

              maxValue        :  1000.0;

              defaultValue    : 0.0;

          >;

      parameter float zoom

          <

                  minValue        : 0.1;

              maxValue        :  10.0;

              defaultValue    : 1.0;

          >;

       

      input image4 src;

      input image4 mapX;

      input image4 mapY;

       

      output pixel4 dst;

       

       

      void evaluatePixel()

      {

          float2 pos = outCoord();

          float4 amountX = sampleLinear(mapX , pos);

          float4 amountY = sampleLinear(mapY , pos);

       

       

          float x = (amountX.b * 256.0 - 128.0) ; //red

          x = x + (amountX.g * 256.0 - 128.0) * 128.0;//alpha

          x = x * scale;

          x = x + pos.x;

          x = x + offsetX ;

          x = x / zoom;

          float y =  (amountY.b * 256.0 - 128.0) ;

          y = y + (amountY.g * 256.0 - 128.0) * 128.0;

          y = y * scale;

          y = y + pos.y;

          y = y + offsetY ;

          y = y / zoom;

          float2 displacedPos = float2( x , y );

       

          dst = sampleLinear(src, displacedPos);

      }

      }

       

      thanx

        • 1. Re: PB Displacement filter really slow with big images
          Kevin Goldsmith Level 3

          the samples are the most expensive thing I'm seeing, but shouldn't be the problem too much. How are you invoking this from  Actionscript?

          • 2. Re: PB Displacement filter really slow with big images
            am0ose Level 1

            I am adding a shader to the filter attribute of a Flex Video Player

             

            code: something like this

             

             

            [Embed(source="displ24test.pbj" , mimeType="application/octet-stream")]

            protected var displacer:Class;

             

            var shader:Shader;

             

            public function init():void

            {

            shader = new Shader( new displacer() );

             

            shader.data.src.input = src;

            shader.data.mapX.input = mapX;

            shader.data.mapY.input = mapY;

            shader.data.scale.value = [ scale ];

            shader.data.offsetX.value = [ offsetX ];

            shader.data.offsetY.value = [ offsetY ];

            shader.data.zoom.value = [ zoom];

             

            _mov.filters = [ new ShaderFilter( shader) ];

            }

             

            then in flex:

             

            <s:VideoPlayer x="10" y="10" source="df_retro5_1k_sound.mov"  id="_mov"  autoPlay="true"/>

             

             

            • 3. Re: PB Displacement filter really slow with big images
              Kevin Goldsmith Level 3

              Off the top of my head, I'm not seeing anything obvious. I'd need to try a few iterations to see what the bottleneck is. One suggestion would be to replace your current shader with an identity and see what your performance is then. That will tell you how much of your time is spent marshalling data in and out of Pixel Bender. Then I would do the shader that took only one other image as input. Hopefully that may help you figure out where your performance is going.