Archive for PixelBender

How to use custom Shaders in Astro(Flash 10)

Here is a simple example using the sample exposure shader that comes with the Adobe’s PixelBender tutorial.


(Moving the mouse from horizontally will change the exposure value)

Firstly, you need the PixelBenderToolkit(http://labs.adobe.com/wiki/index.php/Pixel_Bender_Toolkit).

I used the Exposure sample code from Adobe’s Pixel Bender tutorial (http://labs.adobe.com/wiki/index.php/Pixel_Bender_Toolkit:Tutorial)

<languageversion>
  kernel NewFilter
  <  namespace : “your namespace”;
    vendor : “your vendor”;
    version : 1;
    description : “your description”;
  >
  {
    input image4 src;
    output pixel4 dst;
    parameter float exposure
    <
      minValue:float(-0.5);
      maxValue:float(0.5);
      defaultValue:float(0.0);
    >;
    void
    evaluatePixel()
    {
      float4 inputColor = sampleNearest(src, outCoord());
      dst.rgb = pow(inputColor.rgb, float3(1.0 - exposure));
      dst.a = inputColor.a;
    }
  }

On PixelBender Toolkit, you can export it as Byte Code Filter for Flash from the File menu.

Exporting it, you will have a .pbj file to be loaded as ByteArray from Flash just like this.

var urlLoader:URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader.addEventListener(Event.COMPLETE, urlLoaderComplete);
urlLoader.load(new URLRequest(“exposure.pbj”));

And after that, creating a Shader instance, and also the ShaderFilter to be applied on a DisplayObject.

private function urlLoaderComplete(ev:Event):void
{
  shader = new Shader(ev.currentTarget.data as ByteArray);
  shaderFilter = new ShaderFilter(shader);
  filters = [shaderFilter];
}

Once you have the shader instance, you can change the shader parameters by doing the following.

shader.data.exposure.value = [0.5];

filters = [shaderFilter]; //re-applying the filter
 

Easy huh?

Here is all the source from this little tutorial.

Enjoy.

(update. Just because Zeh said to)


One more example using the TwirlFilter created by Elba Sobrino.
Works the same way, move the mouse along the image.

Comments (3)