AS3 PixelBender and Neuro Science experimentation

January 26th, 2010
by admin

Several experiments with flash pixel bender kernels and neuroscience math.
First is the 2D grid of coupled neural oscillators ( the neuroscientific equivalent of usual coupled oscillators descripted by some differential equations. Nice example is a double pendulum on youtube ).
So every pixel behaves like an oscillator and gives its energy to neighboring pixels. I’ve decided to store the energy in alpha component of 32 pixel.
On every render action, I’m stripping this alpha component and showing only 24 bit pixels:

mainBmp.bitmapData.applyFilter( mainBmp.bitmapData , mainBmp.bitmapData.rect , pt , shader );
bufBmp.bitmapData.copyPixels( mainBmp.bitmapData , mainBmp.bitmapData.rect , pt , null , null , false );

The last argument of copyPixels function tells flash to skip the alpha component. “shader” ( last argument of mainBmp’s applyFilter ) is the pixel bender filter.
This is the .as source: sine_pixel.as
And this is the kernel source: neur.pbk
Compiled kernel: neur.pbj

CLICK to see online simulation. Pretty cpu demanding, but it’s 256×256 oscillators grid. Click and drag on the stage like you were drawing, to start oscillation ( in the beginning the grid is synchronized ).
This is how it behaves in pure actionscript( flash player 10 needed, because I’ve optimized it using the Vector class ): sine_waves.swf … it has lower resolution though, 100×100. ( source )

The big resolution version ( 512×512 ): sine-hi.swf. CPU burning shader. I didn’t optimize it too much, maybe something can be changed to speed it up even more.

Ok, so that was the oscillation. There’s one more thing – grid of Sodium-Potassium neurons from previous post. I wanted to check if it’s going to be faster with pixel bender. And indeed – it is.
This is the source . I’m simulating current and the neuron response:

mainBmp.bitmapData.applyFilter( mainBmp.bitmapData , mainBmp.bitmapData.rect , pt , shader );
vBmp.bitmapData.copyChannel( mainBmp.bitmapData , mainBmp.bitmapData.rect , pt , BitmapDataChannel.RED, BitmapDataChannel.RED );
nBmp.bitmapData.copyChannel( mainBmp.bitmapData , mainBmp.bitmapData.rect , pt , BitmapDataChannel.BLUE, BitmapDataChannel.BLUE );

On every frame, I’m applying the shader on bitmap. Red component of pixel is the neuron response, green is the input current and blue is the gating variable. This time, I’m leaving alpha component alone. Because of this approach, I must copy RED channel from shaded bitmap to output bitmap, to see the graphical illustration of neuron response. The same thing happens with BLUE channel, which I copy to another bitmap. This is the kernel source: model.pbk. And this is the compiled kernel: model.pbj

Finally, 4 online demos. Try clicking the stage to generate some input current.
256×256 grid, first bitmap illustrates neuron response, second – gating var ( click the left bitmap )
The same as previous, but 512×512 grid
512×512 neuron response grid
512×512 gating var grid

Tags: , , , , , ,
Posted in flash experiments | Comments (3)

3 Responses to “AS3 PixelBender and Neuro Science experimentation”

  1. Tweets that mention Teleranek ? Blog Archive ? AS3 PixelBender and Neuro Science experimentation — Topsy.com Says:

    […] This post was mentioned on Twitter by David Lenaerts, Adobe Pixel Bender, den ivanov, nojyfied, Guy and others. Guy said: RT @pixelbender: AS3 PixelBender and Neuro Science experimentation – http://bit.ly/cUBwhc #Flash #Actionscript […]

  2. Yet more Pixel Bender community links « Kevin Goldsmith Says:

    […] SmartAA – reconstruct anti aliasing with Pixel Bender by Jan-C. Frischmuth (the same person who did Real-time Screen Space Ambient Occlusion with Pixel Bender and After Effects) A lot of cool Pixel Bender experiments happening on this blog, definitely worth checking out. […]

  3. megan kelly Says:

    Excellent points. I like how you put this article together. You have done a very good job. Admirable.

Leave a Reply