flash.display

# ShaderParameter - AS3

Package | flash.display
Class | public final dynamic class ShaderParameter
Inheritance | ShaderParameter Object

Language Version: | ActionScript 3.0

Runtime Versions: | Flash Player 10, AIR 1.5

A ShaderParameter instance represents a single input parameter of a shader kernel. A kernel can be defined to accept zero, one, or more parameters that are used in the kernel execution. A ShaderParameter provides information about the parameter, such as the type of data it expects. It also provides a mechanism for setting the parameter value that is used when the shader executes. To specify a value or values for the shader parameter, create an Array containing the value or values and assign it to the `value` property.

A ShaderParameter instance representing a parameter for a Shader instance is accessed as a property of the Shader instance's `data` property. The ShaderParameter property has the same name as the parameter's name in the shader code. For example, if a shader defines a parameter named `radius`, the ShaderParameter instance representing the `radius` parameter is available as the `radius` property, as shown here:

Copy

    var radiusParam:ShaderParameter = myShader.data.radius;

In addition to the defined properties of the ShaderParameter class, each ShaderParameter instance has additional properties corresponding to any metadata defined for the parameter. These properties are added to the ShaderParameter object when it is created. The properties' names match the metadata names specified in the shader's source code. The data type of each property varies according to the data type of the corresponding metadata. A text metadata value such as "description" is a String instance. A metadata property with a non-string value (such as `minValue` or `defaultValue`) is represented as an Array instance. The number of elements and element data types correspond to the metadata values.

For example, suppose a shader includes the following two parameter declarations:

Copy

         parameter float2 size
         <
             description: "The size of the image to which the kernel is applied";
             minValue: float2(0.0, 0.0);
             maxValue: float2(100.0, 100.0);
             defaultValue: float2(50.0, 50.0);
         >;

         parameter float radius
         <
             description: "The radius of the effect";
             minValue: 0.0;
             maxValue: 50.0;
             defaultValue: 25.0;
         >;

The ShaderParameter instance corresponding to the `size` parameter has the following metadata properties in addition to its built-in properties:

Property name | Data type | Value
--- | --- | ---
`name` | String | `"size"`
`description` | String | `"The size of the image to which the kernel is applied"`
`minValue` | Array | `[0, 0]`
`maxValue` | Array | `[100, 100]`
`defaultValue` | Array | `[50, 50]`

The ShaderParameter corresponding to the `radius` parameter has the following additional properties:

Property name | Data type | Value
--- | --- | ---
`name` | String | `"radius"`
`description` | String | `"The radius of the effect"`
`minValue` | Array | `[0]`
`maxValue` | Array | `[50]`
`defaultValue` | Array | `[25]`

Generally, developer code does not create a ShaderParameter instance directly. A ShaderParameter instance is created for each of a shader's parameters when the Shader instance is created.

More examples

Specifying shader parameter values

Related API Elements

flash.display.ShaderData
flash.display.Shader.data

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | constructor : Object A reference to the class object or constructor function for a given object instance. | Object
|  | index : int [read-only] The zero-based index of the parameter. | ShaderParameter
|  | type : String [read-only] The data type of the parameter as defined in the shader. | ShaderParameter
|  | value : Array The value or values that are passed in as the parameter value to the shader. | ShaderParameter

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | ShaderParameter() Creates a ShaderParameter instance. | ShaderParameter
|  | hasOwnProperty(name:String):Boolean Indicates whether an object has a specified property defined. | Object
|  | isPrototypeOf(theClass:Object):Boolean Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter. | Object
|  | propertyIsEnumerable(name:String):Boolean Indicates whether the specified property exists and is enumerable. | Object
|  | setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void Sets the availability of a dynamic property for loop operations. | Object
|  | toLocaleString():String Returns the string representation of this object, formatted according to locale-specific conventions. | Object
|  | toString():String Returns the string representation of the specified object. | Object
|  | valueOf():Object Returns the primitive value of the specified object. | Object

Property Detail

### index

property

`index:int` [read-only]

Language Version: | ActionScript 3.0

Runtime Versions: | Flash Player 10, AIR 1.5

The zero-based index of the parameter.

Implementation
`public function get index():int`

### type

property

`type:String` [read-only]

Language Version: | ActionScript 3.0

Runtime Versions: | Flash Player 10, AIR 1.5

The data type of the parameter as defined in the shader. The set of possible values for the `type` property is defined by the constants in the ShaderParameterType class.

Implementation
`public function get type():String`

Related API Elements

flash.display.ShaderParameterType

### value

property

`value:Array`

Language Version: | ActionScript 3.0

Runtime Versions: | Flash Player 10, AIR 1.5

The value or values that are passed in as the parameter value to the shader. The `value` property is an indexed Array. The number and type of the elements of the Array correspond to the data type of the parameter, which can be determined using the `type` property.

The following table indicates the parameter type and corresponding number and data type of the `value` Array's elements:

Parameter type | # Elements | Element data type
--- | --- | ---
float (`ShaderParameterType.FLOAT`) | 1 | Number
float2 (`ShaderParameterType.FLOAT2`) | 2 | Number
float3 (`ShaderParameterType.FLOAT3`) | 3 | Number
float4 (`ShaderParameterType.FLOAT4`) | 4 | Number
int (`ShaderParameterType.INT`) | 1 | int or uint
int2 (`ShaderParameterType.INT2`) | 2 | int or uint
int3 (`ShaderParameterType.INT3`) | 3 | int or uint
int4 (`ShaderParameterType.INT4`) | 4 | int or uint
bool (`ShaderParameterType.BOOL`) | 1 | Boolean
bool2 (`ShaderParameterType.BOOL2`) | 2 | Boolean
bool3 (`ShaderParameterType.BOOL3`) | 3 | Boolean
bool4 (`ShaderParameterType.BOOL4`) | 4 | Boolean
float2x2 (`ShaderParameterType.MATRIX2X2`) | 4 | Number
float3x3 (`ShaderParameterType.MATRIX3X3`) | 9 | Number
float4x4 (`ShaderParameterType.MATRIX4X4`) | 16 | Number

For the matrix parameter types, the array elements fill the rows of the matrix, then the columns. For example, suppose the following line of ActionScript is used to fill a `float2x2` parameter named `myMatrix`:

Copy

    myShader.data.myMatrix.value = [.1, .2, .3, .4];

Within the shader, the matrix elements have the following values:

- `myMatrix[0][0]`: .1
- `myMatrix[0][1]`: .2
- `myMatrix[1][0]`: .3
- `myMatrix[1][1]`: .4

Implementation
`public function get value():Array`
`public function set value(value:Array):void`
Constructor Detail

### ShaderParameter

()
Constructor

`public function ShaderParameter()`

Language Version: | ActionScript 3.0

Runtime Versions: | Flash Player 10, AIR 1.5

Creates a ShaderParameter instance. Developer code does not call the ShaderParameter constructor directly. A ShaderParameter instance is created for each of a shader's parameters when the Shader instance is created.

© 2015 Adobe Systems Incorporated. All rights reserved.
Mon Apr 10 2017, 12:28 PM -07:00