Introducing Beam — Play & Create Interactive Video Shorts. Explore Beam →
var CustomPipeline2 = new Phaser.Class({ Extends: Phaser.Renderer.WebGL.Pipelines.SinglePipeline, initialize: function CustomPipeline2 (game) { Phaser.Renderer.WebGL.Pipelines.SinglePipeline.call(this, { game: game, renderer: game.renderer, fragShader: ` precision mediump float; uniform sampler2D uMainSampler; uniform float time; varying vec2 outTexCoord; varying vec4 outTint; #define SPEED 10.0 void main(void) { float c = cos(time * SPEED); float s = sin(time * SPEED); mat4 hueRotation = mat4(0.299, 0.587, 0.114, 0.0, 0.299, 0.587, 0.114, 0.0, 0.299, 0.587, 0.114, 0.0, 0.0, 0.0, 0.0, 1.0) + mat4(0.701, -0.587, -0.114, 0.0, -0.299, 0.413, -0.114, 0.0, -0.300, -0.588, 0.886, 0.0, 0.0, 0.0, 0.0, 0.0) * c + mat4(0.168, 0.330, -0.497, 0.0, -0.328, 0.035, 0.292, 0.0, 1.250, -1.050, -0.203, 0.0, 0.0, 0.0, 0.0, 0.0) * s; vec4 pixel = texture2D(uMainSampler, outTexCoord); gl_FragColor = pixel * hueRotation; } ` }); } }); var config = { type: Phaser.AUTO, parent: 'phaser-example', width: 800, height: 600, backgroundColor: '#000000', scene: { preload: preload, create: create, update: update } }; var time = 0; var game = new Phaser.Game(config); function preload () { this.load.image('volcano', 'assets/pics/rick-and-morty-by-sawuinhaff-da64e7y.png'); this.load.image('hotdog', 'assets/sprites/hotdog.png'); customPipeline = game.renderer.addPipeline('Custom', new CustomPipeline2(game)); } function create () { this.add.image(400, 300, 'volcano'); this.add.image(400, 300, 'hotdog').setScrollFactor(0); this.cameras.main.setRenderToTexture(customPipeline); this.cameras.main.setZoom(0.5); var cursors = this.input.keyboard.createCursorKeys(); var controlConfig = { camera: this.cameras.main, left: cursors.left, right: cursors.right, up: cursors.up, down: cursors.down, acceleration: 0.06, drag: 0.0005, maxSpeed: 1.0 }; controls = new Phaser.Cameras.Controls.SmoothedKeyControl(controlConfig); } function update (t, delta) { controls.update(delta); customPipeline.setFloat1('time', time); time += 0.005; }
var CustomPipeline2 = new Phaser.Class({
Extends: Phaser.Renderer.WebGL.Pipelines.SinglePipeline,
initialize:
function CustomPipeline2 (game)
{
Phaser.Renderer.WebGL.Pipelines.SinglePipeline.call(this, {
game: game,
renderer: game.renderer,
fragShader: `
precision mediump float;
uniform sampler2D uMainSampler;
uniform float time;
varying vec2 outTexCoord;
varying vec4 outTint;
#define SPEED 10.0
void main(void)
{
float c = cos(time * SPEED);
float s = sin(time * SPEED);
mat4 hueRotation = mat4(0.299, 0.587, 0.114, 0.0, 0.299, 0.587, 0.114, 0.0, 0.299, 0.587, 0.114, 0.0, 0.0, 0.0, 0.0, 1.0) + mat4(0.701, -0.587, -0.114, 0.0, -0.299, 0.413, -0.114, 0.0, -0.300, -0.588, 0.886, 0.0, 0.0, 0.0, 0.0, 0.0) * c + mat4(0.168, 0.330, -0.497, 0.0, -0.328, 0.035, 0.292, 0.0, 1.250, -1.050, -0.203, 0.0, 0.0, 0.0, 0.0, 0.0) * s;
vec4 pixel = texture2D(uMainSampler, outTexCoord);
gl_FragColor = pixel * hueRotation;
}
`
});
}
});
var config = {
type: Phaser.AUTO,
parent: 'phaser-example',
width: 800,
height: 600,
backgroundColor: '#000000',
scene: {
preload: preload,
create: create,
update: update
}
};
var time = 0;
var game = new Phaser.Game(config);
function preload ()
{
this.load.image('volcano', 'assets/pics/rick-and-morty-by-sawuinhaff-da64e7y.png');
this.load.image('hotdog', 'assets/sprites/hotdog.png');
customPipeline = game.renderer.addPipeline('Custom', new CustomPipeline2(game));
}
function create ()
{
this.add.image(400, 300, 'volcano');
this.add.image(400, 300, 'hotdog').setScrollFactor(0);
this.cameras.main.setRenderToTexture(customPipeline);
this.cameras.main.setZoom(0.5);
var cursors = this.input.keyboard.createCursorKeys();
var controlConfig = {
camera: this.cameras.main,
left: cursors.left,
right: cursors.right,
up: cursors.up,
down: cursors.down,
acceleration: 0.06,
drag: 0.0005,
maxSpeed: 1.0
};
controls = new Phaser.Cameras.Controls.SmoothedKeyControl(controlConfig);
}
function update (t, delta)
{
controls.update(delta);
customPipeline.setFloat1('time', time);
time += 0.005;
}