Pixel Bender Inputs – Vector or ByteArray

Pixel Bender for Flash Player lets you play some more advanced games. Based on your needs you can force your kernels to “eat” not only BitmapData, but also ByteArray-s or Vector-s. With this knowledge, you can simply use Pixel Bender kernels for some fast math or processing like 3D engines (3D to 2D projection) etc. Lets have a look at some simple demos, how to push vector and raw bytes directly into shader via ShaderJob:


Simple (one-dimension) vector may be recognized by pixel bender as 3-channel input just as simple as providing correct width/height for shader:

var src:Vector.<Number> = new Vector.<Number>();

var shader:Shader = new Shader(code);
shader.data.src.input = src;
shader.data.src.width = src.length / 3; // forces pixel bender to use image3 as input
shader.data.src.height = 1;

var res:Vector.<Number> = new Vector.<Number>();
var job:ShaderJob = new ShaderJob(shader, res, src.length / 3, 1);

for(var i:uint=0; i<src.length; i+=3)
    x = res[i];
    y = res[i+1];
    z = res[i+2];


If you are more in “low-level” things, try using raw bytes as input. Do not forget to setup LITTLE_ENDIAN for source and result variables. Also make sure width*height*4 results in source bytes length.

var src:ByteArray = new ByteArray();
src.endian = Endian.LITTLE_ENDIAN;
src.position = 0;

var shader:Shader = new Shader(code);
shader.data.src.input = src;
shader.data.src.width = 256; // e.g.
shader.data.src.height = src.length/4/256;

var res:ByteArray = new ByteArray();
res.endian = Endian.LITTLE_ENDIAN;

var job:ShaderJob = new ShaderJob(shader, res, 256, src.length/4/256);

res.position = 0;
for(var i:uint = 0; i<src.length/4; i++)
    x = res.readFloat();
    y = res.readFloat();
    z = res.readFloat();

Lets have a look at how pixel bender handles input and outputs. As with current version of pixel bender/flash player it seems like:

'res' : cannot have 1 or 2 channel outputs

… but you can use 3 or 4 channel outputs (float3, pixel3).

<languageVersion : 1.0;>
kernel threed <namespace : "sk.yoz";vendor : "Yoz";version : 1;>
    input image3 src;
    output float3 res; // or pixel3
    void evaluatePixel()
        res = sample(src, outCoord());
        // we have res.x, res.y and res.z

Where to go from here:

6 comments so far

  1. Edgar August 2, 2010 19:21
  2. Jozef Chúťka August 2, 2010 22:53

    @Edgar thnx, good source. Added to article

  3. karanvir singh September 14, 2010 15:35

    hii can any one say whether can i play games that run with shader pixel 3.0(assassin 2 so on….)
    in a graphic card that has shader pixel value 2.0.
    please suggest.

  4. Jozef Chúťka September 14, 2010 16:22

    sory karanvir singh, this is a very different technology

  5. sastradhar October 28, 2011 22:11

    if i want to pixel bender to work on unsigned short as input
    can you tell me what should be the width and height of the source i need to pass.

  6. Jozef Chúťka October 31, 2011 10:50

    sastradhar, you have to use Numbers as input, pixel bender does not work with integers. width * height * input type must match the input data length

Leave a comment

Please be polite and on topic. Your e-mail will never be published.