Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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: http://unitzeroone.com/blog/2009/03/18/flash-10-massive-amounts-of-3d-particles-with-alchemy-source-included/

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
        {
            shader.data.ab.value = [1.0, 8.0];
            shader.data.src.input = testVectorNum;

            shader.data.src.width = SIZE/400;
            shader.data.src.height = 100;
            shaderJob = new ShaderJob(shader, testVectorNum, SIZE / 4, 1);
            var time : int = getTimer(), i : int = 0;
            shaderJob.start(true);
            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.

Update:

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
    {
        shader.data.ab.value = [1.0, 8.0];
        var time : int = getTimer(), i : int = 0;
        testBitmapData.setVector(testBitmapData.rect, testVectorInt);
        shader.data.src.input = testBitmapData;

        shaderJob = new ShaderJob(shader, testBitmapData);
        shaderJob.start(true);
        testVectorInt = testBitmapData.getVector(testBitmapData.rect);
        trace("TEST1 : ", getTimer() - time);
    }
share|improve this question

1 Answer 1

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
        {
            shader.data.ab.value = [1.0, 8.0];
            var time : int = getTimer(), i : int = 0;
            shader.data.src.input = testVectorInt;//testBitmapData;
            shader.data.src.width = SIZE/4000;
            shader.data.src.height = 1000;
            shaderJob = new ShaderJob(shader, testVectorNum, SIZE / 4000, 1000);//(shader, testVectorInt2, SIZE/4, 1);
            shaderJob.start(true);
            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

 
discard

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.