I’ve been revisiting one of my favourite topics lately – recursion – and have been getting together a bunch of sketches for a big personal project I’m working on (more on that another time). Anyway, I inadvertently stumbled across quite a nice way of making things grow in a convincing manner, and whilst this script doesn’t actually use recursion ‘per se’, I thought it was kind of cool so I ran with it.
It also presented a good opportunity to try out another Flash Player 10 feature that I’ve been eager to try, which is using Pixel Bender and ShaderJob. Although I’ve used Pixel Bender before, I’ve never used it in this way.
Basically, the idea is to exploit Pixel Bender’s performance and ask it to do some of the heavier number crunching for you – a concept that is currently being used by the Papervision3D team to give some juice to the next release. The other great thing about this approach is that these computations can run in another thread, leaving you more resources for other tasks (like rendering a fishing boat load of tentacles)
So, although this isn’t the best example of using Pixel Bender’s capabilities, it was a nice opportunity to exercise the idea. Each Tentacle starts a new ShaderJob and Pixel Bender whips up some tasty trigonometry for me, before passing it back inside a Vector object (typed Array). From there it’s just a question of making those numbers look nice… Kind of reminds me of the illustrative style used for the O’Reilly book covers…

I don’t why I like growing tentacles. It’s kinda disturbing.
could we be so lucky as possibly get the source?
i don’t really get the point with recursion ; i’m totally new in that kind of stuff… I’d be interested in understanding some basic concepts :)
Anyway, this is pretty awesome :D
Hi
Ahh we all like tentacles:) as always your stuff is great to look at.
I was wondering, what part is it pixel bender is doing heavy lifting on in this sketch?
As I see it, this is not just starting out with a big circle and then drawing a smaller circle on top of it. It seems you actually draw the entire set each time, so you have an array of circles and you push new large circles in from the bottom and redraw everything each frame? processing style:)
I can’t figure out where the pixel bender part goes:) ..next end coordinate? are all the tentacles like 20×20 = 400 circles long, to mimic 2D image terminology?
Hope you decide to elaborate a bit on how you use pixel bender for number crunching, there is just not enough info on that out there.
Hey Ricki,
Cheers for the comment. I’ve been really enjoying browsing your site! You have some great stuff going on there :)
Re. your comment – I didn’t find much by way of explanation either, so it was the Flex SDK docs that helped the most in the end. Perhaps I should write up the process and put up a new post on the subject?
This particular experiment doesn’t gain a huge amount of performance from using PixelBender – it was simply that I saw it as a good opportunity to implement the theory.
You’re pretty much spot on with your description though – each tentacle is made up of 150 to 300 segments, so what I’m doing is pre-computing the position of each segment using an additive sine / cosine based algorithm, but instead of doing this in Flash, I’m setting up a ShaderJob which will compute all of these values for me and write them to a Vector, which is passed back to Flash and the values are simply read from the Vector as the tentacle draws itself.
There’s some debate as to the correct and incorrect times to use this process, as writing the initial ByteArray or Vector, passing it to PB and then retrieving the results and reading them is a costly process in itself (as opposed to just performing the calculations inline with Actionscript – optimised AS can be just as good sometimes). I think that generally its a question of testing the performance of both approaches on a project-by-project basis. I can see why a 3D engine for example would benefit from the PixelBender approach – if the calculations for your meshes / cameras / textures are all bundled into a single job that can run in another thread asynchronously, then Flash can use its resources for rendering.
I’ll try and write up a quick example anyway. Generally it’s a pretty straight forward process, though there are a few pitfalls when dealing with PB!
Hi Justin
Thanks for elaborating and thanks for the compliment:) I just started and your site is a constant source of inspiration.
I am just waiting for an idea to come along that would justify using PB, I think I got something and was planning on writing it up in the weekend, but these things has a way of suddenly taking longer that expected.
I would like to utilize sound and have PB write up a bump map/flow field from the fast Fourier transform, either having PB do both the FFT and the bump map or just the bump map, I would think that having flash doing the sound manipulation for a low res sample was just as fast as having the data sent back and forth… to the lab.
I’ll ping this post if I get something written up.
Cheers
that’s amazing, great work :)
Can you provide source code or at least a tut for how to connect everything together to make this?
i like it so much – and would like to look over the source ;-)
Ditto would love to see the source for this (or even nudges in the right direction to get the tentacles so beautifully tentacular)–I’ve got a simple game idea growing on me =)
I’ve been staring at this on-and-off for 40 minutes while listening to the new Porcupine Tree album. It’s quite hypnotic :)
I really love the tentacles. We can we see source code for this awesome work?