Shader Uniforms and Animation
Demonstrates how to load a custom fragment shader and pass dynamic data, such as time, to it using the setupUniforms callback.
800 × 600
class Example extends Phaser.Scene
{
constructor()
{
super();
}
preload()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
this.load.glsl('hsl', 'assets/shaders/hsl.frag');
this.load.image('logo', 'assets/sprites/phaser3-logo-small.png');
}
create()
{
const shader = this.add.shader({
name: 'hsl',
fragmentKey: 'hsl',
setupUniforms: (setUniform, drawingContext) =>
{
setUniform('time', this.game.loop.getDuration());
},
}, 400, 300, this.scale.width, this.scale.width);
this.add.image(400, 300, 'logo');
}
}
const config = {
scale: { mode: Phaser.Scale.FIT },
type: Phaser.WEBGL,
parent: 'game-container',
width: 800,
height: 600,
scene: Example
};
const game = new Phaser.Game(config);