Using The Pixel Bender Filters in Actionscript 3.0
The best thing about Pixel Bender filters is soon we will have more amazing effects. I am not a person which is has a great background of math and I never work with image processing or with C. But the great part of Pixel Bender is you can use filters which is been created from someone else. This is similar like using classes in action script. Someone wrote good class and opens for public and everybody is using. So even if you are not the one who wrote filter still is good to know how to use them.
In this article I will explain how to use Pixel Bender Filters in Flash Player. Well probably you know that Pixel Bender filters can be use in Flash and After Effects. But if you want to use in flash you have to export the Pixel Bender file for flash. For exporting .pbj file you have to select “Export Kernel Filter For Flash Player” in File menu. I assume you all ready did that and I am passing the code which will be use in Flash.
How To Use Filter
As filters are out of flash for using them first of all we have to load them in flash. For loading .pbj file in flash we are going to use URLLoader class. First we will create new URLLoader object. Then with load method we will add name of file that we want to load. As our file is coded in ByteCode we have to set URLLoaderDataFormat as BINARY. And of course we have to add the event listener for getting information of file is loaded or not. So the code will look like this;
loader.load(new URLRequest("MyTestFilter.pbj"));
loader.dataFormat=URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, filterLoaded);
We also need a Shader and ShaderFilter object. Shader object reperesent the data which will load. We can say this is presenting the code which been wrote in Pixel Bender. And ShaderFilter is a class that will help us to use in Flash.
var shaderFilter:ShaderFilter;
Now we can write out event listener function. In function first we will get the data which been load. Second we pass that data to ShaderFilter, and last thing we have to do is assign filter to dispaly object we have.
shader = new Shader(loader.data);
shaderFilter = new ShaderFilter(shader);
image_mc.filters = [shaderFilter];
}
PS:If you want to know more about how to use Bitmap filters you check the link at below;
http://enginyoyen.com/blog/eng/index.php/using-filters-with-actionscript-30/
Using the Filter Parameters
I have mentioned it before, that can be parameters in Filters. Those parameters usually decide amount of effect which will apply to display object. The filter I made as an example has one parameter. For manipulating this parameter we have to use data property of shader object. I will use a slider component to change the value of the parameter and we will see the effect at real time. At below you can the amount value which is type of array. The float type in Pixel Bender is carrying more than one value as we are not using the float type in Action script 3 for solution we are using arrays to balance the value. Even when you are entering single value still you have to assign value as array. And we are assigning the filter again because we want to see the difference at real time;
function changeAmount(e:SliderEvent) {
shader.data.amount.value = [e.target.value];
image_mc.filters = [shaderFilter];
}
Examle Image
At below is a result of diffrent amount of effect. You can download source files and chek it out to
![]()
Source Files
For using the source files over here you need to have the Flash CS4 and Pixel Bender on your computer.
http://enginyoyen.com/blog/eng/wp-content/uploads/2008/11/howtousepixelbenderfilter.rar
Up Shot
This is the basic of how you can use Pixel Bender Filters in Actionscript 3.0. Of course still you can reach all type of information about a filter but I will cover that some other time.
Take Care
Engin!
One Response to “Using The Pixel Bender Filters in Actionscript 3.0”
Leave a Reply


[...] > Engin Yöyen - Stay Updated On Web » Using The Pixel Bender Filters in Actionscript 3.0 [...]