|
===================================
SOME LINKS
===================================
Start here:
http://www.adobe.com/devnet/flash/articles/pixel_bender_basics_03.html
Adobe Labs page
http://labs.adobe.com/technologies/pixelbender/
Twitter feed
http://twitter.com/pixelbender
Pixel Bender Exchange
http://www.adobe.com/cfusion/exchange/index.cfm?event=productHome&exc=26
Forum
http://www.adobe.com/cfusion/webforums/forum/categories.cfm?forumid=72&catid=661&entercat=y
MAX presentation 11/2008
http://tv.adobe.com/#vi+f15383v1072
Adobe TV video
http://tv.adobe.com/#vi+f1552v1003
Embedding into SWF
http://www.mikechambers.com/blog/2008/09/08/embedding-pixel-bender-filters-within-a-swf/
Apply to video..
http://www.brooksandrus.com/blog/2009/01/19/pixel-bender-effects-video-killer-runtime-effects/
Fuckin color keying
http://www.video-flash.de/index/flash-player-10-pixel-bender-realtime-color-keying/
Simple example, math only
http://www.boostworthy.com/blog/?p=243
Audio mixing
http://www.kaourantin.net/2008/10/audio-mixing-with-pixel-bender.html
Endian-ness is opposite:
http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=72&catid=675&threadid=1373666&enterthread=y
===================================
SOME EXPOSITION...
===================================
What about the 4th? Well, as you can see the ones in the list are designed
for graphics only. The last one is more powerful than that. Instead of
targeting a specific graphics primitive in the Flash Player, you can target
BitmapData objects, ByteArrays or Vectors. Not only that but if you use
ByteArray or Vector the data you handle are 32-bit floating point numbers
for each channel, unlike BitmapData which is limited to 8-bit unsigned
integers per channel. In the end this means you can use Pixel Bender
kernels to not only do graphics stuff, but generic number crunching.
If you can accept the 32-bit floating point limitation.
# The internal RGB color space of the Flash Player is alpha
pre-multiplied and that is what the Pixel Bender kernel gets.
# Output color values are always clamped against the alpha. This is not
the case when the output is a ByteArray or Vector.
# The maximum native JIT code buffer size for a kernel is 32KB, if you
hit this limit which can happen with complex filters the Flash Player
falls back to interpreted mode mode like it does in all cases on
PowerPC based machines.
# Math functions apart from simple multiplication, division, addition
and subtracting work slightly differently on different platforms,
depending on the C-library implementation or CPU.
In the Pixel Bender model, images do not have a size. Instead, each
image is thought of as being defined over an infinite plane of discrete
pixel coordinates.
This Pixel Bender coordinate model has implications for filter design.
For example, it is not possible to write a Pixel Bender kernel that
reflects an image around its “center,” because the center is undefined.
Instead, the coordinates of the circle must be denoted explicitly by
passing them in as kernel parameters.
Pixel Bender images have 32 bits per channel, but graphics in Flash
Player 10 have only 8 bits per channel. When a kernel is run in Flash
Player, the input image data is converted to 32 bits per channel
and then converted back to 8 bits per channel when kernel execution is
complete.
No arrays for Flash.
No dependent values.
===================================
PBK / TOOLKIT NOTES
===================================
Toolkit
Make sure to check Build > Enable Actionscript warnings
File types
pbk - source code
pbj - abc
pbg - graph code
Types
float
int
bool
pixel (represented internally as a float)
image1/2/3/4 - represents an entire image with 1,2,3 or 4 channels
No arrays.
Vectors
Above Types can be declared as 2,3 or 4 element vectors (eg, "float2", "pixel4")
Declared like this: float3(0.0, 0.5, 1.0);
Accessed like this: myFloat[0], or myPixel.r
Also, r,g,b,a == 0,1,2,3
x,y,z,w == 0,1,2,3
s,t,p,q == 0,1,2,3
"Swizzing":
float3 noAlpha = vec4.rgb;
float4 reversed = vec4.abgr;
vec2 = vec4.xz;
Casting
Works between bool, int, and float:
Eg, "bool(myFloat)"
- Declaring the input and output variables
input image4 src;
output pixel4 dst;
- Declaring parameters (AS-controlled variables)
parameter float exposure;
- Declaring parameters for 'UI'
parameter float red
< minValue:float(0);
maxValue:float(1);
defaultValue:float(0.0);
>;
- Declaring variables
float4 inputColor = sampleNearest(src, outCoord());
- Declaring constants
const pixel3 color1 = pixel3(1,0,0);
- Main function
void evaluatePixel()
{
}
- Flow control
if else, that's it
- Functions
outCoord():float2 - the current coordinates
sampleNearest(imageN, float2 f):pixelN - nearest pixel to f
sampleLinear(imageN, float2 f):pixelN - nearest pixel to f, bilinear
- Math functions
pow, exp, exp2, log, log2, sqrt
sin, cos, tan, asin, acos, atan
abs, sine, ceil, floor, fract, mod,
step, clamp, mix, smoothStep
radians, degrees
length, distance, dot, cross, normalize
matrix stuff...
- Region functions
...
================================
USE IN ACTIONSCRIPT
================================
Example:
[Embed(source="alpha.pbj", mimeType="application/octet-stream")]
private var PbjAlpha:Class;
_shader = new Shader(new PbjAlpha());
_shaderFilter = new ShaderFilter(_shader);
_sprite.filters = [ _shaderFilter ];
Feeding extra inputs to the shader:
They live in "_shader.data.*". Are of type "ShaderInput". Eg:
_shader.data.myInputVariable.input = a BitmapData or ByteArray
_shader.data.myInputVariable.width/height - need to be specified only for ByteArray inputs
_shader.data.myInputVariable.channels = 3 or 4; // read only?
_shader.data.myInputVariable.name = "myInputVariable"; // read only?
_shader.data.myInputVariable.index = 0, 1, 2, ...; // read only?
The first input in a shader is (always?)(by default?) the object
that the shaderfilter is applied to.
Using parameters declared in the PBK
Found in "_shader.data.*" also. Of type "ShaderParameter". Eg:
_shader.data.myParam.defaultValue/minValue/maxValue -
Array of 1 or more elements;
defined by PBK metadata
_shader.data.myParam.value - Array
_shader.data.myParam.type = "float"
_shader.data.myParam.index
!important:
After changing any parameter, you have to reapply the shader:
"s.filters = [ _shaderFilter ];"
Using ShaderJob:
_shaderJob = new ShaderJob(_shader, _outputBitmap, _width, _height);
_shaderJob.addEventListener(Event.COMPLETE, onShaderJobComplete);
protected function onShaderJobComplete(event:Event):void
{
// do stuff with "_outputBitmap" or event.bitmapData or event.byteArray, etc.
}
|
|
Page last modified on June 07, 2009, at 03:36 PM
|
|