GODPAPER | All Packages | All Classes | Index | Frames No Frames |
DisplacementMapFilter

Package | starling.filters
Class | public class DisplacementMapFilter
Inheritance | DisplacementMapFilter FragmentFilter Object

The DisplacementMapFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. You can use this filter to apply a warped or mottled effect to any object that inherits from the DisplayObject class.

The filter uses the following formula:

    dstPixel[x, y] = srcPixel[x + ((componentX(x, y) - 128) * scaleX) / 256,
                              y + ((componentY(x, y) - 128) * scaleY) / 256)]

Where `componentX(x, y)` gets the componentX property color value from the map texture at `(x - mapPoint.x, y - mapPoint.y)`.

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | componentX : uint Describes which color channel to use in the map image to displace the x result. | DisplacementMapFilter
|  | componentY : uint Describes which color channel to use in the map image to displace the y result. | DisplacementMapFilter
|  | isCached : Boolean [read-only] Indicates if the filter is cached (via the "cache" method). | FragmentFilter
|  | mapPoint : Point A value that contains the offset of the upper-left corner of the target display object from the upper-left corner of the map image. | DisplacementMapFilter
|  | mapTexture : Texture The texture that will be used to calculate displacement. | DisplacementMapFilter
|  | mode : String The filter mode, which is one of the constants defined in the "FragmentFilterMode" class. | FragmentFilter
|  | offsetX : Number Use the x-offset to move the filter output to the right or left. | FragmentFilter
|  | offsetY : Number Use the y-offset to move the filter output to the top or bottom. | FragmentFilter
|  | repeat : Boolean Indicates how the pixels at the edge of the input image (the filtered object) will be wrapped at the edge. | DisplacementMapFilter
|  | resolution : Number The resolution of the filter texture. | FragmentFilter
|  | scaleX : Number The multiplier used to scale the x displacement result from the map calculation. | DisplacementMapFilter
|  | scaleY : Number The multiplier used to scale the y displacement result from the map calculation. | DisplacementMapFilter

Protected Properties
Hide Inherited Protected Properties
Show Inherited Protected Properties

| Property | Defined By
--- | --- | ---
|  | baseTextureID : int The ID (sampler) of the input texture (containing the output of the previous pass). | FragmentFilter
|  | marginX : Number The x-margin will extend the size of the filter texture along the x-axis. | FragmentFilter
|  | marginY : Number The y-margin will extend the size of the filter texture along the y-axis. | FragmentFilter
|  | mvpConstantID : int The ID of the first register of the modelview-projection constant (a 4x4 matrix). | FragmentFilter
|  | numPasses : int The number of passes the filter is applied. | FragmentFilter
|  | texCoordsAtID : int The ID of the vertex buffer attribute that stores the texture coordinates. | FragmentFilter
|  | vertexPosAtID : int The ID of the vertex buffer attribute that stores the vertex position. | FragmentFilter

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | DisplacementMapFilter(mapTexture:Texture, mapPoint:Point = null, componentX:uint = 0, componentY:uint = 0, scaleX:Number = 0.0, scaleY:Number = 0.0, repeat:Boolean = false) Creates a new displacement map filter that uses the provided map texture. | DisplacementMapFilter
|  | cache():void Caches the filter output into a texture. | FragmentFilter
|  | clearCache():void Clears the cached output of the filter. | FragmentFilter
|  | dispose():void [override] Disposes the filter (programs, buffers, textures). | DisplacementMapFilter
|  | render(object:DisplayObject, support:RenderSupport, parentAlpha:Number):void Applies the filter on a certain display object, rendering the output into the current render target. | FragmentFilter

Protected Methods
Show Inherited Protected Methods
Show Inherited Protected Methods

| Method | Defined By
--- | --- | ---
|  | activate(pass:int, context:Context3D, texture:Texture):void Subclasses must override this method and use it to activate their fragment- and to vertext-programs. | FragmentFilter
|  | assembleAgal(fragmentShader:String = null, vertexShader:String = null):Program3D Assembles fragment- and vertex-shaders, passed as Strings, to a Program3D. | FragmentFilter
|  | createPrograms():void Subclasses must override this method and use it to create their fragment- and vertex-programs. | FragmentFilter
|  | deactivate(pass:int, context:Context3D, texture:Texture):void This method is called directly after 'context.drawTriangles'. | FragmentFilter

Protected Constants
Hide Inherited Protected Constants
Show Inherited Protected Constants

| Constant | Defined By
--- | --- | ---
|  | PMA : Boolean = true All filter processing is expected to be done with premultiplied alpha. | FragmentFilter
|  | STD_FRAGMENT_SHADER : String = tex oc, v0, fs0 <2d, clamp, linear, mipnone> The standard fragment shader code. | FragmentFilter
|  | STD_VERTEX_SHADER : String The standard vertex shader code. | FragmentFilter

Property Detail

componentX | property

`componentX:uint`

Describes which color channel to use in the map image to displace the x result. Possible values are constants from the BitmapDataChannel class.

Implementation
`public function get componentX():uint`
`public function set componentX(value:uint):void`

componentY | property |

`componentY:uint`

Describes which color channel to use in the map image to displace the y result. Possible values are constants from the BitmapDataChannel class.

Implementation
`public function get componentY():uint`
`public function set componentY(value:uint):void`

mapPoint | property |

`mapPoint:Point`

A value that contains the offset of the upper-left corner of the target display object from the upper-left corner of the map image.

Implementation
`public function get mapPoint():Point`
`public function set mapPoint(value:Point):void`

mapTexture | property |

`mapTexture:Texture`

The texture that will be used to calculate displacement.

Implementation
`public function get mapTexture():Texture`
`public function set mapTexture(value:Texture):void`

repeat | property |

`repeat:Boolean`

Indicates how the pixels at the edge of the input image (the filtered object) will be wrapped at the edge.

Implementation
`public function get repeat():Boolean`
`public function set repeat(value:Boolean):void`

scaleX | property |

`scaleX:Number`

The multiplier used to scale the x displacement result from the map calculation.

Implementation
`public function get scaleX():Number`
`public function set scaleX(value:Number):void`

scaleY | property |

`scaleY:Number`

The multiplier used to scale the y displacement result from the map calculation.

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

DisplacementMapFilter | () | Constructor

`public function DisplacementMapFilter(mapTexture:Texture, mapPoint:Point = null, componentX:uint = 0, componentY:uint = 0, scaleX:Number = 0.0, scaleY:Number = 0.0, repeat:Boolean = false)`

Creates a new displacement map filter that uses the provided map texture.

Parameters

| `mapTexture:Texture`
| `mapPoint:Point` (default = `null`)``
| `componentX:uint` (default = `0`)``
| `componentY:uint` (default = `0`)``
| `scaleX:Number` (default = `0.0`)``
| `scaleY:Number` (default = `0.0`)``
| `repeat:Boolean` (default = `false`)``

Method Detail

dispose | () | method

`override public function dispose():void`

Disposes the filter (programs, buffers, textures).

Thu Jan 16 2014, 01:11 PM +08:00