Added phaser build and hellophaser sample
This commit is contained in:
49
filters/.jshintrc
Normal file
49
filters/.jshintrc
Normal file
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"globals" : { "Phaser": false, "PIXI": false, "p2": false },
|
||||
// Ignore Environment Globals
|
||||
"browser" : true, // Standard browser globals e.g. `window`, `document`.
|
||||
|
||||
// Development
|
||||
"devel" : true, // Allow developments statements e.g. `console.log();`.
|
||||
|
||||
// ECMAScript Support
|
||||
"es3" : true, // Support legacy browser and javascript environments.
|
||||
"esnext" : false, // This option tells JSHint that your code uses ECMAScript 6 specific syntax.
|
||||
"strict" : false, // Require `use strict` pragma in every file.
|
||||
"globalstrict": false, // Allow global "use strict" (also enables 'strict').
|
||||
|
||||
// Functionality
|
||||
"bitwise" : false, // Prohibit bitwise operators (&, |, ^, etc.).
|
||||
"boss" : true, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
|
||||
"camelcase" : false, // Force all variable names to use either camelCase style or UPPER_CASE with underscores.
|
||||
"curly" : true, // Require {} for every new block or scope.
|
||||
"eqeqeq" : false, // Require triple equals i.e. `===`.
|
||||
"eqnull" : true, // Tolerate use of `== null`.
|
||||
"evil" : false, // Tolerate use of `eval`.
|
||||
"expr" : false, // Tolerate `ExpressionStatement` as Programs.
|
||||
"forin" : false, // Tolerate `for in` loops without `hasOwnPrototype`.
|
||||
"freeze" : true, // Prohibits overwriting prototypes of native objects such as Array and Date.
|
||||
"funcscope" : true, // This option suppresses warnings about declaring variables inside of control structures while accessing them later from the outside.
|
||||
"immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
|
||||
"latedef" : true, // Prohibit variable use before definition.
|
||||
"laxbreak" : false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
|
||||
"laxcomma" : false, // This option suppresses warnings about comma-first coding style.
|
||||
"loopfunc" : true, // Allow functions to be defined within loops.
|
||||
"noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`.
|
||||
"notypeof" : false, // This option suppresses warnings about invalid typeof operator values.
|
||||
"shadow" : true, // Allows re-define variables later in code e.g. `var x=1; x=2;`.
|
||||
"smarttabs" : false, // This option suppresses warnings about mixed tabs and spaces when the latter are used for alignmnent only.
|
||||
"supernew" : false, // Tolerate `new function () { ... };` and `new Object;`.
|
||||
"undef" : true, // Require all non-global variables be declared before they are used.
|
||||
"unused" : true, // This option warns when you define and never use your variables.
|
||||
|
||||
// Styling
|
||||
"indent" : false, // Specify indentation spacing
|
||||
"newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`.
|
||||
"noempty" : true, // Prohibit use of empty blocks.
|
||||
"nonew" : true, // Prohibit use of constructors for side-effects.
|
||||
"plusplus" : false, // Prohibit use of `++` & `--`.
|
||||
"quotmark" : false, // This option enforces the consistency of quotation marks used throughout your code.
|
||||
"sub" : true, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
|
||||
"trailing" : true // Prohibit trailing whitespaces.
|
||||
}
|
||||
96
filters/BinarySerpents.js
Normal file
96
filters/BinarySerpents.js
Normal file
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* Original shader by Trisomie21 (https://www.shadertoy.com/view/MslGRH)
|
||||
* Tweaked, uniforms added and converted to Phaser/PIXI by Richard Davey
|
||||
*/
|
||||
Phaser.Filter.BinarySerpents = function (game) {
|
||||
|
||||
Phaser.Filter.call(this, game);
|
||||
|
||||
this.uniforms.march = { type: '1i', value: 100 };
|
||||
this.uniforms.maxDistance = { type: '1f', value: 5.0 };
|
||||
this.uniforms.fog = { type: '1f', value: 5.0 };
|
||||
|
||||
this.fragmentSrc = [
|
||||
|
||||
"precision mediump float;",
|
||||
"uniform vec3 resolution;",
|
||||
"uniform float time;",
|
||||
"uniform int march;",
|
||||
"uniform float maxDistance;",
|
||||
"uniform float fog;",
|
||||
|
||||
"// With tweaks by PauloFalcao and Richard Davey",
|
||||
|
||||
"float Texture3D(vec3 n, float res) {",
|
||||
"n = floor(n*res+.5);",
|
||||
"return fract(sin((n.x+n.y*1e5+n.z*1e7)*1e-4)*1e5);",
|
||||
"}",
|
||||
|
||||
"float map( vec3 p ) {",
|
||||
"p.x+=sin(p.z*4.0+time*4.0)*0.1*cos(time*0.1);",
|
||||
"p = mod(p,vec3(1.0, 1.0, 1.0))-0.5;",
|
||||
"return length(p.xy)-.1;",
|
||||
"}",
|
||||
|
||||
"void main( void )",
|
||||
"{",
|
||||
"vec2 pos = (gl_FragCoord.xy*2.0 - resolution.xy) / resolution.y;",
|
||||
"vec3 camPos = vec3(cos(time*0.3), sin(time*0.3), 1.5);",
|
||||
"vec3 camTarget = vec3(0.0, 0.0, 0.0);",
|
||||
|
||||
"vec3 camDir = normalize(camTarget-camPos);",
|
||||
"vec3 camUp = normalize(vec3(0.0, 1.0, 0.0));",
|
||||
"vec3 camSide = cross(camDir, camUp);",
|
||||
"float focus = 2.0;",
|
||||
|
||||
"vec3 rayDir = normalize(camSide*pos.x + camUp*pos.y + camDir*focus);",
|
||||
"vec3 ray = camPos;",
|
||||
"float d = 0.0, total_d = 0.0;",
|
||||
"const int MAX_MARCH = 100;",
|
||||
"float c = 1.0;",
|
||||
|
||||
"for (int i=0; i < MAX_MARCH; ++i) {",
|
||||
"if (i < march) {",
|
||||
"d = map(ray);",
|
||||
"total_d += d;",
|
||||
"ray += rayDir * d;",
|
||||
"if(abs(d)<0.001) { break; }",
|
||||
"if(total_d>maxDistance) { c = 0.; total_d=maxDistance; break; }",
|
||||
"}",
|
||||
"}",
|
||||
|
||||
"vec4 result = vec4( vec3(c*.4 , c*.6, c) * (fog - total_d) / fog, 1.0 );",
|
||||
|
||||
"ray.z -= 5.+time*.5;",
|
||||
"float r = Texture3D(ray, 33.);",
|
||||
"gl_FragColor = result * (step(r, .3) + r * .2 + .1);",
|
||||
"}"
|
||||
];
|
||||
|
||||
};
|
||||
|
||||
Phaser.Filter.BinarySerpents.prototype = Object.create(Phaser.Filter.prototype);
|
||||
Phaser.Filter.BinarySerpents.prototype.constructor = Phaser.Filter.BinarySerpents;
|
||||
|
||||
Phaser.Filter.BinarySerpents.prototype.init = function (width, height, march, maxDistance) {
|
||||
|
||||
if (typeof march === 'undefined') { march = 100; }
|
||||
if (typeof maxDistance === 'undefined') { maxDistance = 5.0; }
|
||||
|
||||
this.setResolution(width, height);
|
||||
this.uniforms.march.value = march;
|
||||
this.uniforms.maxDistance.value = maxDistance;
|
||||
|
||||
};
|
||||
|
||||
Object.defineProperty(Phaser.Filter.BinarySerpents.prototype, 'fog', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.fog.value;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.fog.value = value;
|
||||
}
|
||||
|
||||
});
|
||||
53
filters/BlurX.js
Normal file
53
filters/BlurX.js
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* A horizontal blur filter by Mat Groves http://matgroves.com/ @Doormat23
|
||||
*/
|
||||
Phaser.Filter.BlurX = function (game) {
|
||||
|
||||
Phaser.Filter.call(this, game);
|
||||
|
||||
this.uniforms.blur = { type: '1f', value: 1 / 512 };
|
||||
|
||||
this.fragmentSrc = [
|
||||
|
||||
"precision mediump float;",
|
||||
"varying vec2 vTextureCoord;",
|
||||
"varying vec4 vColor;",
|
||||
"uniform float blur;",
|
||||
"uniform sampler2D uSampler;",
|
||||
|
||||
"void main(void) {",
|
||||
|
||||
"vec4 sum = vec4(0.0);",
|
||||
|
||||
"sum += texture2D(uSampler, vec2(vTextureCoord.x - 4.0*blur, vTextureCoord.y)) * 0.05;",
|
||||
"sum += texture2D(uSampler, vec2(vTextureCoord.x - 3.0*blur, vTextureCoord.y)) * 0.09;",
|
||||
"sum += texture2D(uSampler, vec2(vTextureCoord.x - 2.0*blur, vTextureCoord.y)) * 0.12;",
|
||||
"sum += texture2D(uSampler, vec2(vTextureCoord.x - blur, vTextureCoord.y)) * 0.15;",
|
||||
"sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y)) * 0.16;",
|
||||
"sum += texture2D(uSampler, vec2(vTextureCoord.x + blur, vTextureCoord.y)) * 0.15;",
|
||||
"sum += texture2D(uSampler, vec2(vTextureCoord.x + 2.0*blur, vTextureCoord.y)) * 0.12;",
|
||||
"sum += texture2D(uSampler, vec2(vTextureCoord.x + 3.0*blur, vTextureCoord.y)) * 0.09;",
|
||||
"sum += texture2D(uSampler, vec2(vTextureCoord.x + 4.0*blur, vTextureCoord.y)) * 0.05;",
|
||||
|
||||
"gl_FragColor = sum;",
|
||||
|
||||
"}"
|
||||
];
|
||||
|
||||
};
|
||||
|
||||
Phaser.Filter.BlurX.prototype = Object.create(Phaser.Filter.prototype);
|
||||
Phaser.Filter.BlurX.prototype.constructor = Phaser.Filter.BlurX;
|
||||
|
||||
Object.defineProperty(Phaser.Filter.BlurX.prototype, 'blur', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.blur.value / (1/7000);
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.dirty = true;
|
||||
this.uniforms.blur.value = (1/7000) * value;
|
||||
}
|
||||
|
||||
});
|
||||
54
filters/BlurY.js
Normal file
54
filters/BlurY.js
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* A vertical blur filter by Mat Groves http://matgroves.com/ @Doormat23
|
||||
*/
|
||||
Phaser.Filter.BlurY = function (game) {
|
||||
|
||||
Phaser.Filter.call(this, game);
|
||||
|
||||
this.uniforms.blur = { type: '1f', value: 1 / 512 };
|
||||
|
||||
this.fragmentSrc = [
|
||||
|
||||
"precision mediump float;",
|
||||
"varying vec2 vTextureCoord;",
|
||||
"varying vec4 vColor;",
|
||||
"uniform float blur;",
|
||||
"uniform sampler2D uSampler;",
|
||||
|
||||
"void main(void) {",
|
||||
|
||||
"vec4 sum = vec4(0.0);",
|
||||
|
||||
"sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y - 4.0*blur)) * 0.05;",
|
||||
"sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y - 3.0*blur)) * 0.09;",
|
||||
"sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y - 2.0*blur)) * 0.12;",
|
||||
"sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y - blur)) * 0.15;",
|
||||
"sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y)) * 0.16;",
|
||||
"sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y + blur)) * 0.15;",
|
||||
"sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y + 2.0*blur)) * 0.12;",
|
||||
"sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y + 3.0*blur)) * 0.09;",
|
||||
"sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y + 4.0*blur)) * 0.05;",
|
||||
|
||||
"gl_FragColor = sum;",
|
||||
|
||||
"}"
|
||||
|
||||
];
|
||||
|
||||
};
|
||||
|
||||
Phaser.Filter.BlurY.prototype = Object.create(Phaser.Filter.prototype);
|
||||
Phaser.Filter.BlurY.prototype.constructor = Phaser.Filter.BlurY;
|
||||
|
||||
Object.defineProperty(Phaser.Filter.BlurY.prototype, 'blur', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.blur.value / (1/7000);
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.dirty = true;
|
||||
this.uniforms.blur.value = (1/7000) * value;
|
||||
}
|
||||
|
||||
});
|
||||
61
filters/CausticLight.js
Normal file
61
filters/CausticLight.js
Normal file
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* A sample demonstrating how to create new Phaser Filters.
|
||||
*/
|
||||
Phaser.Filter.SampleFilter = function (game) {
|
||||
|
||||
Phaser.Filter.call(this, game);
|
||||
|
||||
this.uniforms.divisor = { type: '1f', value: 0.5 };
|
||||
|
||||
// The fragment shader source
|
||||
this.fragmentSrc = [
|
||||
|
||||
"precision mediump float;",
|
||||
"uniform vec3 resolution;",
|
||||
"uniform float time;",
|
||||
|
||||
"const int complexity = 40; // More points of color.",
|
||||
"const float mouse_factor = 25.0; // Makes it more/less jumpy.",
|
||||
"const float mouse_offset = 5.0; // Drives complexity in the amount of curls/cuves. Zero is a single whirlpool.",
|
||||
"const float fluid_speed = 45.0; // Drives speed, higher number will make it slower.",
|
||||
"const float color_intensity = 0.30;",
|
||||
|
||||
"const float Pi = 3.14159;",
|
||||
|
||||
"float sinApprox(float x) {",
|
||||
"x = Pi + (2.0 * Pi) * floor(x / (2.0 * Pi)) - x;",
|
||||
"return (4.0 / Pi) * x - (4.0 / Pi / Pi) * x * abs(x);",
|
||||
"}",
|
||||
|
||||
"float cosApprox(float x) {",
|
||||
"return sinApprox(x + 0.5 * Pi);",
|
||||
"}",
|
||||
|
||||
"void main()",
|
||||
"{",
|
||||
"vec2 p=(2.0*gl_FragCoord.xy-resolution)/max(resolution.x,resolution.y);",
|
||||
"for(int i=1;i<complexity;i++)",
|
||||
"{",
|
||||
"vec2 newp=p;",
|
||||
"newp.x+=0.6/float(i)*sin(float(i)*p.y+time/fluid_speed+0.3*float(i))+mouse.y/mouse_factor+mouse_offset;",
|
||||
"newp.y+=0.6/float(i)*sin(float(i)*p.x+time/fluid_speed+0.3*float(i+10))-mouse.x/mouse_factor+mouse_offset;",
|
||||
"p=newp;",
|
||||
"}",
|
||||
"vec3 col=vec3(color_intensity*sin(3.0*p.x)+color_intensity,color_intensity*sin(3.0*p.y)+color_intensity,color_intensity*sin(p.x+p.y)+color_intensity);",
|
||||
"gl_FragColor=vec4(col, 1.0);",
|
||||
"}"
|
||||
];
|
||||
|
||||
};
|
||||
|
||||
Phaser.Filter.SampleFilter.prototype = Object.create(Phaser.Filter.prototype);
|
||||
Phaser.Filter.SampleFilter.prototype.constructor = Phaser.Filter.SampleFilter;
|
||||
|
||||
Phaser.Filter.SampleFilter.prototype.init = function (width, height, divisor) {
|
||||
|
||||
if (typeof divisor == 'undefined') { divisor = 0.5; }
|
||||
|
||||
this.setResolution(width, height);
|
||||
this.uniforms.divisor.value = divisor;
|
||||
|
||||
};
|
||||
171
filters/CheckerWave.js
Normal file
171
filters/CheckerWave.js
Normal file
@@ -0,0 +1,171 @@
|
||||
/**
|
||||
* Original shader from http://glsl.heroku.com/e#12260.0
|
||||
* Tweaked, uniforms added and converted to Phaser/PIXI by Richard Davey
|
||||
*/
|
||||
Phaser.Filter.CheckerWave = function (game) {
|
||||
|
||||
Phaser.Filter.call(this, game);
|
||||
|
||||
this.uniforms.alpha = { type: '1f', value: 1.0 };
|
||||
this.uniforms.vrp = { type: '3f', value: { x: 0.0, y: -5.0, z: 0.0 }};
|
||||
this.uniforms.color1 = { type: '3f', value: { x: 0, y: 1, z: 1 }};
|
||||
this.uniforms.color2 = { type: '3f', value: { x: 1, y: 1, z: 1 }};
|
||||
|
||||
this.fragmentSrc = [
|
||||
|
||||
"precision mediump float;",
|
||||
"uniform vec2 resolution;",
|
||||
"uniform float time;",
|
||||
"uniform float alpha;",
|
||||
"uniform vec3 vrp;",
|
||||
"uniform vec3 color1;",
|
||||
"uniform vec3 color2;",
|
||||
|
||||
"// Scene Start",
|
||||
|
||||
"// Floor",
|
||||
"vec2 obj0(in vec3 p) {",
|
||||
"// obj deformation",
|
||||
"p.y=p.y+sin(sqrt(p.x*p.x+p.z*p.z)-time*4.0)*0.5;",
|
||||
"//plane",
|
||||
"return vec2(p.y+3.0,0);",
|
||||
"}",
|
||||
|
||||
"// Floor Color (checkerboard)",
|
||||
"vec3 obj0_c(in vec3 p) {",
|
||||
"if (fract(p.x*.5)>.5)",
|
||||
"if (fract(p.z*.5)>.5)",
|
||||
"return color1;",
|
||||
"else",
|
||||
"return color2;",
|
||||
"else",
|
||||
"if (fract(p.z*.5)>.5)",
|
||||
"return color2;",
|
||||
"else",
|
||||
"return color1;",
|
||||
"}",
|
||||
|
||||
"// Scene End",
|
||||
|
||||
"void main(void) {",
|
||||
"vec2 vPos=-1.0+2.0*gl_FragCoord.xy/resolution.xy;",
|
||||
|
||||
"// Camera animation",
|
||||
"vec3 vuv=vec3(0,2,sin(time*0.1));//Change camere up vector here",
|
||||
"vec3 prp=vec3(-sin(time*0.6)*8.0,0,cos(time*0.4)*8.0); //Change camera path position here",
|
||||
|
||||
"// Camera setup",
|
||||
"vec3 vpn=normalize(vrp-prp);",
|
||||
"vec3 u=normalize(cross(vuv,vpn));",
|
||||
"vec3 v=cross(vpn,u);",
|
||||
"vec3 vcv=(prp+vpn);",
|
||||
"vec3 scrCoord=vcv+vPos.x*u*resolution.x/resolution.y+vPos.y*v;",
|
||||
"vec3 scp=normalize(scrCoord-prp);",
|
||||
|
||||
"// Raymarching",
|
||||
"const vec3 e=vec3(0.1,0,0);",
|
||||
"const float maxd=80.0; //Max depth",
|
||||
|
||||
"vec2 s=vec2(0.1,0.0);",
|
||||
"vec3 c,p,n;",
|
||||
|
||||
"float f=1.0;",
|
||||
|
||||
"for (int i=0;i<156;i++) {",
|
||||
"if (abs(s.x)<.01||f>maxd) break;",
|
||||
"f+=s.x;",
|
||||
"p=prp+scp*f;",
|
||||
"s=obj0(p);",
|
||||
"}",
|
||||
|
||||
"if (f<maxd) {",
|
||||
"if (s.y==0.0)",
|
||||
"c=obj0_c(p);",
|
||||
"n=normalize(",
|
||||
"vec3(s.x-obj0(p-e.xyy).x,",
|
||||
"s.x-obj0(p-e.yxy).x,",
|
||||
"s.x-obj0(p-e.yyx).x));",
|
||||
"float b=dot(n,normalize(prp-p));",
|
||||
"vec4 color = vec4(( b * c + pow(b, 8.0)) * (1.0 - f * .02), 1.0); //simple phong LightPosition=CameraPosition",
|
||||
"color.a = alpha;",
|
||||
"gl_FragColor=color;",
|
||||
"}",
|
||||
"else gl_FragColor=vec4(0,0,0.1,alpha); //background color",
|
||||
"}"
|
||||
|
||||
];
|
||||
|
||||
};
|
||||
|
||||
Phaser.Filter.CheckerWave.prototype = Object.create(Phaser.Filter.prototype);
|
||||
Phaser.Filter.CheckerWave.prototype.constructor = Phaser.Filter.CheckerWave;
|
||||
|
||||
Phaser.Filter.CheckerWave.prototype.init = function (width, height) {
|
||||
|
||||
this.setResolution(width, height);
|
||||
|
||||
};
|
||||
|
||||
Phaser.Filter.CheckerWave.prototype.setColor1 = function (red, green, blue) {
|
||||
|
||||
this.uniforms.color1.value.x = red;
|
||||
this.uniforms.color1.value.y = green;
|
||||
this.uniforms.color1.value.z = blue;
|
||||
|
||||
};
|
||||
|
||||
Phaser.Filter.CheckerWave.prototype.setColor2 = function (red, green, blue) {
|
||||
|
||||
this.uniforms.color2.value.x = red;
|
||||
this.uniforms.color2.value.y = green;
|
||||
this.uniforms.color2.value.z = blue;
|
||||
|
||||
};
|
||||
|
||||
Object.defineProperty(Phaser.Filter.CheckerWave.prototype, 'alpha', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.alpha.value;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.alpha.value = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.Filter.CheckerWave.prototype, 'cameraX', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.vrp.value.x;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.vrp.value.x = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.Filter.CheckerWave.prototype, 'cameraY', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.vrp.value.y;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.vrp.value.y = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.Filter.CheckerWave.prototype, 'cameraZ', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.vrp.value.z;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.vrp.value.z = value;
|
||||
}
|
||||
|
||||
});
|
||||
86
filters/ColorBars.js
Normal file
86
filters/ColorBars.js
Normal file
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* Original shader by thygate@gmail.com, rotation and color mix modifications by malc (mlashley@gmail.com)
|
||||
* Tweaked, uniforms added and converted to Phaser/PIXI by Richard Davey
|
||||
*/
|
||||
Phaser.Filter.ColorBars = function (game) {
|
||||
|
||||
Phaser.Filter.call(this, game);
|
||||
|
||||
this.uniforms.alpha = { type: '1f', value: 1 };
|
||||
// this.uniforms.origin = { type: '1f', value: 2.0 }
|
||||
|
||||
this.fragmentSrc = [
|
||||
|
||||
"// bars - thygate@gmail.com",
|
||||
"// rotation and color mix modifications by malc (mlashley@gmail.com)",
|
||||
"// modified by @hintz 2013-04-30",
|
||||
|
||||
"precision mediump float;",
|
||||
|
||||
"uniform vec3 resolution;",
|
||||
"uniform float time;",
|
||||
"uniform float alpha;",
|
||||
|
||||
"vec2 position;",
|
||||
"vec4 color;",
|
||||
|
||||
"float f = 6.0;",
|
||||
|
||||
"float c = cos(time / 2.0);",
|
||||
"float s = sin(time / 2.0);",
|
||||
"mat2 R = mat2(c, -s, s, -c);",
|
||||
|
||||
"//float barsize = 0.15;",
|
||||
"float barsize = 0.12;",
|
||||
"//float barsangle = 200.0 * sin(time * 0.001);",
|
||||
"float barsangle = 200.0 * cos(time * 0.001);",
|
||||
|
||||
"vec4 bar(float pos, float r, float g, float b) {",
|
||||
"return max(0.0, 1.0 - abs(pos - position.y) / barsize) * vec4(r, g, b, 1.0);",
|
||||
"}",
|
||||
|
||||
"void main(void)",
|
||||
"{",
|
||||
"position = (gl_FragCoord.xy - 0.5 * resolution.xy) / resolution.xx;",
|
||||
"//position = 2.0 * position * R; // R = rotation",
|
||||
"position = 2.5 * position * R;",
|
||||
"//float t = time * 0.5; // 0.5 = spin speed",
|
||||
"float t = time * 0.5;",
|
||||
"vec4 color = vec4(0.0);",
|
||||
"color += bar(sin(t), 1.0, 0.0, 0.0);",
|
||||
"color += bar(sin(t + barsangle / f * 2.), 1.0, 0.5, 0.0);",
|
||||
"color += bar(sin(t + barsangle / f * 4.), 1.0, 1.0, 0.0);",
|
||||
"color += bar(sin(t + barsangle / f * 6.), 0.0, 1.0, 0.0);",
|
||||
"color += bar(sin(t + barsangle / f * 8.), 0.0, 1.0, 1.0);",
|
||||
"color += bar(sin(t + barsangle / f * 10.), 0.0, 0.0, 1.0);",
|
||||
"color += bar(sin(t + barsangle / f * 12.), 0.5, 0.0, 1.0);",
|
||||
"color += bar(sin(t + barsangle / f * 14.), 1.0, 0.0, 1.0);",
|
||||
"color.a = alpha;",
|
||||
"gl_FragColor = color;",
|
||||
"}"
|
||||
|
||||
];
|
||||
|
||||
};
|
||||
|
||||
Phaser.Filter.ColorBars.prototype = Object.create(Phaser.Filter.prototype);
|
||||
Phaser.Filter.ColorBars.prototype.constructor = Phaser.Filter.ColorBars;
|
||||
|
||||
Phaser.Filter.ColorBars.prototype.init = function (width, height) {
|
||||
|
||||
this.setResolution(width, height);
|
||||
|
||||
};
|
||||
|
||||
Object.defineProperty(Phaser.Filter.ColorBars.prototype, 'alpha', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.alpha.value;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.alpha.value = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
112
filters/Fire.js
Normal file
112
filters/Fire.js
Normal file
@@ -0,0 +1,112 @@
|
||||
/**
|
||||
* Original shader by @301z (http://glsl.heroku.com/e#11707.0)
|
||||
* Tweaked, uniforms added and converted to Phaser/PIXI by Richard Davey
|
||||
*/
|
||||
Phaser.Filter.Fire = function (game) {
|
||||
|
||||
Phaser.Filter.call(this, game);
|
||||
|
||||
this.uniforms.alpha = { type: '1f', value: 1.0 };
|
||||
this.uniforms.shift = { type: '1f', value: 1.6 };
|
||||
this.uniforms.speed = { type: '2f', value: { x: 0.7, y: 0.4 } };
|
||||
|
||||
this.fragmentSrc = [
|
||||
|
||||
"precision mediump float;",
|
||||
"uniform vec2 resolution;",
|
||||
"uniform float time;",
|
||||
"uniform float alpha;",
|
||||
"uniform vec2 speed;",
|
||||
"uniform float shift;",
|
||||
|
||||
"float rand(vec2 n) {",
|
||||
"return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);",
|
||||
"}",
|
||||
|
||||
"float noise(vec2 n) {",
|
||||
"const vec2 d = vec2(0.0, 1.0);",
|
||||
"vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));",
|
||||
"return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);",
|
||||
"}",
|
||||
|
||||
"float fbm(vec2 n) {",
|
||||
"float total = 0.0, amplitude = 1.0;",
|
||||
"for (int i = 0; i < 4; i++) {",
|
||||
"total += noise(n) * amplitude;",
|
||||
"n += n;",
|
||||
"amplitude *= 0.5;",
|
||||
"}",
|
||||
"return total;",
|
||||
"}",
|
||||
|
||||
"void main() {",
|
||||
|
||||
"const vec3 c1 = vec3(0.5, 0.0, 0.1);",
|
||||
"const vec3 c2 = vec3(0.9, 0.0, 0.0);",
|
||||
"const vec3 c3 = vec3(0.2, 0.0, 0.0);",
|
||||
"const vec3 c4 = vec3(1.0, 0.9, 0.0);",
|
||||
"const vec3 c5 = vec3(0.1);",
|
||||
"const vec3 c6 = vec3(0.9);",
|
||||
|
||||
"vec2 p = gl_FragCoord.xy * 8.0 / resolution.xx;",
|
||||
"float q = fbm(p - time * 0.1);",
|
||||
"vec2 r = vec2(fbm(p + q + time * speed.x - p.x - p.y), fbm(p + q - time * speed.y));",
|
||||
"vec3 c = mix(c1, c2, fbm(p + r)) + mix(c3, c4, r.x) - mix(c5, c6, r.y);",
|
||||
"gl_FragColor = vec4(c * cos(shift * gl_FragCoord.y / resolution.y), alpha);",
|
||||
"}"
|
||||
];
|
||||
|
||||
};
|
||||
|
||||
Phaser.Filter.Fire.prototype = Object.create(Phaser.Filter.prototype);
|
||||
Phaser.Filter.Fire.prototype.constructor = Phaser.Filter.Fire;
|
||||
|
||||
Phaser.Filter.Fire.prototype.init = function (width, height, alpha, shift) {
|
||||
|
||||
this.setResolution(width, height);
|
||||
|
||||
if (typeof alpha !== 'undefined') {
|
||||
this.uniforms.alpha.value = alpha;
|
||||
}
|
||||
|
||||
if (typeof shift !== 'undefined') {
|
||||
this.uniforms.shift.value = shift;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Object.defineProperty(Phaser.Filter.Fire.prototype, 'alpha', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.alpha.value;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.alpha.value = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.Filter.Fire.prototype, 'shift', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.shift.value;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.shift.value = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.Filter.Fire.prototype, 'speed', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.speed.value;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.speed.value = value;
|
||||
}
|
||||
|
||||
});
|
||||
50
filters/Gray.js
Normal file
50
filters/Gray.js
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* @author Mat Groves http://matgroves.com/ @Doormat23
|
||||
*/
|
||||
|
||||
/**
|
||||
* This turns your displayObjects to grayscale.
|
||||
* @class Gray
|
||||
* @contructor
|
||||
*/
|
||||
Phaser.Filter.Gray = function (game) {
|
||||
|
||||
Phaser.Filter.call(this, game);
|
||||
|
||||
this.uniforms.gray = { type: '1f', value: 1.0 };
|
||||
|
||||
this.fragmentSrc = [
|
||||
|
||||
"precision mediump float;",
|
||||
|
||||
"varying vec2 vTextureCoord;",
|
||||
"varying vec4 vColor;",
|
||||
"uniform sampler2D uSampler;",
|
||||
"uniform float gray;",
|
||||
|
||||
"void main(void) {",
|
||||
"gl_FragColor = texture2D(uSampler, vTextureCoord);",
|
||||
"gl_FragColor.rgb = mix(gl_FragColor.rgb, vec3(0.2126 * gl_FragColor.r + 0.7152 * gl_FragColor.g + 0.0722 * gl_FragColor.b), gray);",
|
||||
"}"
|
||||
];
|
||||
|
||||
};
|
||||
|
||||
Phaser.Filter.Gray.prototype = Object.create(Phaser.Filter.prototype);
|
||||
Phaser.Filter.Gray.prototype.constructor = Phaser.Filter.Gray;
|
||||
|
||||
/**
|
||||
* The strength of the gray. 1 will make the object black and white, 0 will make the object its normal color
|
||||
* @property gray
|
||||
*/
|
||||
Object.defineProperty(Phaser.Filter.Gray.prototype, 'gray', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.gray.value;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.gray.value = value;
|
||||
}
|
||||
|
||||
});
|
||||
79
filters/HueRotate.js
Normal file
79
filters/HueRotate.js
Normal file
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* Original shader by Daniil (https://www.shadertoy.com/view/4sl3DH)
|
||||
* Tweaked, uniforms added and converted to Phaser/PIXI by Richard Davey
|
||||
*/
|
||||
Phaser.Filter.HueRotate = function (game) {
|
||||
|
||||
Phaser.Filter.call(this, game);
|
||||
|
||||
this.uniforms.alpha = { type: '1f', value: 1.0 };
|
||||
this.uniforms.size = { type: '1f', value: 0.03 };
|
||||
this.uniforms.iChannel0 = { type: 'sampler2D', value: null, textureData: { repeat: true } };
|
||||
|
||||
this.fragmentSrc = [
|
||||
|
||||
"precision mediump float;",
|
||||
"uniform vec2 resolution;",
|
||||
"uniform float time;",
|
||||
"uniform float alpha;",
|
||||
"uniform sampler2D iChannel0;",
|
||||
|
||||
"/* Simple hue rotation filter based on article:",
|
||||
"http://beesbuzz.biz/code/hsv_color_transforms.php",
|
||||
"*/",
|
||||
|
||||
"#define SPEED 10.0",
|
||||
|
||||
"void main(void)",
|
||||
"{",
|
||||
"vec2 uv = gl_FragCoord.xy / resolution.xy;",
|
||||
|
||||
"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.000, 0.000, 0.000, 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.000, 0.000, 0.000, 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.000, 0.000, 0.000, 0.0) * s;",
|
||||
|
||||
"vec4 pixel = texture2D(iChannel0, uv);",
|
||||
|
||||
"gl_FragColor = pixel * hueRotation;",
|
||||
"}"
|
||||
];
|
||||
|
||||
};
|
||||
|
||||
Phaser.Filter.HueRotate.prototype = Object.create(Phaser.Filter.prototype);
|
||||
Phaser.Filter.HueRotate.prototype.constructor = Phaser.Filter.HueRotate;
|
||||
|
||||
Phaser.Filter.HueRotate.prototype.init = function (width, height, texture) {
|
||||
|
||||
this.setResolution(width, height);
|
||||
|
||||
this.uniforms.iChannel0.value = texture;
|
||||
|
||||
};
|
||||
|
||||
Object.defineProperty(Phaser.Filter.HueRotate.prototype, 'alpha', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.alpha.value;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.alpha.value = value;
|
||||
}
|
||||
|
||||
});
|
||||
130
filters/LightBeam.js
Normal file
130
filters/LightBeam.js
Normal file
@@ -0,0 +1,130 @@
|
||||
/**
|
||||
* Original shader from http://glsl.heroku.com/e#4122.10
|
||||
* Tweaked, uniforms added and converted to Phaser/PIXI by Richard Davey
|
||||
*/
|
||||
Phaser.Filter.LightBeam = function (game) {
|
||||
|
||||
Phaser.Filter.call(this, game);
|
||||
|
||||
this.uniforms.alpha = { type: '1f', value: 1 };
|
||||
this.uniforms.thickness = { type: '1f', value: 70.0 };
|
||||
this.uniforms.speed = { type: '1f', value: 1.0 };
|
||||
this.uniforms.red = { type: '1f', value: 2.0 };
|
||||
this.uniforms.green = { type: '1f', value: 1.0 };
|
||||
this.uniforms.blue = { type: '1f', value: 1.0 };
|
||||
|
||||
this.fragmentSrc = [
|
||||
|
||||
"precision mediump float;",
|
||||
"uniform vec2 resolution;",
|
||||
"uniform float time;",
|
||||
"uniform float alpha;",
|
||||
"uniform float thickness;",
|
||||
"uniform float speed;",
|
||||
"uniform float red;",
|
||||
"uniform float green;",
|
||||
"uniform float blue;",
|
||||
|
||||
"void main(void) {",
|
||||
|
||||
"vec2 uPos = (gl_FragCoord.xy / resolution.xy);",
|
||||
|
||||
"uPos.y -= 0.50;",
|
||||
|
||||
"float vertColor = 0.0;",
|
||||
|
||||
"for (float i = 0.0; i < 1.0; i++)",
|
||||
"{",
|
||||
"float t = time * (i + speed);",
|
||||
"uPos.y += sin(uPos.x + t) * 0.2;",
|
||||
"float fTemp = abs(1.0 / uPos.y / thickness);",
|
||||
"vertColor += fTemp;",
|
||||
"}",
|
||||
|
||||
"vec4 color = vec4(vertColor * red, vertColor * green, vertColor * blue, alpha);",
|
||||
"gl_FragColor = color;",
|
||||
"}"
|
||||
];
|
||||
|
||||
};
|
||||
|
||||
Phaser.Filter.LightBeam.prototype = Object.create(Phaser.Filter.prototype);
|
||||
Phaser.Filter.LightBeam.prototype.constructor = Phaser.Filter.LightBeam;
|
||||
|
||||
Phaser.Filter.LightBeam.prototype.init = function (width, height) {
|
||||
|
||||
this.setResolution(width, height);
|
||||
|
||||
};
|
||||
|
||||
Object.defineProperty(Phaser.Filter.LightBeam.prototype, 'alpha', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.alpha.value;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.alpha.value = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.Filter.LightBeam.prototype, 'red', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.red.value;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.red.value = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.Filter.LightBeam.prototype, 'green', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.green.value;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.green.value = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.Filter.LightBeam.prototype, 'blue', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.blue.value;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.blue.value = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.Filter.LightBeam.prototype, 'thickness', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.thickness.value;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.thickness.value = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.Filter.LightBeam.prototype, 'speed', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.speed.value;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.speed.value = value;
|
||||
}
|
||||
|
||||
});
|
||||
108
filters/Marble.js
Normal file
108
filters/Marble.js
Normal file
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* Original shader from http://glsl.heroku.com/e#9213.0
|
||||
* Tweaked, uniforms added and converted to Phaser/PIXI by Richard Davey
|
||||
*/
|
||||
Phaser.Filter.Marble = function (game) {
|
||||
|
||||
Phaser.Filter.call(this, game);
|
||||
|
||||
this.uniforms.alpha = { type: '1f', value: 1.0 };
|
||||
|
||||
// Drives speed, higher number will make it slower.
|
||||
this.uniforms.fluid_speed = { type: '1f', value: 10.0 };
|
||||
|
||||
this.uniforms.color_intensity = { type: '1f', value: 0.30 };
|
||||
|
||||
// The fragment shader source
|
||||
this.fragmentSrc = [
|
||||
|
||||
"precision mediump float;",
|
||||
"uniform vec2 resolution;",
|
||||
"uniform float time;",
|
||||
"uniform vec2 mouse;",
|
||||
"uniform float alpha;",
|
||||
"uniform float fluid_speed;",
|
||||
"uniform float color_intensity;",
|
||||
|
||||
"const int complexity = 40; // More points of color.",
|
||||
"const float mouse_factor = 25.0; // Makes it more/less jumpy.",
|
||||
"const float mouse_offset = 5.0; // Drives complexity in the amount of curls/cuves. Zero is a single whirlpool.",
|
||||
|
||||
"const float Pi = 3.14159;",
|
||||
|
||||
"float sinApprox(float x) {",
|
||||
"x = Pi + (2.0 * Pi) * floor(x / (2.0 * Pi)) - x;",
|
||||
"return (4.0 / Pi) * x - (4.0 / Pi / Pi) * x * abs(x);",
|
||||
"}",
|
||||
|
||||
"float cosApprox(float x) {",
|
||||
"return sinApprox(x + 0.5 * Pi);",
|
||||
"}",
|
||||
|
||||
"void main()",
|
||||
"{",
|
||||
"vec2 p=(2.0*gl_FragCoord.xy-resolution)/max(resolution.x,resolution.y);",
|
||||
"for(int i=1;i<complexity;i++)",
|
||||
"{",
|
||||
"vec2 newp=p;",
|
||||
"newp.x+=0.6/float(i)*sin(float(i)*p.y+time/fluid_speed+0.3*float(i))+mouse.y/mouse_factor+mouse_offset;",
|
||||
"newp.y+=0.6/float(i)*sin(float(i)*p.x+time/fluid_speed+0.3*float(i+10))-mouse.x/mouse_factor+mouse_offset;",
|
||||
"p=newp;",
|
||||
"}",
|
||||
"vec3 col=vec3(color_intensity*sin(3.0*p.x)+color_intensity,color_intensity*sin(3.0*p.y)+color_intensity,color_intensity*sin(p.x+p.y)+color_intensity);",
|
||||
"gl_FragColor=vec4(col, alpha);",
|
||||
"}"
|
||||
];
|
||||
|
||||
};
|
||||
|
||||
Phaser.Filter.Marble.prototype = Object.create(Phaser.Filter.prototype);
|
||||
Phaser.Filter.Marble.prototype.constructor = Phaser.Filter.Marble;
|
||||
|
||||
Phaser.Filter.Marble.prototype.init = function (width, height, speed, intensity) {
|
||||
|
||||
this.setResolution(width, height);
|
||||
|
||||
if (typeof speed === 'undefined') { speed = 10.0; }
|
||||
if (typeof intensity === 'undefined') { intensity = 0.30; }
|
||||
|
||||
this.uniforms.fluid_speed.value = speed;
|
||||
this.uniforms.color_intensity.value = intensity;
|
||||
|
||||
};
|
||||
|
||||
Object.defineProperty(Phaser.Filter.Marble.prototype, 'alpha', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.alpha.value;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.alpha.value = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.Filter.Marble.prototype, 'speed', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.fluid_speed.value;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.fluid_speed.value = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.Filter.Marble.prototype, 'intensity', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.color_intensity.value;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.color_intensity.value = value;
|
||||
}
|
||||
|
||||
});
|
||||
123
filters/Plasma.js
Normal file
123
filters/Plasma.js
Normal file
@@ -0,0 +1,123 @@
|
||||
/**
|
||||
* Original shader by TriggerHLM (https://www.shadertoy.com/view/MdXGDH)
|
||||
* Tweaked, uniforms added and converted to Phaser/PIXI by Richard Davey
|
||||
*/
|
||||
Phaser.Filter.Plasma = function (game) {
|
||||
|
||||
Phaser.Filter.call(this, game);
|
||||
|
||||
this.uniforms.alpha = { type: '1f', value: 1.0 };
|
||||
this.uniforms.size = { type: '1f', value: 0.03 };
|
||||
this.uniforms.redShift = { type: '1f', value: 0.5 };
|
||||
this.uniforms.greenShift = { type: '1f', value: 0.5 };
|
||||
this.uniforms.blueShift = { type: '1f', value: 0.9 };
|
||||
|
||||
this.fragmentSrc = [
|
||||
|
||||
"precision mediump float;",
|
||||
"uniform float time;",
|
||||
"uniform float alpha;",
|
||||
"uniform float size;",
|
||||
"uniform float redShift;",
|
||||
"uniform float greenShift;",
|
||||
"uniform float blueShift;",
|
||||
|
||||
"const float PI = 3.14159265;",
|
||||
|
||||
"float ptime = time * 0.1;",
|
||||
|
||||
"void main(void) {",
|
||||
|
||||
"float color1, color2, color;",
|
||||
|
||||
"color1 = (sin(dot(gl_FragCoord.xy, vec2(sin(ptime * 3.0), cos(ptime * 3.0))) * 0.02 + ptime * 3.0) + 1.0) / 2.0;",
|
||||
"vec2 center = vec2(640.0 / 2.0, 360.0 / 2.0) + vec2(640.0 / 2.0 * sin(-ptime * 3.0), 360.0 / 2.0 * cos(-ptime * 3.0));",
|
||||
"color2 = (cos(length(gl_FragCoord.xy - center) * size) + 1.0) / 2.0;",
|
||||
"color = (color1 + color2) / 2.0;",
|
||||
|
||||
"float red = (cos(PI * color / redShift + ptime * 3.0) + 1.0) / 2.0;",
|
||||
"float green = (sin(PI * color / greenShift + ptime * 3.0) + 1.0) / 2.0;",
|
||||
"float blue = (sin(PI * color / blueShift + ptime * 3.0) + 1.0) / 2.0;",
|
||||
|
||||
"gl_FragColor = vec4(red, green, blue, alpha);",
|
||||
"}"
|
||||
];
|
||||
|
||||
};
|
||||
|
||||
Phaser.Filter.Plasma.prototype = Object.create(Phaser.Filter.prototype);
|
||||
Phaser.Filter.Plasma.prototype.constructor = Phaser.Filter.Plasma;
|
||||
|
||||
Phaser.Filter.Plasma.prototype.init = function (width, height, alpha, size) {
|
||||
|
||||
this.setResolution(width, height);
|
||||
|
||||
if (typeof alpha !== 'undefined') {
|
||||
this.uniforms.alpha.value = alpha;
|
||||
}
|
||||
|
||||
if (typeof size !== 'undefined') {
|
||||
this.uniforms.size.value = size;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Object.defineProperty(Phaser.Filter.Plasma.prototype, 'alpha', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.alpha.value;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.alpha.value = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.Filter.Plasma.prototype, 'size', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.size.value;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.size.value = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.Filter.Plasma.prototype, 'redShift', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.redShift.value;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.redShift.value = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.Filter.Plasma.prototype, 'greenShift', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.greenShift.value;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.greenShift.value = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.Filter.Plasma.prototype, 'blueShift', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.blueShift.value;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.blueShift.value = value;
|
||||
}
|
||||
|
||||
});
|
||||
51
filters/SampleFilter.js
Normal file
51
filters/SampleFilter.js
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* A sample demonstrating how to create new Phaser Filters.
|
||||
*/
|
||||
Phaser.Filter.SampleFilter = function (game) {
|
||||
|
||||
Phaser.Filter.call(this, game);
|
||||
|
||||
/**
|
||||
* By default the following uniforms are already created and available:
|
||||
*
|
||||
* uniform float time - The current number of elapsed milliseconds in the game.
|
||||
* uniform vec3 resolution - The dimensions of the filter. Can be set via setSize(width, height)
|
||||
* uniform vec4 mouse - The mouse / touch coordinates taken from the pointer given to the update function, if any.
|
||||
* uniform sampler2D uSampler - The current texture (usually the texture of the Sprite the shader is bound to)
|
||||
*
|
||||
* Add in any additional vars you require. Here is a new one called 'wobble' that is a 2f:
|
||||
*
|
||||
* this.uniforms.wobble = { type: '2f', value: { x: 0, y: 0 }};
|
||||
*
|
||||
* The supported types are: 1f, 1fv, 1i, 2f, 2fv, 2i, 2iv, 3f, 3fv, 3i, 3iv, 4f, 4fv, 4i, 4iv, mat2, mat3, mat4 and sampler2D.
|
||||
*/
|
||||
|
||||
this.uniforms.divisor = { type: '1f', value: 0.5 };
|
||||
|
||||
// The fragment shader source
|
||||
this.fragmentSrc = [
|
||||
|
||||
"precision mediump float;",
|
||||
"uniform vec3 resolution;",
|
||||
"uniform float time;",
|
||||
"uniform float divisor;",
|
||||
|
||||
"void main(void) {",
|
||||
"vec2 uv = gl_FragCoord.xy / resolution.xy;",
|
||||
"gl_FragColor = vec4(uv, divisor * sin(time), 0.0);",
|
||||
"}"
|
||||
];
|
||||
|
||||
};
|
||||
|
||||
Phaser.Filter.SampleFilter.prototype = Object.create(Phaser.Filter.prototype);
|
||||
Phaser.Filter.SampleFilter.prototype.constructor = Phaser.Filter.SampleFilter;
|
||||
|
||||
Phaser.Filter.SampleFilter.prototype.init = function (width, height, divisor) {
|
||||
|
||||
if (typeof divisor == 'undefined') { divisor = 0.5; }
|
||||
|
||||
this.setResolution(width, height);
|
||||
this.uniforms.divisor.value = divisor;
|
||||
|
||||
};
|
||||
71
filters/Tunnel.js
Normal file
71
filters/Tunnel.js
Normal file
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* Original shader by 4rknova (https://www.shadertoy.com/view/lssGDn)
|
||||
* Tweaked, uniforms added and converted to Phaser/PIXI by Richard Davey
|
||||
*/
|
||||
Phaser.Filter.Tunnel = function (game) {
|
||||
|
||||
Phaser.Filter.call(this, game);
|
||||
|
||||
this.uniforms.alpha = { type: '1f', value: 1 };
|
||||
this.uniforms.origin = { type: '1f', value: 2.0 };
|
||||
this.uniforms.iChannel0 = { type: 'sampler2D', value: null, textureData: { repeat: true } };
|
||||
|
||||
this.fragmentSrc = [
|
||||
|
||||
"precision mediump float;",
|
||||
"uniform vec2 resolution;",
|
||||
"uniform float time;",
|
||||
"uniform sampler2D iChannel0;",
|
||||
"uniform float alpha;",
|
||||
"uniform float origin;",
|
||||
|
||||
"#define S 0.79577471545 // Precalculated 2.5 / PI",
|
||||
"#define E 0.0001",
|
||||
|
||||
"void main(void)",
|
||||
"{",
|
||||
"vec2 p = (origin * gl_FragCoord.xy / resolution.xy - 1.0) * vec2(resolution.x / resolution.y, 1.0);",
|
||||
"vec2 t = vec2(S * atan(p.x, p.y), 1.0 / max(length(p), E));",
|
||||
"vec3 c = texture2D(iChannel0, t + vec2(time * 0.1, time)).xyz;",
|
||||
"gl_FragColor = vec4(c / (t.y + 0.5), alpha);",
|
||||
"}"
|
||||
|
||||
];
|
||||
|
||||
};
|
||||
|
||||
Phaser.Filter.Tunnel.prototype = Object.create(Phaser.Filter.prototype);
|
||||
Phaser.Filter.Tunnel.prototype.constructor = Phaser.Filter.Tunnel;
|
||||
|
||||
Phaser.Filter.Tunnel.prototype.init = function (width, height, texture) {
|
||||
|
||||
this.setResolution(width, height);
|
||||
this.uniforms.iChannel0.value = texture;
|
||||
|
||||
texture.baseTexture._powerOf2 = true;
|
||||
|
||||
};
|
||||
|
||||
Object.defineProperty(Phaser.Filter.Tunnel.prototype, 'alpha', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.alpha.value;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.alpha.value = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.Filter.Tunnel.prototype, 'origin', {
|
||||
|
||||
get: function() {
|
||||
return this.uniforms.origin.value;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.uniforms.origin.value = value;
|
||||
}
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user