Archive for the 'Pixel Bender' Category

Inverted augmented reality with Pixel Bender

I had the idea that I wanted to do an augmented reality project that used a white rectangle on black instead of the usual black on white. After some discussion on Twitter it was clear that I needed to invert the BitmapData coming out of the camera before sending it to the FLARToolkit. Now there are many ways which you could do that but I decided to use a Pixel Bender filter just for the hell of it. It worked perfectly and it doesn’t seem to affect performance much at all.

You can download the full source which is just a modification of the code used in the gotoAndLearn tutorial on augmented reality. Once you go black, well you know the rest.

Lee

Pixel Bender is NOT hardware accelerated

After reading various tweets this morning coming out of the MIX09 conference I thought I needed to go on the record regarding Pixel Bender. The Pixel Bender toolkit runs filters using hardware acceleration. But Pixel Bender filters that are running inside of Flash Player 10 are not accelerated in any way and are instead rendered via software. This is a failure on our part for not communicating this clearly enough.

Lee

Pixel Bender basics on Adobe TV

Here is a video that I did a while back for Adobe TV. It walks you through how to create a simple Pixel Bender filter and then incorporate it into Flash CS4. Very similar to what I showed on gotoAndLearn but it’s still worth a look.

Lee

New tutorial on animating Pixel Bender

I just uploaded the new tutorial that shows how to animate Pixel Bender filters. I create a simple contrast filter an use it to transition between two images. I’m using GTween to do the actual animation. I like the structure and syntax of it but any tweening engine would work. This tutorial also demonstrates some of the Eclipse modifications I’ve been making like the snippets panel and the ability to test directly in Flash.

Lee

Second Pixel Bender tutorial is now live

I just uploaded the second part of the Pixel Bender tutorial. This time I show you how to export a Pixel Bender filter from the toolkit. Then I import the PBJ file into Flash and apply it to an image. I am compiling to Flash Player 10 using MXMLC which I described in detail in an earlier tutorial. This workflow will obviously be much easier once Flash CS4 is released. If you come up with some cool filters let us know in the comments! Check it out at http://www.gotoandlearn.com.

Lee

New video tutorial on using Pixel Bender

I just finished uploading a new tutorial that shows you the basics of getting started with Pixel Bender. This can be scary for people who don’t have a background in pixel shader programming (i.e. me). Over the last few days I have finally figured out enough to be able to record a tutorial on it. This is part 1 of 2 and it shows you how to create a couple of simple filters. Part 2 will show you how to export and load those filters into your Flash movies. Check it out at http://www.gotoandlearn.com.

Lee

My first Pixel Bender filter (SquarePattern)

Today I spent a few hours getting up to speed with Pixel Bender. It definitely has a steep learning curve but it is well worth the effort. Below you can check out my first creation called SquarePattern for lack of a better word. This filter essentially samples the current pixel as well as a different pixel and averages them out. Which pixel is dependent on the amount parameter. The result is a kind of crosshatch effect.

I was actually really excited earlier because I created a cool blur effect but I couldn’t export it to Flash because you can’t use for loops if the filter will be used in the player. Bummer! To do a blur, you essentially average a certain amount of pixels together. The number of pixels you average determines the strength of the blur. Oh well, I hope we add loops to Pixel Bender soon.

Click on the image below to see the filter in action. You must have Flash Player 10 RC installed to view it.

The Pixel Bender code is below. I will be doing a tutorial on this very soon so don’t worry if it looks scary.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<languageversion : 1.0;>

kernel QuadBlur
< namespace : "com.leebrimelow.filters";
    vendor : "Lee Brimelow";
    version : 1;
    description : "Creates a four-direction blur.";
>
{
    input image4 src;
    output pixel4 dst;
   
    parameter int amount
    < minValue:0;
        maxValue:100;
        defaultValue:0;
    >;

    void
    evaluatePixel()
    {
        pixel4 orig = sampleNearest(src, outCoord());
        float2 pos = outCoord();
        orig += sampleNearest(src, outCoord()-float2(cos(float(pos.x))*float(amount),0));
        orig += sampleNearest(src, outCoord()-float2(sin(float(pos.y))*float(amount),0));
        orig += sampleNearest(src, outCoord()-float2(0,cos(float(pos.x))*float(amount)));
        orig += sampleNearest(src, outCoord()-float2(0,sin(float(pos.y))*float(amount)));
       
        dst = orig/4.0;
    }
}</languageversion>

The ActionScript 3 code that I used to import the new shader is shown below. I left out the code for the throw slider as I’ve already shown that before.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
var l:URLLoader = new URLLoader();
l.dataFormat = URLLoaderDataFormat.BINARY;
l.addEventListener(Event.COMPLETE, onComplete);
l.load(new URLRequest("squarepattern.pbj"));
   
var shader:Shader;
var filter:ShaderFilter
   
function onComplete(e:Event):void
{
    shader = new Shader(l.data);
    filter = new ShaderFilter(shader);
    image.filters = [filter];
    addEventListener(Event.ENTER_FRAME, loop);
}

function onChange(p:Number):void
{
    p *= 50;
    shader.data.amount.value = [p, p, p];
    image.filters = [filter];
}

You can download the PBJ file if you want this odd effect in your Flash movies.

Lee

Next Page »