Skip to main content
Version: Phaser v3.88.2

PreFXPipeline

The Pre FX Pipeline is a special kind of pipeline designed specifically for applying

special effects to Game Objects before they are rendered. Where-as the Post FX Pipeline applies an effect after the

object has been rendered, the Pre FX Pipeline allows you to control the rendering of

the object itself - passing it off to its own texture, where multi-buffer compositing

can take place.

You can only use the PreFX Pipeline on the following types of Game Objects, or those

that extend from them:

Sprite

Image

Text

TileSprite

RenderTexture

Video

Constructor

new PreFXPipeline(config)

Parameters

nametypeoptionaldescription
configPhaser.Types.Renderer.WebGL.WebGLPipelineConfigNoThe configuration options for this pipeline.

Scope: static

Extends

Phaser.Renderer.WebGL.WebGLPipeline

Source: src/renderer/webgl/pipelines/PreFXPipeline.js#L20
Since: 3.60.0

Inherited Members

From Phaser.Renderer.WebGL.WebGLPipeline:


Public Members

colorMatrixShader

colorMatrixShader: Phaser.Renderer.WebGL.WebGLShader

Description:

A reference to the Color Matrix Shader belonging to this Pipeline.

This property is set during the boot method.

Source: src/renderer/webgl/pipelines/PreFXPipeline.js#L139
Since: 3.60.0


copyShader

copyShader: Phaser.Renderer.WebGL.WebGLShader

Description:

A reference to the Copy Shader belonging to this Pipeline.

This shader is used when you call the copySprite method.

This property is set during the boot method.

Source: src/renderer/webgl/pipelines/PreFXPipeline.js#L111
Since: 3.60.0


drawSpriteShader

drawSpriteShader: Phaser.Renderer.WebGL.WebGLShader

Description:

A reference to the Draw Sprite Shader belonging to this Pipeline.

This shader is used when the sprite is drawn to this fbo (or to the game if drawToFrame is false)

This property is set during the boot method.

Source: src/renderer/webgl/pipelines/PreFXPipeline.js#L97
Since: 3.60.0


fsTarget

fsTarget: Phaser.Renderer.WebGL.RenderTarget

Description:

The full-screen Render Target that the sprite is first drawn to.

Source: src/renderer/webgl/pipelines/PreFXPipeline.js#L199
Since: 3.60.0


gameShader

gameShader: Phaser.Renderer.WebGL.WebGLShader

Description:

A reference to the Game Draw Shader belonging to this Pipeline.

This shader draws the fbo to the game.

This property is set during the boot method.

Source: src/renderer/webgl/pipelines/PreFXPipeline.js#L125
Since: 3.60.0


quadVertexBuffer

quadVertexBuffer: Phaser.Renderer.WebGL.Wrappers.WebGLBufferWrapper

Description:

The WebGLBuffer that holds the quadVertexData.

Source: src/renderer/webgl/pipelines/PreFXPipeline.js#L160
Since: 3.60.0


quadVertexData

quadVertexData: ArrayBuffer

Description:

Raw byte buffer of vertices used specifically during the copySprite method.

Source: src/renderer/webgl/pipelines/PreFXPipeline.js#L150
Since: 3.60.0


quadVertexViewF32

quadVertexViewF32: Float32Array

Description:

Float32 view of the quad array buffer.

Source: src/renderer/webgl/pipelines/PreFXPipeline.js#L170
Since: 3.60.0


Inherited Methods

From Phaser.Events.EventEmitter:

From Phaser.Renderer.WebGL.WebGLPipeline:


Public Methods

batchQuad

<instance> batchQuad(gameObject, x0, y0, x1, y1, x2, y2, x3, y3, u0, v0, u1, v1, tintTL, tintTR, tintBL, tintBR, tintEffect, [texture])

Description:

Adds the vertices data into the batch and flushes if full.

Assumes 6 vertices in the following arrangement:


0----3

|\ B|

| \ |

| \ |

| A \|

| \

1----2

Where x0 / y0 = 0, x1 / y1 = 1, x2 / y2 = 2 and x3 / y3 = 3

Parameters:

nametypeoptionaldescription
gameObjectPhaser.GameObjects.GameObject | nullNoThe Game Object, if any, drawing this quad.
x0numberNoThe top-left x position.
y0numberNoThe top-left y position.
x1numberNoThe bottom-left x position.
y1numberNoThe bottom-left y position.
x2numberNoThe bottom-right x position.
y2numberNoThe bottom-right y position.
x3numberNoThe top-right x position.
y3numberNoThe top-right y position.
u0numberNoUV u0 value.
v0numberNoUV v0 value.
u1numberNoUV u1 value.
v1numberNoUV v1 value.
tintTLnumberNoThe top-left tint color value.
tintTRnumberNoThe top-right tint color value.
tintBLnumberNoThe bottom-left tint color value.
tintBRnumberNoThe bottom-right tint color value.
tintEffectnumber | booleanNoThe tint effect for the shader to use.
texturePhaser.Renderer.WebGL.Wrappers.WebGLTextureWrapperYesTexture that will be assigned to the current batch if a flush occurs.

Overrides: Phaser.Renderer.WebGL.WebGLPipeline#batchQuad

Returns: boolean - true if this method caused the batch to flush, otherwise false.

Source: src/renderer/webgl/pipelines/PreFXPipeline.js#L294
Since: 3.60.0


bindAndDraw

<instance> bindAndDraw(source)

Description:

This method is called by drawToGame and copyToGame. It takes the source Render Target

and copies it back to the game canvas, or the next frame buffer in the stack, and should

be considered the very last thing this pipeline does.

You don't normally need to call this method, or override it, however it is left public

should you wish to do so.

Note that it does not set a shader. You should do this yourself if invoking this.

Parameters:

nametypeoptionaldescription
sourcePhaser.Renderer.WebGL.RenderTargetNoThe Render Target to draw to the game.

Source: src/renderer/webgl/pipelines/PreFXPipeline.js#L701
Since: 3.60.0


blendFrames

<instance> blendFrames(source1, source2, [target], [strength], [clearAlpha])

Description:

Draws the source1 and source2 Render Targets to the target Render Target

using a linear blend effect, which is controlled by the strength parameter.

Parameters:

nametypeoptionaldefaultdescription
source1Phaser.Renderer.WebGL.RenderTargetNoThe first source Render Target.
source2Phaser.Renderer.WebGL.RenderTargetNoThe second source Render Target.
targetPhaser.Renderer.WebGL.RenderTargetYesThe target Render Target.
strengthnumberYes1The strength of the blend.
clearAlphabooleanYestrueClear the alpha channel when running gl.clear on the target?

Source: src/renderer/webgl/pipelines/PreFXPipeline.js#L617
Since: 3.60.0


blendFramesAdditive

<instance> blendFramesAdditive(source1, source2, [target], [strength], [clearAlpha])

Description:

Draws the source1 and source2 Render Targets to the target Render Target

using an additive blend effect, which is controlled by the strength parameter.

Parameters:

nametypeoptionaldefaultdescription
source1Phaser.Renderer.WebGL.RenderTargetNoThe first source Render Target.
source2Phaser.Renderer.WebGL.RenderTargetNoThe second source Render Target.
targetPhaser.Renderer.WebGL.RenderTargetYesThe target Render Target.
strengthnumberYes1The strength of the blend.
clearAlphabooleanYestrueClear the alpha channel when running gl.clear on the target?

Source: src/renderer/webgl/pipelines/PreFXPipeline.js#L635
Since: 3.60.0


copy

<instance> copy(source, target)

Description:

Draws the source Render Target to the target Render Target.

This is done using whatever the currently bound shader is. This method does

not set a shader. All it does is bind the source texture, set the viewport and UVs

then bind the target framebuffer, clears it and draws the source to it.

At the end a null framebuffer is bound. No other clearing-up takes place, so

use this method carefully.

Parameters:

nametypeoptionaldescription
sourcePhaser.Renderer.WebGL.RenderTargetNoThe source Render Target.
targetPhaser.Renderer.WebGL.RenderTargetNoThe target Render Target.

Source: src/renderer/webgl/pipelines/PreFXPipeline.js#L575
Since: 3.60.0


copySprite

<instance> copySprite(source, target, [clear], [clearAlpha], [eraseMode], [colorMatrix], [shader])

Description:

Copy the source Render Target to the target Render Target.

No target resizing takes place. If the source Render Target is larger than the target,

then only a portion the same size as the target dimensions is copied across.

Calling this method will invoke the onCopySprite handler and will also call

the onFXCopy callback on the Sprite. Both of these happen prior to the copy, allowing you

to use them to set shader uniforms and other values.

You can optionally pass in a ColorMatrix. If so, it will use the ColorMatrix shader

during the copy, allowing you to manipulate the colors to a fine degree.

See the ColorMatrix class for more details.

Parameters:

nametypeoptionaldefaultdescription
sourcePhaser.Renderer.WebGL.RenderTargetNoThe source Render Target being copied from.
targetPhaser.Renderer.WebGL.RenderTargetNoThe target Render Target that will be copied to.
clearbooleanYestrueClear the target before copying?
clearAlphabooleanYestrueClear the alpha channel when running gl.clear on the target?
eraseModebooleanYesfalseErase source from target using ERASE Blend Mode?
colorMatrixPhaser.Display.ColorMatrixYesOptional ColorMatrix to use when copying the Sprite.
shaderPhaser.Renderer.WebGL.WebGLShaderYesThe shader to use to copy the target. Defaults to the copyShader.

Source: src/renderer/webgl/pipelines/PreFXPipeline.js#L468
Since: 3.60.0


copyToGame

<instance> copyToGame(source)

Description:

This method will copy the given Render Target to the game canvas using the gameShader.

Unless you've changed it, the gameShader copies the target without modifying it, just

ensuring it is placed in the correct location on the canvas.

If you wish to draw the target with and apply the fragment shader at the same time,

see the drawToGame method instead.

This method should be the final thing called in your pipeline.

Parameters:

nametypeoptionaldescription
sourcePhaser.Renderer.WebGL.RenderTargetNoThe Render Target to copy to the game.

Source: src/renderer/webgl/pipelines/PreFXPipeline.js#L676
Since: 3.60.0


destroy

<instance> destroy()

Description:

Destroys all shader instances, removes all object references and nulls all external references.

Overrides: Phaser.Renderer.WebGL.WebGLPipeline#destroy

Returns: Phaser.Renderer.WebGL.Pipelines.PreFXPipeline - This WebGLPipeline instance.

Fires: Phaser.Renderer.WebGL.Pipelines.Events#event:DESTROY

Source: src/renderer/webgl/pipelines/PreFXPipeline.js#L888
Since: 3.60.0


drawToGame

<instance> drawToGame(source)

Description:

This method will copy the given Render Target to the game canvas using the copyShader.

This applies the results of the copy shader during the draw.

If you wish to copy the target without any effects see the copyToGame method instead.

This method should be the final thing called in your pipeline.

Parameters:

nametypeoptionaldescription
sourcePhaser.Renderer.WebGL.RenderTargetNoThe Render Target to draw to the game.

Source: src/renderer/webgl/pipelines/PreFXPipeline.js#L653
Since: 3.60.0


onCopySprite

<instance> onCopySprite(source, target, gameObject)

Description:

This callback is invoked when you call the copySprite method.

It will fire after the shader has been set, but before the source target has been copied,

so use it to set any additional uniforms you may need.

Note: Manipulating the Sprite during this callback will not change the Render Targets.

Parameters:

nametypeoptionaldescription
sourcePhaser.Renderer.WebGL.RenderTargetNoThe source Render Target being copied from.
targetPhaser.Renderer.WebGL.RenderTargetNoThe target Render Target that will be copied to.
gameObjectPhaser.GameObjects.SpriteNoThe Sprite being copied.

Source: src/renderer/webgl/pipelines/PreFXPipeline.js#L449
Since: 3.60.0


onDraw

<instance> onDraw(target, [swapTarget], [altSwapTarget])

Description:

This method is called every time the batchSprite method is called and is passed a

reference to the current render target.

If you override this method, then it should make sure it calls either the

drawToGame or copyToGame methods as the final thing it does. However, you can do as

much additional processing as you like prior to this.

Parameters:

nametypeoptionaldescription
targetPhaser.Renderer.WebGL.RenderTargetNoThe Render Target to draw to the game.
swapTargetPhaser.Renderer.WebGL.RenderTargetYesThe Swap Render Target, useful for double-buffer effects.
altSwapTargetPhaser.Renderer.WebGL.RenderTargetYesThe Swap Render Target, useful for double-buffer effects.

Overrides: Phaser.Renderer.WebGL.WebGLPipeline#onDraw

Source: src/renderer/webgl/pipelines/PreFXPipeline.js#L787
Since: 3.60.0


onDrawSprite

<instance> onDrawSprite(gameObject, target)

Description:

This callback is invoked when a sprite is drawn by this pipeline.

It will fire after the shader has been set, but before the sprite has been drawn,

so use it to set any additional uniforms you may need.

Note: Manipulating the Sprite during this callback will not change how it is drawn to the Render Target.

Parameters:

nametypeoptionaldescription
gameObjectPhaser.GameObjects.SpriteNoThe Sprite being drawn.
targetPhaser.Renderer.WebGL.RenderTargetNoThe Render Target the Sprite will be drawn to.

Source: src/renderer/webgl/pipelines/PreFXPipeline.js#L431
Since: 3.60.0


onResize

<instance> onResize(width, height)

Description:

Handles the resizing of the quad vertex data.

Parameters:

nametypeoptionaldescription
widthnumberNoThe new width of the quad.
heightnumberNoThe new height of the quad.

Overrides: Phaser.Renderer.WebGL.WebGLPipeline#onResize

Source: src/renderer/webgl/pipelines/PreFXPipeline.js#L261
Since: 3.60.0


resetUVs

<instance> resetUVs()

Description:

Resets the quad vertice UV values to their default settings.

The quad is used by the copy shader in this pipeline.

Source: src/renderer/webgl/pipelines/PreFXPipeline.js#L875
Since: 3.60.0


setTargetUVs

<instance> setTargetUVs(source, target)

Description:

Sets the vertex UV coordinates of the quad used by the copy shaders

so that they correctly adjust the texture coordinates for a blit frame effect.

Be sure to call resetUVs once you have finished manipulating the UV coordinates.

Parameters:

nametypeoptionaldescription
sourcePhaser.Renderer.WebGL.RenderTargetNoThe source Render Target.
targetPhaser.Renderer.WebGL.RenderTargetNoThe target Render Target.

Source: src/renderer/webgl/pipelines/PreFXPipeline.js#L847
Since: 3.60.0


setUVs

<instance> setUVs(uA, vA, uB, vB, uC, vC, uD, vD)

Description:

Set the UV values for the 6 vertices that make up the quad used by the copy shader.

Be sure to call resetUVs once you have finished manipulating the UV coordinates.

Parameters:

nametypeoptionaldescription
uAnumberNoThe u value of vertex A.
vAnumberNoThe v value of vertex A.
uBnumberNoThe u value of vertex B.
vBnumberNoThe v value of vertex B.
uCnumberNoThe u value of vertex C.
vCnumberNoThe v value of vertex C.
uDnumberNoThe u value of vertex D.
vDnumberNoThe v value of vertex D.

Source: src/renderer/webgl/pipelines/PreFXPipeline.js#L807
Since: 3.60.0