UNPKG

starling-framework

Version:

A fast, productive library for 2D cross-platform development.

105 lines 4.38 kB
import Texture from "../textures/Texture"; import Painter from "../rendering/Painter"; import IFilterHelper from "./IFilterHelper"; import FragmentFilter from "./FragmentFilter"; import DisplacementMapEffect from "./DisplacementMapEffect"; declare namespace starling.filters { /** * 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. * * * * <p>The filter uses the following formula:</p> * * <listing>dstPixel[x, y] = srcPixel[x + ((componentX(x, y) - 128) &#42; scaleX) / 256, * * y + ((componentY(x, y) - 128) &#42; scaleY) / 256] * * </listing> * * * * <p>Where <code>componentX(x, y)</code> gets the componentX property color value from the * * map texture at <code>(x - mapX, y - mapY)</code>.</p> * * * * <strong>Clamping to the Edges</strong> * * * * <p>Per default, the filter allows the object to grow beyond its actual bounds to make * * room for the displacement (depending on <code>scaleX/Y</code>). If you want to clamp the * * displacement to the actual object bounds, set all margins to zero via a call to * * <code>filter.padding.setTo()</code>. This works only with rectangular, stage-aligned * * objects, though.</p> * */ export class DisplacementMapFilter extends FragmentFilter { /** * Creates a new displacement map filter that uses the provided map texture. * * * * @param mapTexture The texture containing the displacement map data. * * @param componentX Describes which color channel to use in the map image to displace * * the x result. Possible values are the BitmapDataChannel constants. * * @param componentY Describes which color channel to use in the map image to displace * * the y result. Possible values are the BitmapDataChannel constants. * * @param scaleX The multiplier used to scale the x displacement result. * * @param scaleY The multiplier used to scale the y displacement result. * */ constructor(mapTexture: Texture, componentX?: number, componentY?: number, scaleX?: number, scaleY?: number); /** * @private */ override process(painter: Painter, pool: IFilterHelper, input0?: Texture, input1?: Texture, input2?: Texture, input3?: Texture): Texture; /** * Describes which color channel to use in the map image to displace the x result. * * Possible values are constants from the BitmapDataChannel class. */ get componentX(): number; set componentX(value: number) /** * Describes which color channel to use in the map image to displace the y result. * * Possible values are constants from the BitmapDataChannel class. */ get componentY(): number; set componentY(value: number) /** * The multiplier used to scale the x displacement result from the map calculation. */ get scaleX(): number; set scaleX(value: number) /** * The multiplier used to scale the y displacement result from the map calculation. */ get scaleY(): number; set scaleY(value: number) /** * The horizontal offset of the map texture relative to the origin. @default 0 */ get mapX(): number; set mapX(value: number) /** * The vertical offset of the map texture relative to the origin. @default 0 */ get mapY(): number; set mapY(value: number) /** * The horizontal scale applied to the map texture. @default 1 */ get mapScaleX(): number; set mapScaleX(value: number) /** * The vertical scale applied to the map texture. @default 1 */ get mapScaleY(): number; set mapScaleY(value: number) /** * The texture that will be used to calculate displacement. */ get mapTexture(): Texture; set mapTexture(value: Texture) /** * 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! * */ get mapRepeat(): boolean; set mapRepeat(value: boolean) get dispEffect(): DisplacementMapEffect; } } export default starling.filters.DisplacementMapFilter;