May 2016
Mo Tu We Th Fr Sa Su
<< >>


Pixel Bender Assembler

Posted on Dec 04 2008

Pixel Bender is an Adobe technology that is now part of the Flash Player 10 API (where its named Shader).

A Pixel Bender script is capable of performing floating point calculus in parallel using available CPU instructions such as SIMD.

In short, it's a way to be able to crunch numbers very efficiently, and can also be used in Flash Player 10 to write pixel-shaders for custom blend modes, filters or graphics fill.

The Pixel Bender Toolkit is freely available and you can use it to experiment custom filters. It takes an PBK script source file and can export it to the PBJ binary file which is a compiled version of a Pixel Bender script that can be loaded by the Flash Player.

The latest Haxe file format library contains complete support to read and write PBJ file, enabling you to write Pixel Bender assembler directly in Haxe, then compile it on-the-fly into PBJ bytes, which can then be saved on disk or loaded directly in Flash.

For instance, you can use it to write the following PBJ dissassembler (Flash10 required) :


For more informations, you can read my Pixel Bender Assembler page for accessing source code, understanding how to get started writing your own PBJ assemblies, and a complete reference of the PBJ assembler.

  • Dec 05, 2008 at 10:10

    Hey Nicolas,

    I have writte the same in ActionScript and I think your version is more complete but I would suggest some more API features such as the ability to react on operations directly.

    package de.popforge.pixelBender.pbj.utils
    import flash.utils.IDataInput;

    import de.popforge.pixelBender.pbj.PBJFormat;

    public interface IOperationBender
    function bendOperation( owner: PBJFormat, input: IDataInput, opCode: int ): void;

    And in PBJFormat like this:
    public function routeOperationToBender( opCode: int, bender: IOperationBender ): void

    It became very useful in order to replace or react on specific opcodes directly.

    It would be also great if you include the ability to unroll loops in your API. E.g. you set the start point to a given position, say what to substitute for the loop and then the amount of iterations so the code could be copied the number of iterations.

    I could not find a way of implementing this very nice in a short amount of time. But I could think about some nice ways that would require some more implementation :)

    Anyways. Next step is a VM -- Hooray



  • Dec 05, 2008 at 20:20

    Hi Joa,

    Thanks to Haxe enums, I guess you can easily substitute opcodes by using a switch. Same for building loops, you can simply write a for loop that will push several times the opcodes in the .code array.

  • Hudson Ansley
    Jan 08, 2009 at 00:48

    Since a filter acts on all pixels, is it only as fast as the slowest operation for any pixel? I am trying to make my code as small as possible and since it will do more or fewer (unrolled) iterations depending on which pixel it is, I can avoid some IF opcodes by always doing the max iterations on every pixel. If the speed of the whole filter is limited by the "slowest" pixel, then the speed of the filter should be the same as (maybe even slightly faster than) a version that uses fewer iterations on some pixels.
    BTW- it is so amazing to have the ability to actually write the PBJ code in the Haxe code! I had not even considered that one would be able to hand code the PBJ bytecode in a much smarter way than the compiler. Thanks so much for working this out.

Name : Email : Website : Message :