|
| 1 | +PIXI.WobbleFilter = function(width, height, texture0, texture1) |
| 2 | +{ |
| 3 | + PIXI.AbstractFilter.call( this ); |
| 4 | + |
| 5 | + this.passes = [this]; |
| 6 | + |
| 7 | + var d = new Date(); |
| 8 | + |
| 9 | + var dates = [ |
| 10 | + d.getFullYear(), // the year (four digits) |
| 11 | + d.getMonth(), // the month (from 0-11) |
| 12 | + d.getDate(), // the day of the month (from 1-31) |
| 13 | + d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds() |
| 14 | + ]; |
| 15 | + |
| 16 | + this.uniforms = { |
| 17 | + iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }}, |
| 18 | + iGlobalTime: { type: 'f', value: 1 }, |
| 19 | + iDate: { type: 'f4', value: dates }, |
| 20 | + iChannel0: { type: 'sampler2D', value: texture0, wrap: 'repeat' }, |
| 21 | + iChannel1: { type: 'sampler2D', value: texture1, wrap: 'repeat' } |
| 22 | + }; |
| 23 | + |
| 24 | + // Shader by deps (https://www.shadertoy.com/view/MssGDM) |
| 25 | + this.fragmentSrc = [ |
| 26 | + "precision mediump float;", |
| 27 | + "uniform vec3 iResolution;", |
| 28 | + "uniform float iGlobalTime;", |
| 29 | + "uniform float iChannelTime[4];", |
| 30 | + "uniform vec4 iMouse;", |
| 31 | + "uniform vec4 iDate;", |
| 32 | + "uniform vec3 iChannelResolution[4];", |
| 33 | + "uniform sampler2D iChannel0;", |
| 34 | + "uniform sampler2D iChannel1;", |
| 35 | + "// add any extra uniforms here", |
| 36 | + |
| 37 | + "void main(void)", |
| 38 | + "{", |
| 39 | + "vec2 uv = (gl_FragCoord.xy / iResolution.xy);", |
| 40 | + "uv.y = 1.0-uv.y;", |
| 41 | + |
| 42 | + "float time = iGlobalTime * 0.75;", |
| 43 | + |
| 44 | + "vec4 pixel2 = texture2D(iChannel1, (uv+vec2(sin(time),cos(time))) * 0.15 );", |
| 45 | + |
| 46 | + "float xDiff = pixel2.r * 0.02;", |
| 47 | + "float yDiff = 0.0;", |
| 48 | + |
| 49 | + "vec2 diffVec = vec2( xDiff, yDiff );", |
| 50 | + |
| 51 | + "vec4 pixel = texture2D(iChannel0, uv + diffVec);", |
| 52 | + |
| 53 | + "gl_FragColor = pixel;", |
| 54 | + "}"]; |
| 55 | + |
| 56 | +} |
| 57 | + |
| 58 | +PIXI.WobbleFilter.prototype = Object.create( PIXI.AbstractFilter.prototype ); |
| 59 | +PIXI.WobbleFilter.prototype.constructor = PIXI.WobbleFilter; |
| 60 | + |
| 61 | +Object.defineProperty(PIXI.WobbleFilter.prototype, 'iGlobalTime', { |
| 62 | + get: function() { |
| 63 | + return this.uniforms.iGlobalTime.value; |
| 64 | + }, |
| 65 | + set: function(value) { |
| 66 | + this.uniforms.iGlobalTime.value = value; |
| 67 | + } |
| 68 | +}); |
| 69 | + |
| 70 | +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render }); |
| 71 | + |
| 72 | +function preload() { |
| 73 | + |
| 74 | + game.load.image('texture0', 'wip/tex04.jpg'); |
| 75 | + game.load.image('texture1', 'wip/tex10.png'); |
| 76 | + |
| 77 | +} |
| 78 | + |
| 79 | +var filter; |
| 80 | +var sprite; |
| 81 | + |
| 82 | +function create() { |
| 83 | + |
| 84 | + noise = game.add.sprite(0, 0, 'texture1'); |
| 85 | + |
| 86 | + sprite = game.add.sprite(0, 0, 'texture0'); |
| 87 | + sprite.width = 800; |
| 88 | + sprite.height = 600; |
| 89 | + |
| 90 | + filter = new PIXI.WobbleFilter(sprite.width, sprite.height, sprite.texture, noise.texture); |
| 91 | + |
| 92 | + sprite.filters = [filter]; |
| 93 | + |
| 94 | +} |
| 95 | + |
| 96 | +function update() { |
| 97 | + |
| 98 | + filter.iGlobalTime = game.time.totalElapsedSeconds(); |
| 99 | + |
| 100 | +} |
| 101 | + |
| 102 | +function render() { |
| 103 | +} |
0 commit comments