Pixel Bender – The End Of Papervision?


Ha!  Honestly, the title was just to get your attention.  But to answer your next question, no, there isn’t a single line of Papervision in this demo (requires Flash Player 10).  This is, in fact, my first real test with Pixel Bender (and integration with Flash).  I had written one or two a few months ago the day it was released, but this was something that I had hoped would change the way I do some things in Flash.  It was inspired, (and some projection stuff borrowed) by the raycasting work of mike welsh, who made this great raycasting shader, which handled reflections, etc.  While it runs great in the toolkit, it can’t work in Flash (but even if it did you would only get about 1 FPS).  What I hoped would be a fast and elegant solution for a client project turned out to simply be a cool little experiment.  Not much application in the real world I don’t think – at least not till Flash gets some GPU support for it.

So, what did I learn?

1. Normalize doesn’t work in Flash – though it does in the toolkit.  I spent about 4 hours tracking down this nightmare.  My project worked great in the AIF Toolkit, but once I brought it over to Flash, the shading turned into a ghoulish wash.  Turns out that the Flash Player doesn’t read normalize.  Instead, you need to do something like this:

float3 vectorNorm = vector/ length(vector);

Or of course, you just do a /= to the original vector.

2.  No Debugging. This is always a struggle when making a shader.  The way you can debug is by simply outputting colors instead of debug statements.  I did end up making some very cool patterns in my filter by outputting various properties as color – but in the end it would be nice to have a simple trace statement.  For example, instead of doing:

out = sampleNearest(src, outCoord())

You can do

out = pixel4(norm.x, norm.y, norm.z, 1.0);

Then the image itself becomes a debug view of sorts.  Its a little less informative than a trace (though it does show trends well), but it helps tremendously when working with shaders.

3.  CPU != GPU.  Running in CPU mode flipped some normals on me.  It worked right in GPU and in Flash.  I read (somewhere) you should test in both to make sure it works all around.  Not sure if this means there will be problems on different computers or not…

4.  Pixel Bender isn’t nearly as fast as I wanted.  Sorry… its true.  It sucked going from the 800 FPS Toolkit to the 165% CPU destroyer (dual-core).  Turning the window mode to GPU took about 15% off the CPU, but it still wasn’t the performance I was hoping PIxel Bender would bring to the Flash Player.  I found the biggest thing that affected performance was simply how big the image was you were applying the filter too.  Apparently alot of math is faster in AS3 than in Pixel Bender (CPU).  I guess one solution would be to pass in more parameters with some of the math already taken care of.

Some Info About the Demo

I guess first thing to point out is that I use two input images.  src is first input image4, and the one that is automatically passed as an input to the shader.  This image4 is simply the object you are applying the shader too.  The second input, texture, is the texture we want to use for the mapping.  By using two images, we don’t have to process every pixel of the texture mapped, if we only want a 512×512 sphere.  In this demo the src image is only 350×350 – much better performance than running it on 1000×500.

Next, the performance sucks.  Well, to be fair, it runs okay – but it won’t run on older computers at all, and runs at max CPU on the newer ones.  I have tried some things to speed this up, such as taking the rotation matrix outside the filter and passing it in, but the change was negligible (I didn’t see a difference).  So, I opted to create the matrix in the filter per pixel and just keep the filter as self-contained as possible.  If anyone has some tips/tricks to make this filter run faster – let me know!

I’m happy with how it looks – sorry for some of the UV code in the shader itself – in order to remove some precision errors, I had to swap the side axis used for determining rotation depending on the location of the hit.  Makes things look better, though code looks a little worse.

Anyways:

Check out the Demo

and

Get the Source (once again, requires Flash CS4 and Flash Player 10)

Enjoy


17 Comments, Comment or Ping

  1. It’s disappointing to hear that the performance of PixelBender isn’t up to expectations. I had high hopes for this new side of Flash.

    Thanks for taking the time to write up about your experiences with it. It’s much appreciated (when I have very little time to learn all that’s new)

    November 25th, 2008

  2. It’s impossble to remplace loops by functions calling themself ? (I never read PB doc and havent got time for testing)

    November 25th, 2008

  3. A very nice example. I find it weird though that the math is faster in AS3. I thought Pixel Bender’s multi-core support would make it much faster…

    November 25th, 2008

  4. The quality of the rendering is really nice, but I agree that the performance is a bit deceiving.

    It is great to see experiments with Pixel Bender starting to come out anyway!

    November 25th, 2008

  5. MEM’s there actually aren’t any loops in Pixel Bender. Or well there are but not for Flash. Essentially what happens is that there is a function that runs over every single picture in an image.

    I wish when you were testing with Pixel Bender and you swtiched to test it for Flash that it would use the CPU instead of GPU. So it would be a true test.

    Andy I had the same problem. My very first heavy pixel pender project essentially crashed flash within half a second cause it was too intense. :(

    Pretty lame.

    November 25th, 2008

  6. The demo crashes my browser :(
    Firefox 3.0.3
    Flash 10,0,12,36
    Debian Linux

    November 25th, 2008

  7. Neat demo. Aside from the lack of debugging I’m really liking the Pixel Bender, especially when used with Photoshop and After Effects. It’s still early days for Flash but hopefully in future versions will open up more potential.

    November 25th, 2008

  8. mud

    Looks great, works well on my laptop (perhaps a bit slow, but not too noticeable). It’s fun to see this kind of development so early… I think Pixel Bender just came out of beta a few weeks ago. Here’s another cool 3D demo found on the net:

    http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&loc=en_us&extid=1634018#

    November 26th, 2008

  9. Nice summary i was essentially saying the same thing like a month ago about the dissapointment in Pixel Bender’s utility but no one listened :) Now atleast there are more ppl coming to this realization.

    I think Pixel Bender is great for simple filters, blend modes and essentially 2D stuff, but once you need to go 3D or any slightly more complex implementations it doesn’t come close to CG or HLSL and even with the limited functionality its still clunky in its execution :/

    Anyway maybe next time Adobe i am looking forward to it ;)

    November 26th, 2008

  10. Oh i forgot, its still great for generating procedural textures, for example this is our double plasma shader applied in 3D scene:

    http://blog.flash-core.com/?p=83

    I am sure in demo oriented part of the flash scene Pixel Bender will get a lot of attention ;)

    November 26th, 2008

  11. Ossia

    Hi Andy,
    I know its off topic but I could really do with a bit of help trying to get the lensflare() to work…its taking me far too long. The setup seems to have changed a little bit since your example and Im not having any joy with it. If its ok Id like to send source – which is mostly from your previous example.
    Respect for all your work

    November 26th, 2008

  12. saul

    OMG! Check This!

    Japanese PV3D is going to take over the world!!!

    http://uk.youtube.com/watch?v=_WSd-cR0c5Y

    December 2nd, 2008

  13. I think Pixel Bender has or is getting limited gpu support (that means also in Flash). Let’s see wha the future ‘ll bring ..

    December 4th, 2008

  14. Igor

    Nice demo, but the earth is rotating the wrong way. ;-)

    February 24th, 2010

  1. Pages tagged "filter" - November 25, 2008

Reply to “Pixel Bender – The End Of Papervision?”