Pixel Bender’s Eccentricities

Pixel Bender doesn't always play quite right with Flash.  I'm attempting to build up a list of just how it behaves oddly.

This is very much a work in progress.  I'm mainly posting it now so I can link to it in other posts.  It is also worth pointing out that these are problems that I have encountered on my particular set up, so it's not at all clear where in the chain these occur. Please do suggest any you find in the comments.  If you can manage to get someone from Adobe to pay attention, that'd be good too!

Comparing vector-type variables

Say you've got two float3 variables and want to see if they're identical.  The following should work:

(one == two)

This does work when testing in Pixel Bender, but seems to always return false when compiled for Flash.  To get around this, compare the elements of the vector-type variables separately:

(one.r == two.r && one.g == two.g && one.b == two.b)

Clamp

There's a handy built-in function called clamp.  This takes three values: x, min, max.  If x is between min and max it just returns x; if x is smaller than min then it returns min; if x is larger than max then it returns max.  This works fine in Pixel Bender, but can fail (only fails in the case of x > max?) when compiled for Flash.  Get around it by using a pair of simple if statements.

Cancelling a save on exit

This isn't really about Pixel Bender for Flash, but a general annoyance.  Upon closing Pixel Bender when it has an unsaved file open, it asks if you want to save it giving options Save, Don't Save, Cancel.  Clicking cancel will cause Pixel Bender to close and abandon the file.  The expected behaviour is for cancel to cancel the whole quit operation.

Sampling outside of an image

Behaviour varies between Pixel Bender and Flash when a shader attempts to sample a pixel from outside the bounds of an image.  In Pixel Bender, a black pixel is returned.  In Flash a pixel identical to the closest pixel that is within the image bounds is returned.

Normalise function creates artefacts

I don't have this properly pinned down, but I think it's related to the first few pixels of each shader instance being processed in interpreted mode (rather than Just in Time) which causes it to use slightly different math functions.  Artefacts have tended to be black rows of 3 pixels length on the right-hand side of the image.  Such artefacts only appear in Flash.

Change from:

myVector = normalize(myVector);

To:

myVector /= length(myVector);

Just beware division by zero.

Flash Player crashes with shaders on large images

On certain browser / OS / hardware set-ups the Flash Player will crash when attempting to run a Pixel Bender shader on a large image.  I can't recreate the crash on my machine, but it looks like the size limit is between 1024x1024 and 1500x1500 (the former works fine, the latter causes the crash.)  It is still possible to put large images through a shader, you just need to chop them up into bite-sized parts first then stitch them together again after they've been through the shader.  Exactly how you do that is going to depend on what your shader's doing.

Order of declaring parameters

When declaring parameters for a shader, you should list float type values before float2 type values.  Presumably there needs to be similar ordering for other types, but I've not experimented.  The parameters 'just break' in seemingly arbitrary ways if they're listed out of that order.

Post a Comment

Your email is never published nor shared.

Powered by WP Hashcash