Skip to main content
Version: Phaser v4.0.0

BaseShader

A BaseShader is a small resource class that contains GLSL code for a shader.

It contains the key of the shader, the source code, and optional metadata. Phaser does not enforce a specific shader type: the source could be a fragment shader, a vertex shader, or even an incomplete snippet of GLSL. It is stored as raw source code and may be retrieved and compiled as you wish. These keys can be used by Phaser.GameObjects.Shader and Phaser.Renderer.WebGL.RenderNodes.BaseFilterShader.

BaseShaders are stored in the Shader Cache, available in a Scene via this.cache.shaders and are referenced by a unique key-based string. Retrieve them via this.cache.shaders.get(key).

BaseShaders are created automatically by the GLSL File Loader when loading an external shader resource. They can also be created at runtime, allowing you to use dynamically generated shader source code.

Constructor

new BaseShader(key, glsl, [metadata])

Parameters

nametypeoptionaldescription
keystringNoThe key of this shader. Must be unique within the shader cache.
glslstringNoThe GLSL source code for the shader.
metadataobjectYesAdditional metadata for this shader code.

Scope: static

Source: src/display/shader/BaseShader.js#L9
Since: 4.0.0

Public Members

glsl

glsl: string

Description:

GLSL source code for a shader. The use of this code is not specified by Phaser. You can add metadata to further describe its purpose.

Source: src/display/shader/BaseShader.js#L50
Since: 4.0.0


key

key: string

Description:

The key of this shader code, unique within the shader cache of this Phaser game instance.

Source: src/display/shader/BaseShader.js#L40
Since: 3.17.0


metadata

metadata: object

Description:

Additional metadata for this shader. This is not used by Phaser, but it may be used by your game code or external tools. For example, you could add properties that describe the shader's purpose, author, version, etc.

Source: src/display/shader/BaseShader.js#L61
Since: 4.0.0