UNPKG

phaser

Version:

A fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers from the team at Phaser Studio Inc.

40 lines (37 loc) 2.01 kB
/** * @author Richard Davey <rich@phaser.io> * @copyright 2013-2026 Phaser Studio Inc. * @license {@link https://opensource.org/licenses/MIT|MIT License} */ var Shader = require('./Shader'); var GameObjectFactory = require('../GameObjectFactory'); /** * Creates a new Shader Game Object and adds it to the Scene. * * A Shader Game Object renders a custom GLSL fragment shader as a rectangular Game Object, allowing you to * display procedural visual effects, generative graphics, or post-processing-style visuals directly within * your game world. The shader runs on the GPU and can receive custom uniforms as well as up to four texture * channel inputs (iChannel0 to iChannel3), making it compatible with shaders written in the Shadertoy style. * * Note: This method will only be available if the Shader Game Object and WebGL support have been built into Phaser. * * @method Phaser.GameObjects.GameObjectFactory#shader * @webglOnly * @since 3.17.0 * * @param {(string|Phaser.Types.GameObjects.Shader.ShaderQuadConfig)} config - The configuration object this Shader will use. It can also be a key that corresponds to a shader in the shader cache, which will be used as `fragmentKey` in a new config object. * @param {number} [x=0] - The horizontal position of this Game Object in the world. * @param {number} [y=0] - The vertical position of this Game Object in the world. * @param {number} [width=128] - The width of the Game Object. * @param {number} [height=128] - The height of the Game Object. * @param {string[]} [textures] - Optional array of texture keys to bind to the iChannel0...3 uniforms. The textures must already exist in the Texture Manager. * * @return {Phaser.GameObjects.Shader} The Game Object that was created. */ if (typeof WEBGL_RENDERER) { GameObjectFactory.register('shader', function (config, x, y, width, height, textures) { return this.displayList.add(new Shader(this.scene, config, x, y, width, height, textures)); }); }