If enabled, PixiJS will fit the filter area into boundaries for better performance. Switch it off if it does not work for specific shader.
true
If enabled is true the filter is applied, if false it will not.
Readonly
legacyLegacy filters use position and uvs from attributes (set by filter system)
The samples override of the filter instance.
If set to null
, the sample count of the current render target is used.
PIXI.Filter.defaultMultisample
The padding of the filter. Some filters require extra space to breath such as a blur. Increasing this will add extra width and height to the bounds of the object that the filter is applied to.
Program that the shader uses.
The WebGL state the filter requires to render.
Static
SOURCE_Used for caching shader IDs.
Static
defaultDefault filter samples for any filter.
PIXI.MSAA_QUALITY.NONE
Static
defaultDefault filter resolution for any filter.
Sets the blend mode of the filter.
PIXI.BLEND_MODES.NORMAL
The resolution of the filter. Setting this to be lower will lower the quality but
increase the performance of the filter.
If set to null
or 0
, the resolution of the current render target is used.
PIXI.Filter.defaultResolution
Static
defaultThe default fragment shader source
Static
defaultThe default vertex shader source
Applies the filter
The renderer to retrieve the filter from
The input render target.
The target to output to.
Optional
clearMode: CLEAR_MODESShould the output be cleared before rendering to it.
Optional
_currentState: FilterStateIt's current state of filter. There are some useful properties in the currentState : target, filters, sourceFrame, destinationFrame, renderTarget, resolution
Static
fromA short hand function to create a shader based of a vertex and fragment shader.
Optional
vertexSrc: stringThe source of the vertex shader.
Optional
fragmentSrc: stringThe source of the fragment shader.
Optional
uniforms: Dict<any>Custom uniforms to use to augment the built-in ones.
A shiny new PixiJS shader!
Generated using TypeDoc
A filter is a special shader that applies post-processing effects to an input texture and writes into an output render-target.
Example of the PIXI.BlurFilter BlurFilter.
Usage
Filters can be applied to any DisplayObject or Container. PixiJS'
FilterSystem
renders the container into temporary Framebuffer, then filter renders it to the screen. Multiple filters can be added to thefilters
array property and stacked on each other.Previous Version Differences
In PixiJS v3, a filter was always applied to whole screen.
In PixiJS v4, a filter can be applied only part of the screen. Developers had to create a set of uniforms to deal with coordinates.
In PixiJS v5 combines both approaches. Developers can use normal coordinates of v3 and then allow filter to use partial Framebuffers, bringing those extra uniforms into account.
Also be aware that we have changed default vertex shader, please consult Wiki.
Frames
The following table summarizes the coordinate spaces used in the filtering pipeline:
Built-in Uniforms
PixiJS viewport uses screen (CSS) coordinates,
(0, 0, renderer.screen.width, renderer.screen.height)
, andprojectionMatrix
uniform maps it to the gl viewport.uSampler
The most important uniform is the input texture that container was rendered into. Important note: as with all Framebuffers in PixiJS, both input and output are premultiplied by alpha.
By default, input normalized coordinates are passed to fragment shader with
vTextureCoord
. Use it to sample the input.This filter is just one uniform less than PIXI.AlphaFilter AlphaFilter.
outputFrame
The
outputFrame
holds the rectangle where filter is applied in screen (CSS) coordinates. It's the same asrenderer.screen
for a fullscreen filter. Only a part ofoutputFrame.zw
size of temporary Framebuffer is used,(0, 0, outputFrame.width, outputFrame.height)
,Filters uses this quad to normalized (0-1) space, its passed into
aVertexPosition
attribute. To calculate vertex position in screen space using normalized (0-1) space:inputSize
Temporary framebuffer is different, it can be either the size of screen, either power-of-two. The
inputSize.xy
are size of temporary framebuffer that holds input. TheinputSize.zw
is inverted, it's a shortcut to evade division inside the shader.Set
inputSize.xy = outputFrame.zw
for a fullscreen filter.To calculate input normalized coordinate, you have to map it to filter normalized space. Multiply by
outputFrame.zw
to get input coordinate. Divide byinputSize.xy
to get input normalized coordinate.resolution
The
resolution
is the ratio of screen (CSS) pixels to real pixels.inputPixel
inputPixel.xy
is the size of framebuffer in real pixels, same asinputSize.xy * resolution
inputPixel.zw
is invertedinputPixel.xy
.It's handy for filters that use neighbour pixels, like PIXI.FXAAFilter FXAAFilter.
inputClamp
If you try to get info from outside of used part of Framebuffer - you'll get undefined behaviour. For displacements, coordinates has to be clamped.
The
inputClamp.xy
is left-top pixel center, you may ignore it, because we use left-top part of FramebufferinputClamp.zw
is bottom-right pixel center.Or:
Additional Information
Complete documentation on Filter usage is located in the Wiki.
Since PixiJS only had a handful of built-in filters, additional filters can be downloaded here from the PixiJS Filters repository.
Memberof
PIXI