topical media & game development

talk show tell print

graphic-shader-zoomBlur.pbj / pbk



  <languageVersion : 1.0;>
  
  kernel ZoomBlur
  <   namespace : "com.rphelan";
      vendor : "Ryan Phelan";
      version : 1;
      description : "A simple implementation of zoom blur, using 15 levels of blur.";
  >
  {
      parameter float2 center
      <
          minValue:float2(0.0, 0.0);
          maxValue:float2(2048.0, 2048.0);
          defaultValue:float2(256.0, 256.0);
      >;
      
      parameter float amount
      <
          minValue:0.0;
          maxValue:0.5;
          defaultValue:0.05;
      >;
  
      input image4 src;
      output pixel4 dst;
  
      void
      evaluatePixel()
      {
          // Obtain the output pixel coordinate
          float2 coord = outCoord();
          
          // Offset by the center value
          coord -= center;
          
          float scale;
          dst = float4(0.0); 
          
          // This is an expanded for loop.
          // Loops are not currently supported in pixel bender.
          // For increased definition at the cost of performance,
          // simply add more levels.
          
          // Take 15 samples radiating out from the center and
          // add them to dst
          
          scale = 1.0;
          dst += sampleNearest( src, coord*scale + center );
          
          scale = 1.0 + amount * (1.0/14.0);
          dst += sampleNearest( src, coord*scale + center );
          
          scale = 1.0 + amount * (2.0/14.0);
          dst += sampleNearest( src, coord*scale + center );
          
          scale = 1.0 + amount * (3.0/14.0);
          dst += sampleNearest( src, coord*scale + center );
          
          scale = 1.0 + amount * (4.0/14.0);
          dst += sampleNearest( src, coord*scale + center );
          
          scale = 1.0 + amount * (5.0/14.0);
          dst += sampleNearest( src, coord*scale + center );
          
          scale = 1.0 + amount * (6.0/14.0);
          dst += sampleNearest( src, coord*scale + center );
          
          scale = 1.0 + amount * (7.0/14.0);
          dst += sampleNearest( src, coord*scale + center );
          
          scale = 1.0 + amount * (8.0/14.0);
          dst += sampleNearest( src, coord*scale + center );
          
          scale = 1.0 + amount * (9.0/14.0);
          dst += sampleNearest( src, coord*scale + center );
          
          scale = 1.0 + amount * (10.0/14.0);
          dst += sampleNearest( src, coord*scale + center );
          
          scale = 1.0 + amount * (11.0/14.0);
          dst += sampleNearest( src, coord*scale + center );
          
          scale = 1.0 + amount * (12.0/14.0);
          dst += sampleNearest( src, coord*scale + center );
          
          scale = 1.0 + amount * (13.0/14.0);
          dst += sampleNearest( src, coord*scale + center );
          
          scale = 1.0 + amount * (14.0/14.0);
          dst += sampleNearest( src, coord*scale + center );
          
          // Divide by 15 to get the average of the samples
          dst /= 15.0;
      }
  }
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.