Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Remember my old question: 2d game view camera zoom, rotation & offset using 'Filter' / 'Shader' processing?

I figured I could use a Pixel Bender Shader to do the computation for any large group of elements in a game to save on processing time. At least it's a theory worth checking.

I also read this question: Pass large array to pixel shader

Which I'm guessing is about accomplishing the same thing in a different language.

I read this tutorial:

I am attempting to do some tests. Here is some of the code:

        private const SIZE : int = Math.pow(10, 5);
        private var testVectorNum : Vector.<Number>; 

        private function testShader():void
   = [1.0, 8.0];
   = testVectorNum;

   = SIZE/400;
   = 100;
            shaderJob = new ShaderJob(shader, testVectorNum, SIZE / 4, 1);
            var time : int = getTimer(), i : int = 0;
            trace("TEST1 : ", getTimer() - time);

The problem is that I keep getting a error saying:

[Fault] exception, information=Error: Error #1000: The system is out of memory.


I managed to partially workaround the problem by converting the vector into bitmapData: (Using this technique I still get a speed boost of 3x using Pixel Bender)

    private function testShader():void
    { = [1.0, 8.0];
        var time : int = getTimer(), i : int = 0;
        testBitmapData.setVector(testBitmapData.rect, testVectorInt); = testBitmapData;

        shaderJob = new ShaderJob(shader, testBitmapData);
        testVectorInt = testBitmapData.getVector(testBitmapData.rect);
        trace("TEST1 : ", getTimer() - time);
share|improve this question
up vote 2 down vote accepted

I found a complete solution to this issue.

Please notice size is now 10,000,000

Here is the new code snippet:

        private const SIZE : int = Math.pow(10, 7);
        private var testVectorInt : Vector.<Number>; //gotta use Number (not int)
        private var testVectorInt2 : Vector.<Number>; //Need separate vectors for I & O

        private function testShader():void
   = [1.0, 8.0];
            var time : int = getTimer(), i : int = 0;
   = testVectorInt;//testBitmapData;
   = SIZE/4000;
   = 1000;
            shaderJob = new ShaderJob(shader, testVectorNum, SIZE / 4000, 1000);//(shader, testVectorInt2, SIZE/4, 1);
            trace("TEST1 : ", getTimer() - time);

You might be wondering what is the speed difference?

Processing the Numbers one by one in a loop took: 1956ms

Doing it in Pixel Bender took: 189ms

This results is true for Flash Player 10.3 on my pc

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.