|
Flash CS4 Resources |
Specifying shader input valuesMany shaders expect one or more input images that are used in the shader processing. However, in many cases an input is specified automatically when the Shader object is used. For example, suppose a shader requires one input, and that shader is used as a filter. When the filter is applied to a display object or BitmapData object, that object is automatically set as the input. In that case you do not explicitly set an input value. However, in some cases, especially if a shader defines multiple inputs, you do explicitly set a value for an input. Each input that is defined in a shader is represented in ActionScript by a ShaderInput object. The ShaderInput object is a property of the ShaderData instance in the Shader object’s data property, as described in Identifying shader inputs and parameters. For example, suppose a shader defines an input named src , and that shader is linked to a Shader object named myShader . In that case you access the ShaderInput object corresponding to the src input using the following identifier: myShader.data.src Each ShaderInput object has an input property that is used to set the value for the input. You set the input property to a BitmapData instance to specify image data. You can also set the input property to a BitmapData or Vector.<Number> instance to specify binary or number data. For details and restrictions on using a BitmapData or Vector.<Number> instance as an input, see the ShaderInput.input listing in the language reference. In addition to the input property, a ShaderInput object has properties that can be used to determine what type of image the input expects. These properties include the width , height , and channels properties. Each ShaderInput object also has an index property that is useful for determining whether an explicit value must be provided for the input. If a shader expects more inputs than the number that are automatically set, then you set values for those inputs. For details on the different ways to use a shader, and whether input values are automatically set, see Using a shader. |