BendPixels: use PixelBender filters as Flex Effects

October 19, 2008

This was *brand new runtimes* week in RIA land, Silverlight 2 released on Tuesday, Flash Player 10 released on Wednesday. And, now that FP10 is out, I’m guessing a new version of AIR that embeds it should not be very far along.

One of my favorite new features in Flash Player 10 is the ability to use PixelBender to create filters that can be applied to objects inside of Flash Player. As I was watching Lee Brimelow’s very helpful PixelBender tutorials I thought it would be cool to use these filters as Flex Effects. So I wrote a custom Flex effect called BendPixels, this effect can be used with a PixelBender filter to animate properties of the filter and very quickly the whole thing turned into library of Flex effects. I’m releasing the BendPixels effect along with many specialized effects as an open source library on Google Code


BendPixels Example

The base BendPixels effect can be used as follows:

<effects :BendPixels 
	benderFileURL="[URL of .pbj file]"
	benderParams="[
			['property1',startValue1, endValue1],
			['property2',startValue2, endValue2],
			['property3',startValue3, endValue3],
 
		      ]"
	/>
  • benderFileURL is the url of the PixelBender binary (.pbj)
  • benderParams is a multi-dimentional array which contains arrays of type [propertyname, startval, endval]

The above syntax loads the pbj at runtime, that’s not the best approach if the pbj file is bigger than a few kb, in that case it would be best to embed the filter binary into the swf and use the benderByteArray property of the effect

[Embed("filter.pbj", mimeType="application/octet-stream")]
private var Filter:Class;
 
...
 
 
<effects :BendPixels 
	benderFileURL="{new Filter() as ByteArray}"
	benderParams="[
			['property1',startValue1, endValue1],
			['property2',startValue2, endValue2],
			['property3',startValue3, endValue3],
 
		      ]"
	/>

Some PixelBender input properties can be of type float2, float3, float4 etc. which means that they require an array as input, in which case you can use arrays to specify start and end values.

<effects :BendPixels 
	benderFileURL="[URL of .pbj file]"
	benderParams="[
			['property1',[s1,s2], [e1,e2]],
			['property2',startValue2, endValue2],
			['property3',startValue3, endValue3],
 
		      ]"
	/>

While the general BendPixels effect is great, the benderParams property is a little verbose, so I thought it would be better to have specialized effects for various commonly used filters .. I’ve implemented effects for some of the filters freely available on Adobe’s PixelBender Exchange

The library currently includes:

* SmudgeEffect based on Frank Reitberger’s Smudge Filter
* TintEffect based on Allen Chou’s Tint Filter
* SliceEffect based on Frank Reitberger’s Slicer Filter
* RippleBlocksEffect based on Allen Chou’s RippleBlocks Filter
* ColorQuantizationEffect based on Eduardo Costa Color Quantization Filter

Thank you to all these people for open sourcing their filters. Check out this example to see what the effects look like.

All these specialized effects and even the BendPixels effect can be used just like other flex effects, they can have a target, can be played with play method, can be used in state transitions, can have easing functions etc.

	<smudge :SmudgeEffect id="smudgerEffect" 
		fromAmount="0" toAmount="1" 
		duration="1000"/>
 
	<tint :TintEffect id="bwTintEffect"
		fromAmount="0" toAmount="1" 
		duration="1000"/>	
 
	<tint :TintEffect id="blueTintEffect"
		fromAmount="0" toAmount="1" 
		fromBlue="0" toBlue="0.5"
		duration="1000"/>	
 
	<rippleblocks :RippleBlocksEffect id="rbEffect"
		fromXAmplitude="0" toXAmplitude="100"
		fromYAmplitude="0" toYAmplitude="100"
		duration="1000"/>
 
	<!-- Note: this uses an easing function -->	
	<colorquantization :ColorQuantizationEffect id="cqEffect"
		fromPalette="64" toPalette="3"
		duration="1000" easingFunction="{Exponential.easeOut}"/>
 
	<slice :SliceEffect id="sliceEffect"
		fromAmount="0" toAmount="20"
		duration="1000"/>

It is very easy to extend the BendPixels class and add your own specialized effects, I will write another post on how to do that, meanwhile check out the library and let me know if you have any feedback. Also, If you have any thoughts on how the library can be improved, I would love to know.


 
Update: released a new version that adds ZoomBlurEffect based on Ryan Phelan’s zoomBlur filter .. check it out
 


12 Responses - What do you think?

  1. I like it !
    Thanks for sharing, I will use that on my new website…

  2. Could these effects be applied directly to actual Flex widgets such as a Panel, Buttons, etc?

  3. @Jay Yes these effects are just like any other flex effect and can be applied to any Flex Component, I’ve just used an mx:Image as an example.

  4. retweet @mrinalwadhwa: @pixelbender I made a little lib to use PixelBender filters as Flex Effects .. check it out.. http://bit.ly/23UiJ7

  5. pixel bender filters in flex: http://bit.ly/23UiJ7 Any news on whether this is coming to Peacock?

  6. Quite cool – thanks for sharing
    However i do not think we can use this in our application (financial flex application) Instead we are looking at possibilities to use Pixel bender as a calculator for mathematical calculations like adding a cubic-spline on top of a chart or the like.

    http://www.softcapital.com/labs/demo/radarlite.html

  7. @Lars glad you like it

    >> However i do not think we can use this in our application (financial flex application)
    Why’s that? do you see any technical limitation .. or you just don’t want to use effects and transitions?

    >> Instead we are looking at possibilities to use Pixel bender as a calculator for mathematical calculations
    I’ve been thinking about that too .. heavy calculations in the Pixelbender kernel can give a good performance boost.

  8. is there a way to create a cylinder with a jpg asset?
    is it easy?
    thanks

  9. [...] > BendPixels: use PixelBender filters as Flex Effects | Rags to Riches [...]

  10. [...] » BendPixels: use PixelBender filters as Flex Effects | Rags to Riches – [...]

  11. Sonny Naqvi
    April 19th, 2009

    Hi, I am getting the following error. Can you please help
    1046: Type was not found or was not a compile-time constant: Shader.

  12. Sonny,

    Are you using Flash Player 10? … Shaders are only available in FP10 … so bendpixels requires it.

    Mrinal

Your thoughts or questions: