13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Working with Pixel B<strong>en</strong>der shaders<br />

var shaderData:ShaderData = myShader.data;<br />

var inputs:Vector. = new Vector.();<br />

var parameters:Vector. = new Vector.();<br />

var metadata:Vector. = new Vector.();<br />

for (var prop:String in shaderData)<br />

{<br />

if (shaderData[prop] is ShaderInput)<br />

{<br />

inputs[inputs.l<strong>en</strong>gth] = shaderData[prop];<br />

}<br />

else if (shaderData[prop] is ShaderParameter)<br />

{<br />

parameters[parameters.l<strong>en</strong>gth] = shaderData[prop];<br />

}<br />

else<br />

{<br />

metadata[metadata.l<strong>en</strong>gth] = shaderData[prop];<br />

}<br />

}<br />

// do something with the inputs or properties<br />

Specifying shader input values<br />

Flash Player 10 and later, Adobe AIR 1.5 and later<br />

Many shaders expect one or more input images that are used in the shader processing. However, in many cases an<br />

input is specified automatically wh<strong>en</strong> the Shader object is used. For example, suppose a shader requires one input, and<br />

that shader is used as a filter. Wh<strong>en</strong> the filter is applied to a display object or BitmapData object, that object is<br />

automatically set as the input. In that case you do not explicitly set an input value.<br />

However, in some cases, especially if a shader defines multiple inputs, you do explicitly set a value for an input. Each<br />

input that is defined in a shader is repres<strong>en</strong>ted in ActionScript by a ShaderInput object. The ShaderInput object is a<br />

property of the ShaderData instance in the Shader object’s data property, as described in “Id<strong>en</strong>tifying shader inputs<br />

and parameters” on page 305. For example, suppose a shader defines an input named src, and that shader is linked to<br />

a Shader object named myShader. In that case you access the ShaderInput object corresponding to the src input using<br />

the following id<strong>en</strong>tifier:<br />

myShader.data.src<br />

Each ShaderInput object has an input property that is used to set the value for the input. You set the input property<br />

to a BitmapData instance to specify image data. You can also set the input property to a BitmapData or<br />

Vector. instance to specify binary or number data. For details and restrictions on using a BitmapData or<br />

Vector. instance as an input, see the ShaderInput.input listing in the ActionScript 3.0 Refer<strong>en</strong>ce for the<br />

Adobe Flash Platform.<br />

In addition to the input property, a ShaderInput object has properties that can be used to determine what type of<br />

image the input expects. These properties include the width, height, and channels properties. Each ShaderInput<br />

object also has an index property that is useful for determining whether an explicit value must be provided for the<br />

input. If a shader expects more inputs than the number that are automatically set, th<strong>en</strong> you set values for those inputs.<br />

For details on the differ<strong>en</strong>t ways to use a shader, and whether input values are automatically set, see “Using a shader”<br />

on page 310.<br />

Last updated 6/6/2012<br />

306

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!