Archive for Benchmark

Fast Metaball Effect in AS3


var container:Sprite = new Sprite();
var balls:Vector. = new Vector.();
var m:Matrix;
var s:Shape;
var r:Number;
var c:uint;
for(var i:int = 0; i < 10; i++){
r = Math.random() * 100 + 100;
m = new Matrix();
m.createGradientBox(r, r, 0, -r * 0.5, -r * 0.5);
s = container.addChild(new Shape()) as Shape;
c = Math.random() * 0xFFFFFF;
s.graphics.beginGradientFill(GradientType.RADIAL, [c, c], [1, 0], [0x00, 0xFF], m);
s.graphics.drawRect(-r * 0.5, -r * 0.5, r, r);
s.x = Math.random() * 400;
s.y = Math.random() * 300;
moveBall(s);
balls.push(s);
}
function moveBall(s:Shape):void
{
//whatever easing to move the spheres
}
var s2:Shape = container.addChild(new Shape()) as Shape;
m = new Matrix();
m.createGradientBox(200, 200, 0, -100, -100);
c = Math.random() * 0xFFFFFF;
s2.graphics.beginGradientFill(GradientType.RADIAL, [c, c], [1, 0], [0x00, 0xFF], m);
s2.graphics.drawRect(-100, -100, 200, 200);
var bmpData:BitmapData = new BitmapData(400, 300, true, 0x00000000);
var bmp:Bitmap = addChild(new Bitmap(bmpData)) as Bitmap;
addEventListener(Event.ENTER_FRAME, render);
function render(e:Event):void
{
s2.x = mouseX;
s2.y = mouseY;
bmpData.applyFilter(bmpData, bmpData.rect, new Point(0, 0), new BlurFilter(2, 2, 2));
bmpData.draw(container);
var i:int, l:int;
var aArr:Array = [];
var c:int;
for(i = 0; i <= 0xFF; i++)
{
c = (i - 0x80) << 1;
if(c < 0) c = 0;
aArr[i] = c << 24;
}
bmpData.paletteMap(bmpData, bmpData.rect, new Point(0, 0), null, null, null, aArr);
}

Vote in HexoSearch Vote

Comments (4)

BitmapData.lock benchmark

Well, I don’t know if anybody read the Thomas Pfeiffer aka Kiroukou (the Sandy3D creator and project leader) commented on my previous post.
Here’s what he said.

Indeed Sandy does a clone of the original texture, for few reasons:
- avoid an unfortunate dispose call.
- allowing to have a setTransparency method to dynamically change the transparency without changing the original bitmapdata of the user.

Concerning the lock() and unclock() are you sure it has a performance impact?
as far I know, this can’t provide any performance boost since the bitmapdata isn’t attached to the flash display list. When the object is out of stage, there’s no advantage to lock it.
But I’d be interessted to have your feedback about that, and your performance test.

About the BitmapData.clone(), he got his point.
It just don’t work for me because I’m using too many 3d Objects with different BitmapMaterial for each, so, the system memory gets too high.
But, about the setTransparency method, he is right.

About the lock and unlock methods, I runned a little benchmark test, because I got curious too how much performance boost you can get.
Here’s the two test I made. (Clicking on the flash area it will re-run the benchmark test)

Using the lock and unlock methods.

Not using the lock and unlock methods.

It’s a really simple test, just to make a benchmark test.
Actually, it’s not a situation that uses any 3d framework.

Creating a BitmapData.
Creating 1000 Bitmaps.
Applying 1000 times a BlurFilter over the BitmapData.

On my PC I get about 150ms faster with locking the BitmapData.

keita

Vote in HexoSearch Vote

Comments (3)

BitmapData.draw x Graphics.beginBitmapFill

Firstly… sorry for my poor English…

Working on Recyou.jp, I had to use many BitmapDatas, and so, I had to work out some way to make it lighter.
One thing I realized is that using Graphics.beginBitmapFill besides BitmapData.draw its much faster.

I made the benchmarks, drawing 10000 bitmapDatas, one using BitmapData.draw, and other using Graphics.beginBitmapFill.

First the benchmark with BitmapData.draw (Clicking on the flash it will re-run the benchmark):

The code is something like this:
[code lang="actionscript"]
var genericBmp:BitmapData = new BitmapData(100,100, false, 0x000000);
var bmp:BitmapData = new BitmapData(100,100, false, 0x000000);
for(var i = 0; i < 10000; i++){
bmp.draw(genericBmp);
}
[/code]

Now the benchmark with Graphics.beginBitmapFill (Clicking on the flash it will re-run the benchmark):

The code is something like this:
[code lang="actionscript"]
var genericBmp:BitmapData = new BitmapData(100,100, false, 0x000000);
var bmp:BitmapData = new BitmapData(100,100, false, 0x000000);
for(var i = 0; i < 10000; i++){
graphics.beginBitmapFill(genericBmp);
graphics.drawRect(0,0,100,100);
}
[/code]

So, if you are trying to create some bitmap pattens or attaching a Bitmap child and redrawing it’s BitmapData, try using the Graphics.beginBitmapFill.

Vote in HexoSearch Vote

Comments (6)