Posted by: Dennis | March 30, 2010

PixelBender and arrays

Greetings all!

It’s been a while…

This post is dedicated to those who seek a solution for passing arrays to a pixel bender shader and use it in Flash Player.

Since you are here, I suppose you know that, and I quote – ” When Pixel Bender is used in Flash Player, arrays are not available”. This made me very sad when I faced the problem for the first time.  I found a quick solution which worked like a charm for me and may be it will save the day for you too.

The idea is to convert the array to a grayscale M px * 1 px  image (M px  * N px for 2 dimensional arrays). For that you’ll need to map the array to [0, 255] interval, by finding the max and then dividing all elements by that value. Generate a BitmapData object out of that and use it as a secondary input for your pixelbender shader.

The intensity of the color at position (x, 1) is your array element at position x. Obviously it will be in interval [0.0 , 1.0] so you will need to multiply by something (like the already known max; or ‘255’ if you are working with color).

I successfully used this method to create several image processing operations like levels, curves, tone mapping and other LUT-based stuff.

I hope it makes sense to some of you. If I’m not too lazy I’ll post a sample project later.

Dennis

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: