Sadly, it seems that Pixel Bender might be nearing the end of its life and being replaced by AGAL - Adobe Graphic Assembler Language. AGAL is a low level language designed specifically for creating shaders and because I want to continue developing my Reaction Diffusion Explorer, I spent Sunday attempting to learn it.
It takes me right back to hacking Z80 machine code on my first computer, the Sinclair ZX80. There are no fancy classes, conditionals or even variables, you have opcodes and registers and that's pretty much your lot!
Before running before I could walk, I thought I'd kick off implementing one of my favourite reaction diffusion simulations, Belousov Zhabotinsky. This is a famous chemical reaction that produces characteristic spirals.
The code in Pixel Bender is pretty straight forward. I take the current pixel and its eight immediate neighbours, add their values together, divide by nine, do a bit of adding, multiplying and dividing magic and I'm done.
AGAL is a bit more challenging. My fragment shader doesn't really understand pixels, it understands normalised UV coordinates. So my first hiccup was simply adding and subtracting one from the current position. Thanks to Cywil at Krecha for pointing this out: when navigating around the current pixel to sample its neighbours I need to add 1 / width or height.
The maths in AGAL is also a little fragile. When I originally divided the accumulated pixel values by nine, the image slowly dimmed out. Simply changing the denominator to 8.9 resolved this, although I'm not sure why. I had a lot of fiddling of getting the subtract, divide and multiply in the right order. Even though, in my view, they should have given the same result.
I render not only to the back buffer but also to a new texture. This texture is fed back into the context3D to be reprocessed on the next frame. Easy!
I'd also like to thank Jonathan Hart for looking over my AGAL and finding some typos.
Next step is to use AGAL for Gray Scott - that's a little more complex but now I've broken the back of Stage3D shaders I'm looking forward to it!
The source code for this is available here and the demo harness is here.