How to use Pixel Bender (pbj) in ActionScript3 on large Vectors to make fast calculations?
- by Arthur Wulf White
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);
}