Hi everyone! I bolded the actual problem with which I’d be happy to get help.
I’ve spent the whole week trying to squeeze the last bit of performance from the Flash Player so as to implement a feature I really want. I still don’t think it’s impossible but it’s getting tough and I’d be glad to get some help!
I want to depth sort 2D images on a per-pixel basis. To achieve this I compare individually each pixel of specially crafted greyscale versions of those images, and output the normally colored result accordingly.
Problem is that AS3 seems too slow to do this realistically. I aim to get between 30 and 50 FPS (50 ideally), and in worst case scenario I expect 100 images to sort. Their size vary from probably be as big as 700x200 to low 10x10.
---- Here’s what I did so far, you don’t need to read this if the post gets too long.
I tried ByteArray with readUnsignedInt, which sucked big time. I tried BitmapData.getVector, and iterating over the returned Vector… Much better but still horrible, like 25ms to compare two medium sized images.
I tried Pixel Bender and the performance gain is huge. However Pixel Bender is crippled with sneaky limitations when ran in Flash.
- As a ShaderJob, one instance job can be ran only once, and starting it takes about 20ms or even 40. (depends on how many inputs you use I think)
- As a BlendMode the speed is perfect, but you can only use 2 input images, and it’s not enough in my case. Also, blend mode can only sample the current pixel, not any pixel you want…so, grouping greyscale and colored images in single images before passing them to the shader is useless.
- As a ShaderFilter, I’m not sure how feasible it is. Comparing two grey images takes 1ms, which still seems a little too slow. And I didn’t find how to deal with the output image anyway, considering both the colour and grey images need to be updated and accessible to the next filter comparison.
Remains Alchemy or haXe using opcodes, but I don’t know how to achieve what I want using them (or a combination of everything I mentioned so far, or other suggestions you may have)…
Any idea?