Conduit for Flash Pixel Bender – Frequently Asked Questions

Conduit for Flash Pixel Bender, developed by Lacquer oy/ltd, is a Mac+Windows application that enables Flash developers to create Pixel Bender shaders with a fully visual user interface.

Conduit for Flash Pixel Bender is part of a family of products: Conduit is a realtime graphics and video effects creation tool which is available as plug-ins for many popular professional applications. There is also Conduit Live, a standalone application designed for live video effects and capture. The Conduit plug-ins and Conduit Live are available as a single affordable bundle, Conduit Suite.

Pixel Bender is a high-performance graphics programming language developed by Adobe. Pixel Bender can be used to create image and video processing effects that run on all Adobe products that support the language.

Flash Player 10 contains a high-profile Pixel Bender implementation. Pixel Bender shaders can be used by Flash developers to create custom image filters and blending modes. They also provide a new way to do high-performance computing within a Flash application.

A shader is basically a small compiled program that has been optimized for graphics and multicore processing. Shaders are one of the most important new features in Flash Player 10 because they give Flash developers access to a completely new special-purpose runtime that has much higher performance than the traditional ActionScript runtime.

Shaders can be used in Flash Player 10 as graphics object fills, graphics and video filters, blending modes, and for background processing jobs using the ShaderJob object. The latter is the key to deploying shaders for non-graphics purposes: many computing jobs that would take an inordinately long time in plain ActionScript can be executed an order of magnitude faster using ShaderJob.

For more information, please see ActionScript reference: Shader class on Adobe's web site.

There's some ambiguity in Adobe's documentation around the terms kernel and shader. Pixel Bender programs are officially called kernels by Adobe. However Flash Player 10 and the Flex SDK documentation refers to them as shaders. As Conduit for Flash Pixel Bender targets Flash Player, it makes sense for us to adopt nomenclature that matches Flash.

Thus in practice "Pixel Bender kernel" and "Pixel Bender shader" both refer to the same thing. The only difference is that a kernel can be either a textual Pixel Bender program (.pbk file) or a Pixel Bender bytecode program (.pbj file), whereas a shader implicitly means the latter format since that's the only format that Flash Player 10 can consume.

A filter is a more generic term for an image processing module within a graphics application. Flash contains a handful of built-in filters, but they are not customizable beyond a few parameters. What's new in Flash Player 10 is that developers can use Pixel Bender shaders as completely custom filters.

Flex is an Adobe technology for creating rich Internet applications that run on the Flash platform, either within a browser through the Flash Player plug-in or as independent desktop applications through Adobe's Internet application runtime AIR. The Flex SDK (Software Development Kit) is a free download and also, except for a few components, open source.

Adobe also offers Flex Builder, an integrated development environment (IDE) based on Eclipse.

There are thus three common ways to develop Flash applications: using the designer-oriented Flash Professional application (which used to be the only way before 2004); using the Adobe Flex Builder IDE; or using only the open source Flex compiler.

Adobe has indicated that Flash Professional CS4 will ship in October 2008. Presumably the release version of Flash Player 10 will become available around the same time.

There's no official release date for Flex 4 yet, but you can start using pre-release versions of the Flex 4 SDK right now:
Flex 4 SDK on Adobe Labs

If you're using Flash Professional CS4, you can import the .PBJ shader files produced by Conduit in exactly the same way as files produced by Adobe's Pixel Bender Toolkit. Please see Flash documentation for details.

If you're working with Flex, a nice way to get started is to watch video tutorials by Lee Brimelow on TheFlashBlog. He shows how to create Flash Player 10 compatible SWF files in Flex, how Pixel Bender shaders are imported into ActionScript, and how they can be applied to images:
Lee Brimelow's video tutorials

ActionScript expert Mike Chambers has written about Pixel Bender filters on his blog, showing several ways of integrating Pixel Bender into your Flash projects. If you need to use a shader just once, the simplest way is to embed a Pixel Bender filter within an SWF:
Embedding Pixel Bender filters within a SWF

If you'd like to reuse a shader, you can encapsulate it inside an ActionScript class, which you can then reuse just as easily as the built-in filters:
Encapsulating custom Pixel Bender filters in ActionScript 3

You can also package shader classes in the SWC format (ActionScript class library), which allows you to create and redistribute entire libraries of shaders that can be used in Flex Builder and Flash Professional CS4:
Creating re-distributable ActionScript libraries of Pixel Bender filters

Visit the Flex SDK website at Adobe's open source projects home to download the free Flex SDK. There are two downloads: the official Adobe Flex SDK and the open source SDK. The latter is sufficient for building Flex projects that use Pixel Bender and target Flash Player (you'll need to install Flash Player separately because it isn't open source, but of course most people already have the player).

To build Flex projects that use Pixel Bender, you'll need to target Flash Player 10. Adobe provides a document that explains this:
Flex SDK - Targeting Flash Player 10 Beta

Shaders are powerful because they run in parallel: each pixel (or array value if you're running a ShaderJob in Flash) can be computed individually of the others. This is how shaders can run on all the available processing units simultaneously.

This pixel-independence requirement is also a limitation: not all visual effects you can build in Conduit can be expressed within the confines of a single shader. These are called multipass effects in Conduit because they require multiple passes for rendering.

Consider an effect that first applies a color correction, then a large blur, then another color correction. This is a multipass effect because the blur needs to sample multiple pixels from its source image for each pixel that it produces. Thus the first color correction must first be rendered into an intermediate (temporary) image as an individual pass, then the blur is rendered using that image as a source.

When exporting a multipass effect to Flash, Conduit will produce .PBJ shader files for all the passes except passes that represent specific sampling-based operations: blurs, min/max, convolutions, transforms. In the case of the above example, Conduit would produce shaders for the two color corrections, but the blur pass would need to be implemented using Flash's built-in Gaussian Blur filter.

Tying the shaders together to form a single filter can be accomplished with ActionScript. More specifically the BitmapData class is useful for intermediate images: each pass is rendered into a BitmapData object using the applyFilter() method. ShaderFilter can be used to render using Pixel Bender shaders. If a shader requires more than one image for input, the shader's data property allows additional images to be passed.

When your multipass filter is complete, it can be encapsulated into an ActionScript class. This allows the filter to be used just like a built-in Flash filter later on. See the following post on Mike Chambers' blog for details:
Encapsulating custom Pixel Bender filters in ActionScript 3

We're hoping to provide more specific code examples of multipass rendering in ActionScript soon!

In Flash Player 10, Pixel Bender shaders are executed on the CPU rather than the GPU mainly for compability reasons. However the performance is still very good (particularly in comparison to plain old ActionScript code!). Pixel Bender shaders are compiled on the fly to native machine code, and shader computing is distributed across all available CPU cores on multicore systems.

Tinic Uro of Adobe provides more details on his blog:
Adobe Pixel Bender in Flash Player 10

Like layers in Photoshop, all images in Flash have an alpha channel that is used to store per-pixel transparency information. However Photoshop and Flash have an important difference in how the alpha value is interpreted.

Photoshop layers use unpremultiplied (a.k.a. straight) alpha: the values of the color channels (red, green and blue) are independent of the alpha and can be modified separately. With a system that uses unpremultiplied alpha, it's possible to have (for example) a bright white pixel with zero alpha, i.e. completely transparent.

For performance reasons, Flash uses premultiplied (a.k.a. matted) alpha: the values of the color channels must be multiplied by the value of the alpha channel. For example, if the alpha value for a certain pixel is 0.5 and the red value is 0.9, the red value would be stored as 0.5 * 0.9 = 0.45.

Premultiplied alpha is used because it's very convenient for the computer, but it may feel unnatural for the user. Luckily it's not very difficult to convert between the two: you just need to apply Premultiply and Unpremultiply nodes in Conduit.

In general, if you're going to edit or replace the alpha channel of an image within Conduit, you'll want to apply Unpremultiply to the image at the start of the Conduit effect tree, then apply Premultiply at the end of the tree.

The Conduit blog covers all the Conduit products. If you have a question that you'd like to see covered on the blog, please feel free to send email to the author: pauli _at_ lacquer _dot_ fi.

dvGarage Inc, the exclusive distributor of Conduit Suite, provides video tutorials and a manual for Conduit. Practically everything in the manual applies to Conduit for Flash Pixel Bender as well.