Skip to main content
Version: Phaser v3.90.0

LightPipeline

The Light Pipeline is an extension of the Multi Pipeline and uses a custom shader

designed to handle forward diffused rendering of 2D lights in a Scene.

The shader works in tandem with Light Game Objects, and optionally texture normal maps,

to provide an ambient illumination effect.

If you wish to provide your own shader, you can use the %LIGHT_COUNT% declaration in the source,

and it will be automatically replaced at run-time with the total number of configured lights.

The maximum number of lights can be set in the Render Config maxLights property and defaults to 10.

Prior to Phaser v3.50 this pipeline was called the ForwardDiffuseLightPipeline.

The fragment shader it uses can be found in shaders/src/Light.frag.

The vertex shader it uses can be found in shaders/src/Multi.vert.

The default shader attributes for this pipeline are:

inPosition (vec2, offset 0)

inTexCoord (vec2, offset 8)

inTexId (float, offset 16)

inTintEffect (float, offset 20)

inTint (vec4, offset 24, normalized)

The default shader uniforms for this pipeline are those from the Multi Pipeline, plus:

uMainSampler (sampler2D)

uNormSampler (sampler2D)

uCamera (vec4)

uResolution (vec2)

uAmbientLightColor (vec3)

uInverseRotationMatrix (mat3)

uLights (Light struct)

Constructor

new LightPipeline(config)

Parameters

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

Scope: static

Extends

Phaser.Renderer.WebGL.Pipelines.MultiPipeline

Source: src/renderer/webgl/pipelines/LightPipeline.js#L16
Since: 3.50.0

Inherited Members

From Phaser.Renderer.WebGL.Pipelines.MultiPipeline:

From Phaser.Renderer.WebGL.WebGLPipeline:


Public Members

currentNormalMap;

currentNormalMap;: Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper

Description:

The currently bound normal map texture at texture unit one, if any.

Source: src/renderer/webgl/pipelines/LightPipeline.js#L88
Since: 3.60.0


lightsActive

lightsActive: boolean

Description:

A boolean that is set automatically during onRender that determines

if the Scene LightManager is active, or not.

Source: src/renderer/webgl/pipelines/LightPipeline.js#L97
Since: 3.53.0


tempVec2

tempVec2: Phaser.Math.Vector2

Description:

A persistent calculation vector used when processing the lights.

Source: src/renderer/webgl/pipelines/LightPipeline.js#L108
Since: 3.60.0


Inherited Methods

From Phaser.Events.EventEmitter:

From Phaser.Renderer.WebGL.Pipelines.MultiPipeline:

From Phaser.Renderer.WebGL.WebGLPipeline:


Public Methods

batchSprite

<instance> batchSprite(gameObject, camera, [parentTransformMatrix])

Description:

Takes a Sprite Game Object, or any object that extends it, and adds it to the batch.

Parameters:

nametypeoptionaldescription
gameObjectPhaser.GameObjects.Image | Phaser.GameObjects.SpriteNoThe texture based Game Object to add to the batch.
cameraPhaser.Cameras.Scene2D.CameraNoThe Camera to use for the rendering transform.
parentTransformMatrixPhaser.GameObjects.Components.TransformMatrixYesThe transform matrix of the parent container, if set.

Overrides: Phaser.Renderer.WebGL.Pipelines.MultiPipeline#batchSprite

Source: src/renderer/webgl/pipelines/LightPipeline.js#L422
Since: 3.50.0


batchTexture

<instance> batchTexture(gameObject, texture, textureWidth, textureHeight, srcX, srcY, srcWidth, srcHeight, scaleX, scaleY, rotation, flipX, flipY, scrollFactorX, scrollFactorY, displayOriginX, displayOriginY, frameX, frameY, frameWidth, frameHeight, tintTL, tintTR, tintBL, tintBR, tintEffect, uOffset, vOffset, camera, parentTransformMatrix, [skipFlip], [textureUnit])

Description:

Generic function for batching a textured quad using argument values instead of a Game Object.

Parameters:

nametypeoptionaldefaultdescription
gameObjectPhaser.GameObjects.GameObjectNoSource GameObject.
texturePhaser.Renderer.WebGL.Wrappers.WebGLTextureWrapperNoTexture associated with the quad.
textureWidthnumberNoReal texture width.
textureHeightnumberNoReal texture height.
srcXnumberNoX coordinate of the quad.
srcYnumberNoY coordinate of the quad.
srcWidthnumberNoWidth of the quad.
srcHeightnumberNoHeight of the quad.
scaleXnumberNoX component of scale.
scaleYnumberNoY component of scale.
rotationnumberNoRotation of the quad.
flipXbooleanNoIndicates if the quad is horizontally flipped.
flipYbooleanNoIndicates if the quad is vertically flipped.
scrollFactorXnumberNoBy which factor is the quad affected by the camera horizontal scroll.
scrollFactorYnumberNoBy which factor is the quad effected by the camera vertical scroll.
displayOriginXnumberNoHorizontal origin in pixels.
displayOriginYnumberNoVertical origin in pixels.
frameXnumberNoX coordinate of the texture frame.
frameYnumberNoY coordinate of the texture frame.
frameWidthnumberNoWidth of the texture frame.
frameHeightnumberNoHeight of the texture frame.
tintTLnumberNoTint for top left.
tintTRnumberNoTint for top right.
tintBLnumberNoTint for bottom left.
tintBRnumberNoTint for bottom right.
tintEffectnumberNoThe tint effect.
uOffsetnumberNoHorizontal offset on texture coordinate.
vOffsetnumberNoVertical offset on texture coordinate.
cameraPhaser.Cameras.Scene2D.CameraNoCurrent used camera.
parentTransformMatrixPhaser.GameObjects.Components.TransformMatrixNoParent container.
skipFlipbooleanYesfalseSkip the renderTexture check.
textureUnitnumberYesUse the currently bound texture unit?

Overrides: Phaser.Renderer.WebGL.Pipelines.MultiPipeline#batchTexture

Source: src/renderer/webgl/pipelines/LightPipeline.js#L440
Since: 3.50.0


batchTextureFrame

<instance> batchTextureFrame(frame, x, y, tint, alpha, transformMatrix, [parentTransformMatrix])

Description:

Adds a Texture Frame into the batch for rendering.

Parameters:

nametypeoptionaldescription
framePhaser.Textures.FrameNoThe Texture Frame to be rendered.
xnumberNoThe horizontal position to render the texture at.
ynumberNoThe vertical position to render the texture at.
tintnumberNoThe tint color.
alphanumberNoThe alpha value.
transformMatrixPhaser.GameObjects.Components.TransformMatrixNoThe Transform Matrix to use for the texture.
parentTransformMatrixPhaser.GameObjects.Components.TransformMatrixYesA parent Transform Matrix.

Overrides: Phaser.Renderer.WebGL.Pipelines.MultiPipeline#batchTextureFrame

Source: src/renderer/webgl/pipelines/LightPipeline.js#L523
Since: 3.50.0


boot

<instance> boot()

Description:

Called when the Game has fully booted and the Renderer has finished setting up.

By this stage all Game level systems are now in place and you can perform any final

tasks that the pipeline may need that relied on game systems such as the Texture Manager.

Overrides: Phaser.Renderer.WebGL.Pipelines.MultiPipeline#boot

Source: src/renderer/webgl/pipelines/LightPipeline.js#L138
Since: 3.11.0


getNormalMap

<instance> getNormalMap([gameObject])

Description:

Returns the normal map WebGLTextureWrapper from the given Game Object.

If the Game Object doesn't have one, it returns the default normal map from this pipeline instead.

Parameters:

nametypeoptionaldescription
gameObjectPhaser.GameObjects.GameObjectYesThe Game Object to get the normal map from.

Returns: Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper - The normal map texture.

Source: src/renderer/webgl/pipelines/LightPipeline.js#L375
Since: 3.50.0


onRender

<instance> onRender(scene, camera)

Description:

This function sets all the needed resources for each camera pass.

Parameters:

nametypeoptionaldescription
scenePhaser.SceneNoThe Scene being rendered.
cameraPhaser.Cameras.Scene2D.CameraNoThe Scene Camera being rendered with.

Overrides: Phaser.Renderer.WebGL.Pipelines.MultiPipeline#onRender

Source: src/renderer/webgl/pipelines/LightPipeline.js#L152
Since: 3.0.0


setGameObject

<instance> setGameObject(gameObject, [frame])

Description:

Custom pipelines can use this method in order to perform any required pre-batch tasks

for the given Game Object. It must return the texture unit the Game Object was assigned.

Parameters:

nametypeoptionaldescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object being rendered or added to the batch.
framePhaser.Textures.FrameYesOptional frame to use. Can override that of the Game Object.

Overrides: Phaser.Renderer.WebGL.Pipelines.MultiPipeline#setGameObject

Returns: number - The texture unit the Game Object has been assigned.

Source: src/renderer/webgl/pipelines/LightPipeline.js#L307
Since: 3.50.0


setNormalMapRotation

<instance> setNormalMapRotation(rotation)

Description:

Rotates the normal map vectors inversely by the given angle.

Only works in 2D space.

Parameters:

nametypeoptionaldescription
rotationnumberNoThe angle of rotation in radians.

Source: src/renderer/webgl/pipelines/LightPipeline.js#L211
Since: 3.16.0


setTexture2D

<instance> setTexture2D([texture], [gameObject])

Description:

Assigns a texture to the current batch. If a different texture is already set it creates a new batch object.

Parameters:

nametypeoptionaldescription
texturePhaser.Renderer.WebGL.Wrappers.WebGLTextureWrapperYesTexture that will be assigned to the current batch. If not given uses blankTexture.
gameObjectPhaser.GameObjects.GameObjectYesThe Game Object being rendered or added to the batch.

Overrides: Phaser.Renderer.WebGL.Pipelines.MultiPipeline#setTexture2D

Source: src/renderer/webgl/pipelines/LightPipeline.js#L253
Since: 3.50.0