extended by Context3DMaskShader, DisplayObjectShader, GraphicsShader, BitmapFilterShader
Available on all platforms
// TODO: Document GLSL Shaders
A Shader instance represents a Pixel Bender shader kernel in ActionScript.
To use a shader in your application, you create a Shader instance for it.
You then use that Shader instance in the appropriate way according to the
effect you want to create. For example, to use the shader as a filter, you
assign the Shader instance to the
shader property of a ShaderFilter
A shader defines a function that executes on all the pixels in an image,
one pixel at a time. The result of each call to the function is the output
color at that pixel coordinate in the image. A shader can specify one or
more input images, which are images whose content can be used in
determining the output of the function. A shader can also specify one or
more parameters, which are input values that can be used in calculating
the function output. In a single shader execution, the input and parameter
values are constant. The only thing that varies is the coordinate of the
pixel whose color is the function result. Shader function calls for
multiple output pixel coordinates execute in parallel to improve shader
The shader bytecode can be loaded at run time using a URLLoader instance.
The following example demonstrates loading a shader bytecode file at run
time and linking it to a Shader instance.
You can also embed the shader into the SWF at compile time using the
metadata tag. The [Embed]
metadata tag is only available if
you use the Flex SDK to compile the SWF. The [Embed]
parameter points to the shader file, and its mimeType
, as in this example:
<codeblock xml:space="preserve"> [Embed(source="myShader.pbj",
mimeType="application/octet-stream)] var MyShaderClass:Class; // ... //
create a new shader and set the embedded shader as its bytecode var
shaderShader = new Shader(); shader.byteCode = new MyShaderClass(); // You
can also pass the bytecode to the Shader() constructor like this: // var
shader:Shader = new Shader(new MyShaderClass()); // do something with the
In either case, you link the raw shader (the
URLLoader.data property or
an instance of the
[Embed] data class) to the Shader instance. As the
previous examples demonstrate, you can do this in two ways. You can pass
the shader bytecode as an argument to the
Alternatively, you can set it as the Shader instance's
Once a Shader instance is created, it can be used in one of several ways:
- A shader fill: The output of the shader is used as a fill for content
drawn with the drawing API. Pass the Shader instance as an argument to the
- A shader filter: The output of the shader is used as a graphic filter
applied to a display object. Assign the Shader instance to the
shaderproperty of a ShaderFilter instance.
- A blend mode: The output of the shader is rendered as the blending
between two overlapping display objects. Assign the Shader instance to the
blendShaderproperty of the upper of the two display objects.
- Background shader processing: The shader executes in the background,
avoiding the possibility of freezing the display, and dispatches an event
when processing is complete. Assign the Shader instance to the
shaderproperty of a ShaderJob instance.
Shader fills, filters, and blends are not supported under GPU rendering.
Mobile Browser Support: This feature is not supported in mobile browsers.
AIR profile support: This feature is supported on all desktop operating systems, but it is not supported on all mobile devices. It is not supported on AIR for TV devices. See <a href="http://help.adobe.com/en_US/air/build/WS144092a96ffef7cc16ddeea2126bb46b82f-8000.html"> AIR Profile Support for more information regarding API support across multiple profiles.
Provides access to parameters, input images, and metadata for the
Shader instance. ShaderParameter objects representing parameters for
the shader, ShaderInput objects representing the input images for the
shader, and other values representing the shader's metadata are
dynamically added as properties of the
data property object when the
Shader instance is created. Those properties can be used to introspect
the shader and to set parameter and input values.
For information about accessing and manipulating the dynamic
properties of the
data object, see the ShaderData class description.
The precision of math operations performed by the shader.
The set of possible values for the
precisionHint property is defined
by the constants in the ShaderPrecision class.
The default value is
ShaderPrecision.FULL. Setting the precision to
ShaderPrecision.FAST can speed up math operations at the expense of
Full precision mode (
ShaderPrecision.FULL) computes all math
operations to the full width of the IEEE 32-bit floating standard and
provides consistent behavior on all platforms. In this mode, some math
operations such as trigonometric and exponential functions can be
Fast precision mode (
ShaderPrecision.FAST) is designed for maximum
performance but does not work consistently on different platforms and
individual CPU configurations. In many cases, this level of precision
is sufficient to create graphic effects without visible artifacts.
The precision mode selection affects the following shader operations. These operations are faster on an Intel processor with the SSE instruction set: