flash.display

# ShaderData - AS3

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

Language Version: | ActionScript 3.0

Runtime Versions: | Flash Player 10, AIR 1.5

A ShaderData object contains properties representing any parameters and inputs for a shader kernel, as well as properties containing any metadata specified for the shader.

These properties are added to the ShaderData object when it is created. The properties' names match the names specified in the shader's source code. The data type of each property varies according to what aspect of the shader the property represents. The properties that represent shader parameters are ShaderParameter instances, the properties that represent input images are ShaderInput instances, and the properties that represent shader metadata are instances of the ActionScript class corresponding to their data type (for example, a String instance for textual metadata and a uint for uint metadata).

For example, consider this shader, which is defined with one input image (`src`), two parameters (`size` and `radius`), and three metadata values (`nameSpace`, `version`, and `description`):

Copy

         <languageVersion : 1.0;>

         kernel DoNothing
         <
             namespace: "Adobe::Example";
             vendor: "Adobe examples";
             version: 1;
             description: "A shader that does nothing, but does it well.";
         >
         {
             input image4 src;

             output pixel4 dst;

             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;
             >;

             void evaluatePixel()
             {
                 float2 one = (radius / radius) ∗ (size / size);
                 dst = sampleNearest(src, outCoord());
             }
         }

If you create a Shader instance by loading the byte code for this shader, the ShaderData instance in its `data` property contains these properties:

Property | Data type | Value
--- | --- | ---
name | String | "DoNothing"
nameSpace | String | "Adobe::Example"
version | String | "1"
description | String | "A shader that does nothing, but does it well."
src | ShaderInput | [A ShaderInput instance]
size | ShaderParameter | [A ShaderParameter instance, with properties for the parameter metadata]
radius | ShaderParameter | [A ShaderParameter instance, with properties for the parameter metadata]

Note that any input image or parameter that is defined in the shader source code but not used in the shader's `evaluatePixel()` function is removed when the shader is compiled to byte code. In that case, there is no corresponding ShaderInput or ShaderParameter instance added as a property of the ShaderData instance.

Generally, developer code does not create a ShaderData instance. A ShaderData instance containing data, parameters, and inputs for a shader is available as the Shader instance's `data` property.

View the examples

More examples

Accessing shader metadata
Identifying shader inputs and parameters

Related API Elements

flash.display.Shader.data
flash.display.ShaderInput
flash.display.ShaderParameter

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

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | ShaderData(byteCode:ByteArray) Creates a ShaderData instance. | ShaderData
|  | 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

Constructor Detail

### ShaderData

()
Constructor

`public function ShaderData(byteCode:ByteArray)`

Language Version: | ActionScript 3.0

Runtime Versions: | Flash Player 10, AIR 1.5

Creates a ShaderData instance. Generally, developer code does not call the ShaderData constructor directly. A ShaderData instance containing data, parameters, and inputs for a Shader instance is accessed using its `data` property.

Parameters

| `byteCode:ByteArray` — The shader's byte code.

Related API Elements

flash.display.Shader.data
Examples How to use this example
ShaderDataExample.1.as
The following example loads a shader and enumerates the ShaderData instance in its `data` property to display the input, parameters, and metadata properties of the shader.

Note that this example assumes there's a shader bytecode file named "donothing.pbj" in the same directory as the output directory for the application.

Copy

    //
    // Source code for the shader:
    //
    <languageVersion : 1.0;>

    kernel DoNothing
    <
        namespace: "Adobe::Example";
        vendor: "Adobe examples";
        version: 1;
        description: "A shader that does nothing, but does it well.";
    >
    {
        input image4 src;

        output pixel4 dst;

        parameter float2 size
        <
            description: "The size of the image to which the shader 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: float(0.0);
            maxValue: float(50.0);
            defaultValue: float(25.0);
        >;

        void evaluatePixel()
        {
            float2 one = (radius / radius) * (size / size);
            dst = sampleNearest(src, outCoord());
        }
    }

    //
    // ActionScript source code:
    //
    package {
        import flash.display.Shader;
        import flash.display.Sprite;
        import flash.events.Event;
        import flash.net.URLLoader;
        import flash.net.URLLoaderDataFormat;
        import flash.net.URLRequest;

        public class ShaderDataExample extends Sprite {

            private var loader:URLLoader;

            public function ShaderDataExample() {
                loader = new URLLoader();
                loader.dataFormat = URLLoaderDataFormat.BINARY;
                loader.addEventListener(Event.COMPLETE, loadCompleteHandler);
                loader.load(new URLRequest("donothing.pbj"));
            }

            private function loadCompleteHandler(event:Event):void {
                var shader:Shader = new Shader();
                shader.byteCode = loader.data;

                for (var p:String in shader.data) {
                    trace(p, ":", shader.data[p]);
                    for (var d:String in shader.data[p]) {
                        trace("\t", d, ":", shader.data[p][d]);
                    }
                }
            }
        }
    }

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