Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DisplacementMapFilter

The DisplacementMapFilter class uses the pixel values from the specified texture (called the map texture) 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 - mapX, y - mapY).

Clamping to the Edges

Per default, the filter allows the object to grow beyond its actual bounds to make room for the displacement (depending on scaleX/Y). If you want to clamp the displacement to the actual object bounds, set all margins to zero via a call to filter.padding.setTo(). This works only with rectangular, stage-aligned objects, though.

Hierarchy

Index

Constructors

constructor

  • new DisplacementMapFilter(mapTexture: Texture, componentX?: number, componentY?: number, scaleX?: number, scaleY?: number): DisplacementMapFilter

Properties

alwaysDrawToBackBuffer

alwaysDrawToBackBuffer: boolean

Indicates if the last filter pass is always drawn directly to the back buffer.

Per default, the filter tries to automatically render in a smart way: objects that are currently moving are rendered to the back buffer, objects that are static are rendered into a texture first, which allows the filter to be drawn directly from the render cache in the next frame (in case the object remains static).

However, this fails when filters are added to an object that does not support the render cache, or to a container with such a child (e.g. a Sprite3D object or a masked display object). In such a case, enable this property for maximum performance.

@default false

antiAliasing

antiAliasing: number

The anti-aliasing level. This is only used for rendering the target object into a texture, not for the filter passes. 0 - none, 4 - maximum. @default 0

componentX

componentX: number

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

componentY

componentY: number

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

dispEffect

isCached

isCached: boolean

Indicates if the filter is cached (via the cache method).

Protected maintainResolutionAcrossPasses

maintainResolutionAcrossPasses: boolean

Indicates if the filter requires all passes to be processed with the exact same resolution.

Some filters must use the same resolution for input and output; e.g. the blur filter is very sensitive to changes of pixel / texel sizes. When the filter is used as part of a filter chain, or if its last pass is drawn directly to the back buffer, such a filter produces artifacts. In that case, the filter author must set this property to true.

@default false

mapRepeat

mapRepeat: boolean

Indicates if pixels at the edge of the map texture will be repeated. Note that this only works if the map texture is a power-of-two texture!

mapTexture

mapTexture: Texture

The texture that will be used to calculate displacement.

mapX

mapX: number

The horizontal offset of the map texture relative to the origin. @default 0

mapY

mapY: number

The vertical offset of the map texture relative to the origin. @default 0

padding

padding: Padding

Padding can extend the size of the filter texture in all directions. That's useful when the filter "grows" the bounds of the object in any direction.

resolution

resolution: number

The resolution of the filter texture. "1" means stage resolution, "0.5" half the stage resolution. A lower resolution saves memory and execution time, but results in a lower output quality. Values greater than 1 are allowed; such values might make sense for a cached filter when it is scaled up. @default 1

scaleX

scaleX: number

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

scaleY

scaleY: number

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

textureFormat

textureFormat: string

The format of the filter texture. @default BGRA

textureSmoothing

textureSmoothing: string

The smoothing mode of the filter texture. @default bilinear

Methods

Protected addEventListener

  • addEventListener(type: string, listener: Function): void

cache

  • cache(): void
  • Caches the filter output into a texture.

    An uncached filter is rendered every frame (except if it can be rendered from the global render cache, which happens if the target object does not change its appearance or location relative to the stage). A cached filter is only rendered once; the output stays unchanged until you call cache again or change the filter settings.

    Beware: you cannot cache filters on 3D objects; if the object the filter is attached to is a Sprite3D or has a Sprite3D as (grand-) parent, the request will be silently ignored. However, you can cache a 2D object that has 3D children!

    Returns void

clearCache

  • clearCache(): void

dispatchEvent

  • dispatchEvent(event: Event): void
  • Dispatches an event to all objects that have registered listeners for its type. If an event with enabled 'bubble' property is dispatched to a display object, it will travel up along the line of parents, until it either hits the root object or someone stops its propagation manually.

    Parameters

    Returns void

dispatchEventWith

  • dispatchEventWith(type: string, bubbles?: boolean, data?: any): void

dispose

  • dispose(): void

Protected get_alwaysDrawToBackBuffer

  • get_alwaysDrawToBackBuffer(): boolean

Protected get_antiAliasing

  • get_antiAliasing(): number

Protected get_componentX

  • get_componentX(): number

Protected get_componentY

  • get_componentY(): number

Protected get_dispEffect

Protected get_isCached

  • get_isCached(): boolean

Protected get_maintainResolutionAcrossPasses

  • get_maintainResolutionAcrossPasses(): boolean

Protected get_mapRepeat

  • get_mapRepeat(): boolean

Protected get_mapTexture

Protected get_mapX

  • get_mapX(): number

Protected get_mapY

  • get_mapY(): number

Protected get_padding

Protected get_resolution

  • get_resolution(): number

Protected get_scaleX

  • get_scaleX(): number

Protected get_scaleY

  • get_scaleY(): number

Protected get_textureFormat

  • get_textureFormat(): string

Protected get_textureSmoothing

  • get_textureSmoothing(): string

hasEventListener

  • hasEventListener(type: string, listener?: any): boolean

Protected process

Protected removeEventListener

  • removeEventListener(type: string, listener: Function): void

removeEventListeners

  • removeEventListeners(type?: string): void

render

Protected set_alwaysDrawToBackBuffer

  • set_alwaysDrawToBackBuffer(value: boolean): boolean

Protected set_antiAliasing

  • set_antiAliasing(value: number): number

Protected set_componentX

  • set_componentX(value: number): number

Protected set_componentY

  • set_componentY(value: number): number

Protected set_maintainResolutionAcrossPasses

  • set_maintainResolutionAcrossPasses(value: boolean): boolean

Protected set_mapRepeat

  • set_mapRepeat(value: boolean): boolean

Protected set_mapTexture

Protected set_mapX

  • set_mapX(value: number): number

Protected set_mapY

  • set_mapY(value: number): number

Protected set_padding

Protected set_resolution

  • set_resolution(value: number): number

Protected set_scaleX

  • set_scaleX(value: number): number

Protected set_scaleY

  • set_scaleY(value: number): number

Protected set_textureFormat

  • set_textureFormat(value: string): string

Protected set_textureSmoothing

  • set_textureSmoothing(value: string): string

Generated using TypeDoc