ShaderToy convertor up and working, lots of shaders being turned into Pixi filters :)
|
@ -78,6 +78,7 @@ Version 1.1.3 - in build
|
|||
* Updated: Sprite will now check the exists property of the Group it is in, if the Group.exists = false the Sprite won't update.
|
||||
* Updated: Lots of documentation tweaks across various files such as Pointer and Color.
|
||||
* Updated: If you specify 'null' as a Group parent it will now revert to using the World as the parent (before only 'undefined' worked)
|
||||
* Updated: Skip preupdate/update for PIXI hierarchies in which an ancestor doesn't exist (thanks cocoademon)
|
||||
|
||||
|
||||
|
||||
|
|
BIN
examples/wip/64x64.png
Normal file
After Width: | Height: | Size: 196 B |
94
examples/wip/TRSIPlasmaFilter.js
Normal file
|
@ -0,0 +1,94 @@
|
|||
PIXI.TRSIPlasmaFilter = function(width, height)
|
||||
{
|
||||
PIXI.AbstractFilter.call( this );
|
||||
|
||||
this.passes = [this];
|
||||
|
||||
var d = new Date();
|
||||
|
||||
var dates = [
|
||||
d.getFullYear(), // the year (four digits)
|
||||
d.getMonth(), // the month (from 0-11)
|
||||
d.getDate(), // the day of the month (from 1-31)
|
||||
d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds()
|
||||
];
|
||||
|
||||
this.uniforms = {
|
||||
iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }},
|
||||
iGlobalTime: { type: 'f', value: 1 },
|
||||
iDate: { type: 'f4', value: dates }
|
||||
};
|
||||
|
||||
// Shader by Rebb / TRSI (https://www.shadertoy.com/view/XdX3Wn)
|
||||
this.fragmentSrc = [
|
||||
"precision mediump float;",
|
||||
"uniform vec3 iResolution;",
|
||||
"uniform float iGlobalTime;",
|
||||
"uniform float iChannelTime[4];",
|
||||
"uniform vec4 iMouse;",
|
||||
"uniform vec4 iDate;",
|
||||
"uniform vec3 iChannelResolution[4];",
|
||||
"// add any extra uniforms here",
|
||||
|
||||
"// Rebb/TRSi^Paradise",
|
||||
|
||||
"float an= sin(iGlobalTime)/3.14157;",
|
||||
"float as= sin(an);",
|
||||
"float zoo = .23232+.38*sin(.7*iGlobalTime);",
|
||||
"void main(void)",
|
||||
"{",
|
||||
"vec2 position = ( gl_FragCoord.xy / iResolution.xy *3.3 );",
|
||||
|
||||
"float color = 0.0;",
|
||||
"color += sin(position.x - position.y) ;",
|
||||
"color += sin(iGlobalTime)* cos(sin(iGlobalTime)*position.y*position.x*sin(position.x))+.008;",
|
||||
"color += sin(iGlobalTime)+position.x*sin(position.y*sin(sin(tan(cos (iGlobalTime)))));",
|
||||
"gl_FragColor = vec4( vec3(sin(color*color)*4.0, sin(color*color) , color )*sin(iGlobalTime+position.x/(iGlobalTime*3.14)),iGlobalTime/10.828 );",
|
||||
|
||||
"}"];
|
||||
|
||||
}
|
||||
|
||||
PIXI.TRSIPlasmaFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
|
||||
PIXI.TRSIPlasmaFilter.prototype.constructor = PIXI.TRSIPlasmaFilter;
|
||||
|
||||
Object.defineProperty(PIXI.TRSIPlasmaFilter.prototype, 'iGlobalTime', {
|
||||
get: function() {
|
||||
return this.uniforms.iGlobalTime.value;
|
||||
},
|
||||
set: function(value) {
|
||||
this.uniforms.iGlobalTime.value = value;
|
||||
}
|
||||
});
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('texture', 'wip/64x64.png');
|
||||
|
||||
}
|
||||
|
||||
var filter;
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
sprite = game.add.sprite(0, 0, 'texture');
|
||||
sprite.width = 800;
|
||||
sprite.height = 600;
|
||||
|
||||
filter = new PIXI.TRSIPlasmaFilter(sprite.width, sprite.height);
|
||||
|
||||
sprite.filters = [filter];
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
filter.iGlobalTime = game.time.totalElapsedSeconds();
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
}
|
136
examples/wip/c64PlasmaFilter.js
Normal file
|
@ -0,0 +1,136 @@
|
|||
PIXI.C64PlasmaFilter = function(width, height)
|
||||
{
|
||||
PIXI.AbstractFilter.call( this );
|
||||
|
||||
this.passes = [this];
|
||||
|
||||
var d = new Date();
|
||||
|
||||
var dates = [
|
||||
d.getFullYear(), // the year (four digits)
|
||||
d.getMonth(), // the month (from 0-11)
|
||||
d.getDate(), // the day of the month (from 1-31)
|
||||
d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds()
|
||||
];
|
||||
|
||||
this.uniforms = {
|
||||
iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }},
|
||||
iGlobalTime: { type: 'f', value: 1 },
|
||||
iDate: { type: 'f4', value: dates }
|
||||
};
|
||||
|
||||
// Shader by ssdsa (https://www.shadertoy.com/view/MslGzN)
|
||||
this.fragmentSrc = [
|
||||
"precision mediump float;",
|
||||
"uniform vec3 iResolution;",
|
||||
"uniform float iGlobalTime;",
|
||||
"uniform float iChannelTime[4];",
|
||||
"uniform vec4 iMouse;",
|
||||
"uniform vec4 iDate;",
|
||||
"uniform vec3 iChannelResolution[4];",
|
||||
"// add any extra uniforms here",
|
||||
|
||||
"// 2D plasma in C64 graphics style",
|
||||
"//",
|
||||
"// Version 1.0 (2013-03-31)",
|
||||
"// Simon Stelling-de San Antonio",
|
||||
|
||||
"float camtime = 1.23*iGlobalTime;",
|
||||
|
||||
"void main(void)",
|
||||
"{",
|
||||
"vec2 p = gl_FragCoord.xy / iResolution.xy;",
|
||||
"p.y = 1.0 - p.y;",
|
||||
"p *= 200.0;",
|
||||
"p.x *= (iResolution.x / iResolution.y);",
|
||||
"p.x /= 2.0;",
|
||||
"p = floor(p);",
|
||||
"p.x *= 2.0;",
|
||||
"float a = p.x+30.0*sin(p.x/21.0 + 0.3*sin(0.4*camtime))+20.0*cos(p.y/19.0 + 0.2*cos(0.6*camtime))-160.0;",
|
||||
"float b = p.y+30.0*cos(p.y/18.0 + 0.4*sin(0.7*camtime))+20.0*sin(p.x/16.0 + 0.5*cos(0.7*camtime))- 97.0;",
|
||||
"float e = floor((length(vec2(a,b))",
|
||||
"+4.0*mod(floor((p.x+p.y+p.y)/2.0),2.0))/13.0);",
|
||||
"float c;",
|
||||
"if (e == 0.0) { c = 9.0;",
|
||||
"} else if (e == 1.0) { c = 2.0;",
|
||||
"} else if (e == 2.0) { c = 8.0;",
|
||||
"} else if (e == 3.0) { c = 10.0;",
|
||||
"} else if (e == 4.0) { c = 15.0;",
|
||||
"} else if (e == 5.0) { c = 7.0;",
|
||||
"} else if (e == 6.0) { c = 1.0;",
|
||||
"} else if (e == 7.0) { c = 13.0;",
|
||||
"} else if (e == 8.0) { c = 3.0;",
|
||||
"} else if (e == 9.0) { c = 14.0;",
|
||||
"} else if (e == 10.0) { c = 4.0;",
|
||||
"} else if (e == 11.0) { c = 6.0;",
|
||||
"} else if (e == 12.0) { c = 0.0;",
|
||||
"} else if (e == 13.0) { c = 11.0;",
|
||||
"} else if (e == 14.0) { c = 5.0;",
|
||||
"} else { c = 12.0;",
|
||||
"}",
|
||||
"vec3 col;",
|
||||
"if (c == 0.0) { col = vec3(0.0);",
|
||||
"} else if (c == 1.0) { col = vec3(1.0);",
|
||||
"} else if (c == 2.0) { col = vec3(137.0, 64.0, 54.0)/256.0;",
|
||||
"} else if (c == 3.0) { col = vec3(122.0, 191.0, 199.0)/256.0;",
|
||||
"} else if (c == 4.0) { col = vec3(138.0, 70.0, 174.0)/256.0;",
|
||||
"} else if (c == 5.0) { col = vec3(104.0, 169.0, 65.0)/256.0;",
|
||||
"} else if (c == 6.0) { col = vec3( 62.0, 49.0, 162.0)/256.0;",
|
||||
"} else if (c == 7.0) { col = vec3(208.0, 220.0, 113.0)/256.0;",
|
||||
"} else if (c == 8.0) { col = vec3(144.0, 95.0, 37.0)/256.0;",
|
||||
"} else if (c == 9.0) { col = vec3( 92.0, 71.0, 0.0)/256.0;",
|
||||
"} else if (c == 10.0) { col = vec3(187.0, 119.0, 109.0)/256.0;",
|
||||
"} else if (c == 11.0) { col = vec3( 85.0, 85.0, 85.0)/256.0;",
|
||||
"} else if (c == 12.0) { col = vec3(128.0, 128.0, 128.0)/256.0;",
|
||||
"} else if (c == 13.0) { col = vec3(172.0, 234.0, 136.0)/256.0;",
|
||||
"} else if (c == 14.0) { col = vec3(124.0, 112.0, 218.0)/256.0;",
|
||||
"} else { col = vec3(171.0, 171.0, 171.0)/256.0;",
|
||||
"}",
|
||||
"gl_FragColor = vec4(col,1.0);",
|
||||
"}"];
|
||||
|
||||
}
|
||||
|
||||
PIXI.C64PlasmaFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
|
||||
PIXI.C64PlasmaFilter.prototype.constructor = PIXI.C64PlasmaFilter;
|
||||
|
||||
Object.defineProperty(PIXI.C64PlasmaFilter.prototype, 'iGlobalTime', {
|
||||
get: function() {
|
||||
return this.uniforms.iGlobalTime.value;
|
||||
},
|
||||
set: function(value) {
|
||||
this.uniforms.iGlobalTime.value = value;
|
||||
}
|
||||
});
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('texture', 'wip/64x64.png');
|
||||
|
||||
}
|
||||
|
||||
var filter;
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
sprite = game.add.sprite(0, 0, 'texture');
|
||||
sprite.width = 800;
|
||||
sprite.height = 600;
|
||||
|
||||
filter = new PIXI.C64PlasmaFilter(sprite.width, sprite.height);
|
||||
|
||||
sprite.filters = [filter];
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
filter.iGlobalTime = game.time.totalElapsedSeconds();
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
}
|
78
examples/wip/colorBoxFilter.js
Normal file
|
@ -0,0 +1,78 @@
|
|||
PIXI.ColorBoxFilter = function()
|
||||
{
|
||||
PIXI.AbstractFilter.call( this );
|
||||
|
||||
this.passes = [this];
|
||||
|
||||
var d = new Date();
|
||||
|
||||
var dates = [
|
||||
d.getFullYear(), // the year (four digits)
|
||||
d.getMonth(), // the month (from 0-11)
|
||||
d.getDate(), // the day of the month (from 1-31)
|
||||
d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds()
|
||||
];
|
||||
|
||||
this.uniforms = {
|
||||
iResolution: { type: 'f3', value: { x: 800, y: 600, z: 0 }},
|
||||
iGlobalTime: { type: 'f', value: 1 },
|
||||
iDate: { type: 'f4', value: dates }
|
||||
};
|
||||
|
||||
this.fragmentSrc = [
|
||||
"precision mediump float;",
|
||||
"uniform vec3 iResolution;",
|
||||
"uniform float iGlobalTime;",
|
||||
"uniform float iChannelTime[4];",
|
||||
"uniform vec4 iMouse;",
|
||||
"uniform vec4 iDate;",
|
||||
"uniform vec3 iChannelResolution[4];",
|
||||
|
||||
"void main(void) {",
|
||||
"vec2 uv = gl_FragCoord.xy / iResolution.xy;",
|
||||
"gl_FragColor = vec4(uv, 0.5 * sin(iGlobalTime), 0.0);",
|
||||
"}"
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
PIXI.ColorBoxFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
|
||||
PIXI.ColorBoxFilter.prototype.constructor = PIXI.ColorBoxFilter;
|
||||
|
||||
Object.defineProperty(PIXI.ColorBoxFilter.prototype, 'iGlobalTime', {
|
||||
get: function() {
|
||||
return this.uniforms.iGlobalTime.value;
|
||||
},
|
||||
set: function(value) {
|
||||
this.uniforms.iGlobalTime.value = value;
|
||||
}
|
||||
});
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('tex', 'wip/tex16.png');
|
||||
game.load.image('sea', 'assets/pics/undersea.jpg');
|
||||
|
||||
}
|
||||
|
||||
var stars;
|
||||
|
||||
function create() {
|
||||
|
||||
stars = new PIXI.ColorBoxFilter();
|
||||
|
||||
var a = game.add.sprite(0, 0, 'sea');
|
||||
a.filters = [stars];
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
stars.iGlobalTime = game.time.totalElapsedSeconds();
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
}
|
107
examples/wip/deformStarFilter.js
Normal file
|
@ -0,0 +1,107 @@
|
|||
PIXI.DeformStarFilter = function(width, height, texture)
|
||||
{
|
||||
PIXI.AbstractFilter.call( this );
|
||||
|
||||
this.passes = [this];
|
||||
|
||||
var d = new Date();
|
||||
|
||||
var dates = [
|
||||
d.getFullYear(), // the year (four digits)
|
||||
d.getMonth(), // the month (from 0-11)
|
||||
d.getDate(), // the day of the month (from 1-31)
|
||||
d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds()
|
||||
];
|
||||
|
||||
this.uniforms = {
|
||||
iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }},
|
||||
iGlobalTime: { type: 'f', value: 1 },
|
||||
iDate: { type: 'f4', value: dates },
|
||||
iChannel0: { type: 'sampler2D', value: texture }
|
||||
};
|
||||
|
||||
// Shader by iq (https://www.shadertoy.com/view/4dXGRn)
|
||||
this.fragmentSrc = [
|
||||
"precision mediump float;",
|
||||
"uniform vec3 iResolution;",
|
||||
"uniform float iGlobalTime;",
|
||||
"uniform float iChannelTime[4];",
|
||||
"uniform vec4 iMouse;",
|
||||
"uniform vec4 iDate;",
|
||||
"uniform vec3 iChannelResolution[4];",
|
||||
"uniform sampler2D iChannel0;",
|
||||
"// add any extra uniforms here",
|
||||
|
||||
"// Created by inigo quilez - iq/2013",
|
||||
"// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.",
|
||||
|
||||
"vec3 sqr( vec3 x ) { return x*x; }",
|
||||
"void main(void)",
|
||||
"{",
|
||||
"vec2 p = -1.0 + 2.0 * gl_FragCoord.xy / iResolution.xy;",
|
||||
"float a = atan(p.y,p.x);",
|
||||
"float r = sqrt(dot(p,p));",
|
||||
"float s = r * (1.0+0.5*cos(iGlobalTime*0.5));",
|
||||
|
||||
"vec2 uv = 0.02*p;",
|
||||
"uv.x += .03*cos(-iGlobalTime+a*4.0)/s;",
|
||||
"uv.y += .02*iGlobalTime +.03*sin(-iGlobalTime+a*4.0)/s;",
|
||||
"uv.y += r*r*0.025*sin(2.0*r);",
|
||||
|
||||
"vec3 col = texture2D( iChannel0, 0.5*uv).xyz * vec3(1.0,0.8,0.6);",
|
||||
"col += sqr(texture2D( iChannel0, 1.0*uv).xxx) * vec3(0.7,1.0,1.0);",
|
||||
|
||||
"float w = 2.0*r;",
|
||||
"w *= 0.5 + 0.5*pow(clamp(1.0-0.75*r,0.0,1.0),0.5);",
|
||||
|
||||
"gl_FragColor = vec4(col*w,1.0);",
|
||||
"}"];
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
PIXI.DeformStarFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
|
||||
PIXI.DeformStarFilter.prototype.constructor = PIXI.DeformStarFilter;
|
||||
|
||||
Object.defineProperty(PIXI.DeformStarFilter.prototype, 'iGlobalTime', {
|
||||
get: function() {
|
||||
return this.uniforms.iGlobalTime.value;
|
||||
},
|
||||
set: function(value) {
|
||||
this.uniforms.iGlobalTime.value = value;
|
||||
}
|
||||
});
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
// game.load.image('texture', 'wip/64x64.png');
|
||||
game.load.image('texture', 'wip/tex08.jpg');
|
||||
|
||||
}
|
||||
|
||||
var filter;
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
sprite = game.add.sprite(0, 0, 'texture');
|
||||
sprite.width = 800;
|
||||
sprite.height = 600;
|
||||
|
||||
filter = new PIXI.DeformStarFilter(sprite.width, sprite.height, sprite.texture);
|
||||
|
||||
sprite.filters = [filter];
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
filter.iGlobalTime = game.time.totalElapsedSeconds();
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
}
|
|
@ -1,46 +1,85 @@
|
|||
PIXI.GreyFilter = function()
|
||||
PIXI.StarNestFilter = function(width, height, texture)
|
||||
{
|
||||
PIXI.AbstractFilter.call( this );
|
||||
|
||||
this.passes = [this];
|
||||
|
||||
// set the uniforms
|
||||
this.uniforms = {
|
||||
grey: {type: 'f', value: 1},
|
||||
};
|
||||
|
||||
this.OLDfragmentSrc = [
|
||||
"precision mediump float;",
|
||||
"varying vec2 vTextureCoord;",
|
||||
"varying float vColor;",
|
||||
"uniform sampler2D uSampler;",
|
||||
"uniform float grey;",
|
||||
"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), grey);",
|
||||
"gl_FragColor = gl_FragColor * vColor;",
|
||||
"}"
|
||||
|
||||
var d = new Date();
|
||||
|
||||
var dates = [
|
||||
d.getFullYear(), // the year (four digits)
|
||||
d.getMonth(), // the month (from 0-11)
|
||||
d.getDate(), // the day of the month (from 1-31)
|
||||
d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds()
|
||||
];
|
||||
|
||||
this.uniforms = {
|
||||
iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }},
|
||||
iGlobalTime: { type: 'f', value: 1 },
|
||||
iDate: { type: 'f4', value: dates },
|
||||
iChannel0: { type: 'sampler2D', value: texture }
|
||||
};
|
||||
|
||||
// Shader by Kali (https://www.shadertoy.com/view/4dfGDM)
|
||||
this.fragmentSrc = [
|
||||
"precision mediump float;",
|
||||
"uniform vec3 iResolution;",
|
||||
"uniform float iGlobalTime;",
|
||||
"uniform float iChannelTime[4];",
|
||||
"uniform vec4 iMouse;",
|
||||
"uniform vec4 iDate;",
|
||||
"uniform vec3 iChannelResolution[4];",
|
||||
"uniform sampler2D iChannel0;",
|
||||
"// add any extra uniforms here",
|
||||
|
||||
"#define M_PI 3.1415926535897932384626433832795",
|
||||
|
||||
"float rand(vec2 co)",
|
||||
"{",
|
||||
"return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);",
|
||||
"}",
|
||||
|
||||
"void main(void)",
|
||||
"{",
|
||||
"float size = 30.0;",
|
||||
"float prob = 0.95;",
|
||||
|
||||
"vec2 pos = floor(1.0 / size * gl_FragCoord.xy);",
|
||||
|
||||
"float color = 0.0;",
|
||||
"float starValue = rand(pos);",
|
||||
|
||||
"if (starValue > prob)",
|
||||
"{",
|
||||
"vec2 center = size * pos + vec2(size, size) * 0.5;",
|
||||
|
||||
"float t = 0.9 + 0.2 * sin(iGlobalTime + (starValue - prob) / (1.0 - prob) * 45.0);",
|
||||
|
||||
"color = 1.0 - distance(gl_FragCoord.xy, center) / (0.5 * size);",
|
||||
"color = color * t / (abs(gl_FragCoord.y - center.y)) * t / (abs(gl_FragCoord.x - center.x));",
|
||||
"}",
|
||||
"else if (rand(gl_FragCoord.xy / iResolution.xy) > 0.996)",
|
||||
"{",
|
||||
"float r = rand(gl_FragCoord.xy);",
|
||||
"color = r * (0.25 * sin(iGlobalTime * (r * 5.0) + 720.0 * r) + 0.75);",
|
||||
"}",
|
||||
|
||||
"gl_FragColor = vec4(vec3(color), 1.0);",
|
||||
"}"];
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
PIXI.GreyFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
|
||||
PIXI.GreyFilter.prototype.constructor = PIXI.GreyFilter;
|
||||
PIXI.StarNestFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
|
||||
PIXI.StarNestFilter.prototype.constructor = PIXI.StarNestFilter;
|
||||
|
||||
/**
|
||||
The strength of the grey. 1 will make the object black and white, 0 will make the object its normal color
|
||||
@property grey
|
||||
*/
|
||||
Object.defineProperty(PIXI.GreyFilter.prototype, 'grey', {
|
||||
Object.defineProperty(PIXI.StarNestFilter.prototype, 'iGlobalTime', {
|
||||
get: function() {
|
||||
return this.uniforms.grey.value;
|
||||
return this.uniforms.iGlobalTime.value;
|
||||
},
|
||||
set: function(value) {
|
||||
this.uniforms.grey.value = value;
|
||||
this.uniforms.iGlobalTime.value = value;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -48,20 +87,30 @@ var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: p
|
|||
|
||||
function preload() {
|
||||
|
||||
game.load.image('atari1', 'assets/sprites/atari130xe.png');
|
||||
game.load.image('coke', 'assets/sprites/cokecan.png');
|
||||
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
|
||||
// game.load.image('texture', 'wip/64x64.png');
|
||||
game.load.image('texture', 'wip/tex08.jpg');
|
||||
|
||||
}
|
||||
|
||||
var filter;
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
game.add.sprite(60, 100, 'atari1');
|
||||
game.add.sprite(360, 200, 'coke');
|
||||
sprite = game.add.sprite(0, 0, 'texture');
|
||||
sprite.width = 800;
|
||||
sprite.height = 600;
|
||||
|
||||
filter = new PIXI.StarNestFilter(sprite.width, sprite.height, sprite.texture);
|
||||
|
||||
sprite.filters = [filter];
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
filter.iGlobalTime = game.time.totalElapsedSeconds();
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
|
|
@ -1,13 +1,76 @@
|
|||
<?php
|
||||
function getTabs() {
|
||||
|
||||
global $tabs;
|
||||
|
||||
$s = "";
|
||||
|
||||
for ($t = 0; $t < $tabs; $t++)
|
||||
{
|
||||
$s = $s . "\t";
|
||||
}
|
||||
|
||||
return $s;
|
||||
|
||||
}
|
||||
|
||||
$pixi = Array();
|
||||
|
||||
$raw = 'Paste ShaderToy code in here';
|
||||
|
||||
$output = "this.fragmentSrc = [\n";
|
||||
$output .= "\t\"precision mediump float;\",\n";
|
||||
$output .= "\t\"uniform vec3 iResolution;\",\n";
|
||||
$output .= "\t\"uniform float iGlobalTime;\",\n";
|
||||
$output .= "\t\"uniform float iChannelTime[4];\",\n";
|
||||
$output .= "\t\"uniform vec4 iMouse;\",\n";
|
||||
$output .= "\t\"uniform vec4 iDate;\",\n";
|
||||
$output .= "\t\"uniform vec3 iChannelResolution[4];\",\n";
|
||||
$output .= "\t\"uniform sampler2D iChannel0;\",\n";
|
||||
$output .= "\t\"// add any extra uniforms here\",\n";
|
||||
$output .= "\n";
|
||||
|
||||
$tabs = 1;
|
||||
|
||||
if (isset($_POST['shader']))
|
||||
{
|
||||
$shader = explode("\n", $_POST['shader']);
|
||||
$raw = urldecode($_POST['shader']);
|
||||
|
||||
for ($i = 0; $i < count($shader); $i++)
|
||||
{
|
||||
$output = $output . "\t\"" . trim($shader[$i]) . "\",\n";
|
||||
$pixi[] = trim($shader[$i]);
|
||||
}
|
||||
|
||||
// Tabbing
|
||||
for ($i = 0; $i < count($pixi); $i++)
|
||||
{
|
||||
if ($pixi[$i] == '{')
|
||||
{
|
||||
$output = $output . getTabs() . '"' . $pixi[$i] . "\",\n";
|
||||
$tabs++;
|
||||
continue;
|
||||
}
|
||||
else if ($pixi[$i] == '}')
|
||||
{
|
||||
$tabs--;
|
||||
}
|
||||
|
||||
if ($pixi[$i] == '')
|
||||
{
|
||||
$output = $output . "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$output = $output . getTabs() . '"' . $pixi[$i] . "\",\n";
|
||||
}
|
||||
}
|
||||
|
||||
$output = rtrim($output);
|
||||
|
||||
if (substr($output, -1) == ',')
|
||||
{
|
||||
$output = substr($output, 0, -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,7 +80,7 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>phaser - filter conv</title>
|
||||
<title>phaser - ShaderToy Convertor</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial;
|
||||
|
@ -27,10 +90,12 @@
|
|||
</head>
|
||||
<body>
|
||||
|
||||
<h1>ShaderToy to PIXI Convertor</h1>
|
||||
|
||||
<form action="filterconv.php" method="post">
|
||||
|
||||
<h2>Input</h2>
|
||||
<textarea name="shader" style="width: 800px; height: 400px"></textarea>
|
||||
<textarea name="shader" style="width: 800px; height: 200px"><?php echo $raw ?></textarea>
|
||||
|
||||
<h2>Output</h2>
|
||||
<textarea style="width: 800px; height: 400px"><?php echo $output ?></textarea>
|
||||
|
|
146
examples/wip/flameFilter.js
Normal file
|
@ -0,0 +1,146 @@
|
|||
PIXI.FlameFilter = function(width, height)
|
||||
{
|
||||
PIXI.AbstractFilter.call( this );
|
||||
|
||||
this.passes = [this];
|
||||
|
||||
var d = new Date();
|
||||
|
||||
var dates = [
|
||||
d.getFullYear(), // the year (four digits)
|
||||
d.getMonth(), // the month (from 0-11)
|
||||
d.getDate(), // the day of the month (from 1-31)
|
||||
d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds()
|
||||
];
|
||||
|
||||
this.uniforms = {
|
||||
iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }},
|
||||
iGlobalTime: { type: 'f', value: 1 },
|
||||
iDate: { type: 'f4', value: dates }
|
||||
};
|
||||
|
||||
// This shader by XT95 (https://www.shadertoy.com/view/MdX3zr)
|
||||
this.fragmentSrc = [
|
||||
|
||||
"precision mediump float;",
|
||||
"uniform vec3 iResolution;",
|
||||
"uniform float iGlobalTime;",
|
||||
"uniform float iChannelTime[4];",
|
||||
"uniform vec4 iMouse;",
|
||||
"uniform vec4 iDate;",
|
||||
"uniform vec3 iChannelResolution[4];",
|
||||
"// add any extra uniforms here",
|
||||
|
||||
"float noise(vec3 p) //Thx to Las^Mercury",
|
||||
"{",
|
||||
"vec3 i = floor(p);",
|
||||
"vec4 a = dot(i, vec3(1., 57., 21.)) + vec4(0., 57., 21., 78.);",
|
||||
"vec3 f = cos((p-i)*acos(-1.))*(-.5)+.5;",
|
||||
"a = mix(sin(cos(a)*a),sin(cos(1.+a)*(1.+a)), f.x);",
|
||||
"a.xy = mix(a.xz, a.yw, f.y);",
|
||||
"return mix(a.x, a.y, f.z);",
|
||||
"}",
|
||||
|
||||
"//-----------------------------------------------------------------------------",
|
||||
"// Scene/Objects",
|
||||
"//-----------------------------------------------------------------------------",
|
||||
"float sphere(vec3 p, vec4 spr)",
|
||||
"{",
|
||||
"return length(spr.xyz-p) - spr.w;",
|
||||
"}",
|
||||
|
||||
"float fire(vec3 p)",
|
||||
"{",
|
||||
"float d= sphere(p*vec3(1.,.5,1.), vec4(.0,-1.,.0,1.));",
|
||||
"return d+(noise(p+vec3(.0,iGlobalTime*2.,.0))+noise(p*3.)*.5)*.25*(p.y) ;",
|
||||
"}",
|
||||
"//-----------------------------------------------------------------------------",
|
||||
"// Raymarching tools",
|
||||
"//-----------------------------------------------------------------------------",
|
||||
"float scene(vec3 p)",
|
||||
"{",
|
||||
"return min(100.-length(p) , abs(fire(p)) );",
|
||||
"}",
|
||||
|
||||
"vec4 Raymarche(vec3 org, vec3 dir)",
|
||||
"{",
|
||||
"float d=0.0;",
|
||||
"vec3 p=org;",
|
||||
"float glow = 0.0;",
|
||||
"float eps = 0.02;",
|
||||
"bool glowed=false;",
|
||||
"for(int i=0; i<64; i++)",
|
||||
"{",
|
||||
"d = scene(p) + eps;",
|
||||
"p += d * dir;",
|
||||
"if( d>eps )",
|
||||
"{",
|
||||
"if( fire(p) < .0)",
|
||||
"glowed=true;",
|
||||
"if(glowed)",
|
||||
"glow = float(i)/64.;",
|
||||
"}",
|
||||
"}",
|
||||
"return vec4(p,glow);",
|
||||
"}",
|
||||
|
||||
"//-----------------------------------------------------------------------------",
|
||||
"// Main functions",
|
||||
"//-----------------------------------------------------------------------------",
|
||||
|
||||
"void main()",
|
||||
"{",
|
||||
"vec2 v = -1.0 + 2.0 * gl_FragCoord.xy / iResolution.xy;",
|
||||
"v.x *= iResolution.x/iResolution.y;",
|
||||
"vec3 org = vec3(0.,-2.,4.);",
|
||||
"vec3 dir = normalize(vec3(v.x*1.6,-v.y,-1.5));",
|
||||
"vec4 p = Raymarche(org,dir);",
|
||||
"float glow = p.w;",
|
||||
"gl_FragColor = mix(vec4(0.), mix(vec4(1.,.5,.1,1.),vec4(0.1,.5,1.,1.),p.y*.02+.4), pow(glow*2.,4.));",
|
||||
"//gl_FragColor = mix(vec4(1.), mix(vec4(1.,.5,.1,1.),vec4(0.1,.5,1.,1.),p.y*.02+.4), pow(glow*2.,4.));",
|
||||
|
||||
"}"
|
||||
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
PIXI.FlameFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
|
||||
PIXI.FlameFilter.prototype.constructor = PIXI.FlameFilter;
|
||||
|
||||
Object.defineProperty(PIXI.FlameFilter.prototype, 'iGlobalTime', {
|
||||
get: function() {
|
||||
return this.uniforms.iGlobalTime.value;
|
||||
},
|
||||
set: function(value) {
|
||||
this.uniforms.iGlobalTime.value = value;
|
||||
}
|
||||
});
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('texture', 'wip/64x64.png');
|
||||
|
||||
}
|
||||
|
||||
var stars;
|
||||
var flame;
|
||||
|
||||
function create() {
|
||||
|
||||
flame = game.add.sprite(0, 0, 'texture');
|
||||
flame.scale.setTo(10, 10);
|
||||
|
||||
stars = new PIXI.FlameFilter(flame.width, flame.height);
|
||||
|
||||
flame.filters = [stars];
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
stars.iGlobalTime = game.time.totalElapsedSeconds();
|
||||
|
||||
}
|
110
examples/wip/hypnoticRipplesFilter.js
Normal file
|
@ -0,0 +1,110 @@
|
|||
PIXI.HypnoticRipplesFilter = function(width, height, texture)
|
||||
{
|
||||
PIXI.AbstractFilter.call( this );
|
||||
|
||||
this.passes = [this];
|
||||
|
||||
var d = new Date();
|
||||
|
||||
var dates = [
|
||||
d.getFullYear(), // the year (four digits)
|
||||
d.getMonth(), // the month (from 0-11)
|
||||
d.getDate(), // the day of the month (from 1-31)
|
||||
d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds()
|
||||
];
|
||||
|
||||
this.uniforms = {
|
||||
iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }},
|
||||
iGlobalTime: { type: 'f', value: 1 },
|
||||
iDate: { type: 'f4', value: dates },
|
||||
iChannel0: { type: 'sampler2D', value: texture }
|
||||
};
|
||||
|
||||
// Shader by Cha (https://www.shadertoy.com/view/ldX3zr)
|
||||
this.fragmentSrc = [
|
||||
"precision mediump float;",
|
||||
"uniform vec3 iResolution;",
|
||||
"uniform float iGlobalTime;",
|
||||
"uniform float iChannelTime[4];",
|
||||
"uniform vec4 iMouse;",
|
||||
"uniform vec4 iDate;",
|
||||
"uniform vec3 iChannelResolution[4];",
|
||||
"uniform sampler2D iChannel0;",
|
||||
"// add any extra uniforms here",
|
||||
|
||||
|
||||
"vec2 center = vec2(0.5,0.5);",
|
||||
"float speed = 0.035;",
|
||||
"float invAr = iResolution.y / iResolution.x;",
|
||||
|
||||
"void main(void)",
|
||||
"{",
|
||||
"vec2 uv = gl_FragCoord.xy / iResolution.xy;",
|
||||
|
||||
"vec3 col = vec4(uv,0.5+0.5*sin(iGlobalTime),1.0).xyz;",
|
||||
|
||||
"vec3 texcol;",
|
||||
|
||||
"float x = (center.x-uv.x);",
|
||||
"float y = (center.y-uv.y) *invAr;",
|
||||
|
||||
"//float r = -sqrt(x*x + y*y); //uncoment this line to symmetric ripples",
|
||||
"float r = -(x*x + y*y);",
|
||||
"float z = 1.0 + 0.5*sin((r+iGlobalTime*speed)/0.013);",
|
||||
|
||||
"texcol.x = z;",
|
||||
"texcol.y = z;",
|
||||
"texcol.z = z;",
|
||||
|
||||
"gl_FragColor = vec4(col*texcol,1.0);",
|
||||
"//gl_FragColor = vec4(texcol,1.0);",
|
||||
"}"];
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
PIXI.HypnoticRipplesFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
|
||||
PIXI.HypnoticRipplesFilter.prototype.constructor = PIXI.HypnoticRipplesFilter;
|
||||
|
||||
Object.defineProperty(PIXI.HypnoticRipplesFilter.prototype, 'iGlobalTime', {
|
||||
get: function() {
|
||||
return this.uniforms.iGlobalTime.value;
|
||||
},
|
||||
set: function(value) {
|
||||
this.uniforms.iGlobalTime.value = value;
|
||||
}
|
||||
});
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
// game.load.image('texture', 'wip/64x64.png');
|
||||
game.load.image('texture', 'wip/tex16.png');
|
||||
|
||||
}
|
||||
|
||||
var filter;
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
sprite = game.add.sprite(0, 0, 'texture');
|
||||
sprite.width = 800;
|
||||
sprite.height = 600;
|
||||
|
||||
filter = new PIXI.HypnoticRipplesFilter(sprite.width, sprite.height, sprite.texture);
|
||||
|
||||
sprite.filters = [filter];
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
filter.iGlobalTime = game.time.totalElapsedSeconds();
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
}
|
220
examples/wip/icosohedronFilter.js
Normal file
|
@ -0,0 +1,220 @@
|
|||
PIXI.IcosohedronFilter = function(width, height, texture)
|
||||
{
|
||||
PIXI.AbstractFilter.call( this );
|
||||
|
||||
this.passes = [this];
|
||||
|
||||
var d = new Date();
|
||||
|
||||
var dates = [
|
||||
d.getFullYear(), // the year (four digits)
|
||||
d.getMonth(), // the month (from 0-11)
|
||||
d.getDate(), // the day of the month (from 1-31)
|
||||
d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds()
|
||||
];
|
||||
|
||||
this.uniforms = {
|
||||
iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }},
|
||||
iGlobalTime: { type: 'f', value: 1 },
|
||||
iDate: { type: 'f4', value: dates },
|
||||
iChannel0: { type: 'sampler2D', value: texture }
|
||||
};
|
||||
|
||||
// Shader by WouterVanNifterick (https://www.shadertoy.com/view/ldS3Rh)
|
||||
this.fragmentSrc = [
|
||||
"precision mediump float;",
|
||||
"uniform vec3 iResolution;",
|
||||
"uniform float iGlobalTime;",
|
||||
"uniform float iChannelTime[4];",
|
||||
"uniform vec4 iMouse;",
|
||||
"uniform vec4 iDate;",
|
||||
"uniform vec3 iChannelResolution[4];",
|
||||
"uniform sampler2D iChannel0;",
|
||||
"// add any extra uniforms here",
|
||||
|
||||
"// Tracer code by Ben Weston - 2013",
|
||||
"// Geometry, colouring and and animation by Wouter van Nifterick 2013",
|
||||
"// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.",
|
||||
|
||||
"const float pi2 = 6.28318530717958647692;",
|
||||
|
||||
"const float epsilon = .003;",
|
||||
"const float normalPrecision = .1;",
|
||||
"const float shadowOffset = .2;",
|
||||
"const int traceDepth = 50; // takes time",
|
||||
"const float drawDistance = 150.0;",
|
||||
"const float stepScale = .9;",
|
||||
|
||||
"const vec3 CamPos = vec3(0,20.0,-20.0);",
|
||||
"const vec3 CamLook = vec3(0,0,0);",
|
||||
|
||||
"const vec3 lightDir = vec3(0,1,1);",
|
||||
"const vec3 fillLightDir = vec3(0,0,-1);",
|
||||
"const vec3 lightColour = vec3(1,.8,.6);",
|
||||
"const vec3 fillLightColour = vec3(.05,.15,.25);",
|
||||
|
||||
|
||||
"float Isosurface( vec3 at )",
|
||||
"{",
|
||||
"float res=.6;",
|
||||
"float n=(1.0+sqrt(5.0))*0.49;",
|
||||
|
||||
"at /= 2.5;",
|
||||
"if(length(at) < 5.9)",
|
||||
"{",
|
||||
"float t =",
|
||||
"res =2.0 -",
|
||||
"(cos(at.x + n * at.y) +",
|
||||
"cos(at.x - n * at.y) +",
|
||||
"cos(at.y + n * at.z) +",
|
||||
"cos(at.y - n * at.z) +",
|
||||
"cos(at.z + n * at.x) +",
|
||||
"cos(at.z - n * at.x)) ;",
|
||||
"}",
|
||||
"return res;",
|
||||
"}",
|
||||
|
||||
"vec3 Shading( vec3 pos, vec3 norm, float shadow, vec3 rd )",
|
||||
"{",
|
||||
"vec3 albedo = vec3(.4);",
|
||||
|
||||
"vec3 l = shadow*lightColour*max(0.0,dot(norm,lightDir));",
|
||||
"vec3 fl = fillLightColour*(dot(norm,fillLightDir)*.5+.5);",
|
||||
|
||||
"vec3 view = normalize(-rd);",
|
||||
"vec3 h = normalize(view+lightDir);",
|
||||
"float specular = pow(max(0.0,dot(h,norm)),200.0);",
|
||||
"vec3 res = albedo*(l+fl) + shadow*specular*22.0*lightColour*0.1;",
|
||||
"return res;",
|
||||
"}",
|
||||
|
||||
|
||||
"float Trace( vec3 ro, vec3 rd )",
|
||||
"{",
|
||||
"float t = 0.0;",
|
||||
"float dist = 1.0;",
|
||||
"for ( int i=0; i < traceDepth; i++ )",
|
||||
"{",
|
||||
"if ( abs(dist) < epsilon || t > drawDistance || t < 0.0 )",
|
||||
"continue;",
|
||||
"dist = Isosurface( ro+rd*t );",
|
||||
"t = t+dist*stepScale;",
|
||||
"}",
|
||||
|
||||
"return t;",
|
||||
"}",
|
||||
|
||||
"// get normal",
|
||||
"vec3 GetNormal( vec3 pos )",
|
||||
"{",
|
||||
"const vec2 delta = vec2(normalPrecision, 0);",
|
||||
"vec3 n;",
|
||||
"n.x = Isosurface( pos + delta.xyy ) - Isosurface( pos - delta.xyy );",
|
||||
"n.y = Isosurface( pos + delta.yxy ) - Isosurface( pos - delta.yxy );",
|
||||
"n.z = Isosurface( pos + delta.yyx ) - Isosurface( pos - delta.yyx );",
|
||||
"return normalize(n);",
|
||||
"}",
|
||||
|
||||
"// camera function by TekF",
|
||||
"// compute ray from camera parameters",
|
||||
"vec3 GetRay( vec3 dir, float zoom, vec2 uv )",
|
||||
"{",
|
||||
"uv = uv - .5;",
|
||||
"uv.x *= iResolution.x/iResolution.y;",
|
||||
|
||||
"dir = zoom*normalize(dir);",
|
||||
"vec3 right = normalize(cross(vec3(0,1,0),dir));",
|
||||
"vec3 up = normalize(cross(dir,right));",
|
||||
|
||||
"return dir + right*uv.x + up*uv.y;",
|
||||
"}",
|
||||
|
||||
"void main(void)",
|
||||
"{",
|
||||
"vec2 uv = gl_FragCoord.xy / iResolution.xy;",
|
||||
|
||||
"vec3 camPos = CamPos;",
|
||||
"vec3 camLook = CamLook;",
|
||||
|
||||
"vec2 camRot = .5*pi2*(iMouse.xy-iResolution.xy*.5)/iResolution.x;",
|
||||
"camRot += iGlobalTime*0.5;",
|
||||
"camRot.y = 0.0;",
|
||||
|
||||
"camPos.yz = cos(camRot.y)*camPos.yz* (0.5+sin (iGlobalTime)*0.2) + sin(camRot.y)*camPos.zy*vec2(1,-1);",
|
||||
"camPos.xz = cos(camRot.x)*camPos.xz + sin(camRot.x)*camPos.zx*vec2(1,-1);",
|
||||
|
||||
"vec3 rd, ro = camPos;",
|
||||
"rd = GetRay( camLook-camPos, 1.0, uv );",
|
||||
|
||||
"float t = Trace(ro,rd);",
|
||||
|
||||
"vec3 result = vec3(0);",
|
||||
"if ( t > 0.0 && t < drawDistance )",
|
||||
"{",
|
||||
"vec3 pos = ro+t*rd;",
|
||||
|
||||
"vec3 norm = GetNormal(pos);",
|
||||
|
||||
"// shadow test",
|
||||
"float shadow = 0.0;",
|
||||
"if ( Trace( pos+lightDir*shadowOffset, lightDir ) < drawDistance )",
|
||||
"shadow = 0.15;",
|
||||
|
||||
"result = Shading( pos, norm, shadow, rd )*6.0;",
|
||||
|
||||
"// fog",
|
||||
"result = mix ( vec3(.6+sin(1.0+iGlobalTime)*0.6,.9+cos(iGlobalTime)*0.2,1.1+sin(iGlobalTime)*0.1), result, exp(-t*t*.0005) )*2.0-0.5;",
|
||||
"result -= distance(vec2(0),pos.xy)*0.03;",
|
||||
"}",
|
||||
|
||||
"gl_FragColor = vec4( result, 1.0 );",
|
||||
"}"];
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
PIXI.IcosohedronFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
|
||||
PIXI.IcosohedronFilter.prototype.constructor = PIXI.IcosohedronFilter;
|
||||
|
||||
Object.defineProperty(PIXI.IcosohedronFilter.prototype, 'iGlobalTime', {
|
||||
get: function() {
|
||||
return this.uniforms.iGlobalTime.value;
|
||||
},
|
||||
set: function(value) {
|
||||
this.uniforms.iGlobalTime.value = value;
|
||||
}
|
||||
});
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
// game.load.image('texture', 'wip/64x64.png');
|
||||
game.load.image('texture', 'wip/tex16.png');
|
||||
|
||||
}
|
||||
|
||||
var filter;
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
sprite = game.add.sprite(0, 0, 'texture');
|
||||
sprite.width = 800;
|
||||
sprite.height = 600;
|
||||
|
||||
filter = new PIXI.IcosohedronFilter(sprite.width, sprite.height, sprite.texture);
|
||||
|
||||
sprite.filters = [filter];
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
filter.iGlobalTime = game.time.totalElapsedSeconds();
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
}
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
function dirToArray($dir) {
|
||||
|
||||
$ignore = array('.', '..', '_site', 'assets', 'states');
|
||||
$ignore = array('.', '..', '_site', 'assets', 'states', 'book');
|
||||
$result = array();
|
||||
$root = scandir($dir);
|
||||
$dirs = array_diff($root, $ignore);
|
||||
|
|
160
examples/wip/plasma3DFilter.js
Normal file
|
@ -0,0 +1,160 @@
|
|||
PIXI.Plasma3DFilter = function(width, height)
|
||||
{
|
||||
PIXI.AbstractFilter.call( this );
|
||||
|
||||
this.passes = [this];
|
||||
|
||||
var d = new Date();
|
||||
|
||||
var dates = [
|
||||
d.getFullYear(), // the year (four digits)
|
||||
d.getMonth(), // the month (from 0-11)
|
||||
d.getDate(), // the day of the month (from 1-31)
|
||||
d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds()
|
||||
];
|
||||
|
||||
this.uniforms = {
|
||||
iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }},
|
||||
iGlobalTime: { type: 'f', value: 1 },
|
||||
iDate: { type: 'f4', value: dates }
|
||||
};
|
||||
|
||||
// Shader by Optimus (https://www.shadertoy.com/view/Mss3zn)
|
||||
this.fragmentSrc = [
|
||||
"precision mediump float;",
|
||||
"uniform vec3 iResolution;",
|
||||
"uniform float iGlobalTime;",
|
||||
"uniform float iChannelTime[4];",
|
||||
"uniform vec4 iMouse;",
|
||||
"uniform vec4 iDate;",
|
||||
"uniform vec3 iChannelResolution[4];",
|
||||
"// add any extra uniforms here",
|
||||
|
||||
"// Dark Chocolate Cave Plasma by Optimus",
|
||||
|
||||
"#ifdef GL_ES",
|
||||
"precision mediump float;",
|
||||
"#endif",
|
||||
|
||||
"float time;",
|
||||
"vec2 mouse;",
|
||||
"vec2 resolution;",
|
||||
|
||||
"const int iters = 256;",
|
||||
|
||||
"const float origin_z = 0.0;",
|
||||
"const float plane_z = 4.0;",
|
||||
"const float far_z = 64.0;",
|
||||
|
||||
"const float step = (far_z - plane_z) / float(iters) * 0.025;",
|
||||
|
||||
"const float color_bound = 0.0;",
|
||||
"const float upper_bound = 1.0;",
|
||||
|
||||
"const float scale = 32.0;",
|
||||
|
||||
"const float disp = 0.25;",
|
||||
|
||||
"float calc_this(vec3 p, float disx, float disy, float disz)",
|
||||
"{",
|
||||
"float c = sin(sin((p.x + disx) * sin(sin(p.z + disz)) + time) + sin((p.y + disy) * cos(p.z + disz) + 2.0 * time) + sin(3.0*p.z + disz + 3.5 * time) + sin((p.x + disx) + sin(p.y + disy + 2.5 * (p.z + disz - time) + 1.75 * time) - 0.5 * time));",
|
||||
"return c;",
|
||||
"}",
|
||||
|
||||
"vec3 get_intersection()",
|
||||
"{",
|
||||
"vec2 position = (gl_FragCoord.xy / resolution.xy - 0.5) * scale;",
|
||||
|
||||
"vec3 pos = vec3(position.x, position.y, plane_z);",
|
||||
"vec3 origin = vec3(0.0, 0.0, origin_z);",
|
||||
|
||||
"vec3 dir = pos - origin;",
|
||||
"vec3 dirstep = normalize(dir) * step;",
|
||||
|
||||
"dir = normalize(dir) * plane_z;",
|
||||
|
||||
|
||||
"float c;",
|
||||
|
||||
"for (int i=0; i<iters; i++)",
|
||||
"{",
|
||||
"c = calc_this(dir, 0.0, 0.0, 0.0);",
|
||||
|
||||
"if (c > color_bound)",
|
||||
"{",
|
||||
"break;",
|
||||
"}",
|
||||
|
||||
"dir = dir + dirstep;",
|
||||
"}",
|
||||
|
||||
"return dir;",
|
||||
"}",
|
||||
|
||||
|
||||
"void main()",
|
||||
"{",
|
||||
"time = iGlobalTime;",
|
||||
"mouse = vec2(iMouse);",
|
||||
"resolution = vec2(iResolution);",
|
||||
|
||||
"vec3 p = get_intersection();",
|
||||
"float dx = color_bound - calc_this(p, disp, 0.0, 0.0);",
|
||||
"float dy = color_bound - calc_this(p, 0.0, disp, 0.0);",
|
||||
|
||||
"vec3 du = vec3(disp, 0.0, dx);",
|
||||
"vec3 dv = vec3(0.0, disp, dy);",
|
||||
"vec3 normal = normalize(cross(du, dv));",
|
||||
|
||||
"vec3 light = normalize(vec3(0.0, 0.0, 1.0));",
|
||||
"float l = dot(normal, light);",
|
||||
|
||||
"float cc = pow(l, 2.0);",
|
||||
"gl_FragColor = vec4(cc*0.8, cc*0.5, cc*0.8, cc);",
|
||||
"}"];
|
||||
|
||||
}
|
||||
|
||||
PIXI.Plasma3DFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
|
||||
PIXI.Plasma3DFilter.prototype.constructor = PIXI.Plasma3DFilter;
|
||||
|
||||
Object.defineProperty(PIXI.Plasma3DFilter.prototype, 'iGlobalTime', {
|
||||
get: function() {
|
||||
return this.uniforms.iGlobalTime.value;
|
||||
},
|
||||
set: function(value) {
|
||||
this.uniforms.iGlobalTime.value = value;
|
||||
}
|
||||
});
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('texture', 'wip/64x64.png');
|
||||
|
||||
}
|
||||
|
||||
var filter;
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
sprite = game.add.sprite(0, 0, 'texture');
|
||||
sprite.width = 800;
|
||||
sprite.height = 600;
|
||||
|
||||
filter = new PIXI.Plasma3DFilter(sprite.width, sprite.height);
|
||||
|
||||
sprite.filters = [filter];
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
filter.iGlobalTime = game.time.totalElapsedSeconds();
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
}
|
96
examples/wip/plasmaBeamFilter.js
Normal file
|
@ -0,0 +1,96 @@
|
|||
PIXI.PlasmaBeamFilter = function(width, height)
|
||||
{
|
||||
PIXI.AbstractFilter.call( this );
|
||||
|
||||
this.passes = [this];
|
||||
|
||||
var d = new Date();
|
||||
|
||||
var dates = [
|
||||
d.getFullYear(), // the year (four digits)
|
||||
d.getMonth(), // the month (from 0-11)
|
||||
d.getDate(), // the day of the month (from 1-31)
|
||||
d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds()
|
||||
];
|
||||
|
||||
this.uniforms = {
|
||||
iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }},
|
||||
iGlobalTime: { type: 'f', value: 1 },
|
||||
iDate: { type: 'f4', value: dates }
|
||||
};
|
||||
|
||||
// Shader by 4rknova (https://www.shadertoy.com/view/Xsl3WH)
|
||||
this.fragmentSrc = [
|
||||
"precision mediump float;",
|
||||
"uniform vec3 iResolution;",
|
||||
"uniform float iGlobalTime;",
|
||||
"uniform float iChannelTime[4];",
|
||||
"uniform vec4 iMouse;",
|
||||
"uniform vec4 iDate;",
|
||||
"uniform vec3 iChannelResolution[4];",
|
||||
"// add any extra uniforms here",
|
||||
|
||||
"#ifdef GL_ES",
|
||||
"precision highp float;",
|
||||
"#endif",
|
||||
|
||||
"#define AMPLITUDE 0.19",
|
||||
"#define WVELOCITY 1.0",
|
||||
"#define WAVEWIDTH 2.0",
|
||||
"#define THICKNESS 0.5",
|
||||
|
||||
"void main(void)",
|
||||
"{",
|
||||
"vec2 uv = gl_FragCoord.xy / iResolution.xy;",
|
||||
|
||||
"float h = sin((uv.x * WAVEWIDTH + iGlobalTime * WVELOCITY) * 2.5) * AMPLITUDE;",
|
||||
"float f = pow(THICKNESS * abs(0.1 / (uv.y * 2.0 - 1.0 + h)), 2.0);",
|
||||
|
||||
"gl_FragColor = vec4(0.0, 0.0, f, 1.0);",
|
||||
"}"];
|
||||
|
||||
}
|
||||
|
||||
PIXI.PlasmaBeamFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
|
||||
PIXI.PlasmaBeamFilter.prototype.constructor = PIXI.PlasmaBeamFilter;
|
||||
|
||||
Object.defineProperty(PIXI.PlasmaBeamFilter.prototype, 'iGlobalTime', {
|
||||
get: function() {
|
||||
return this.uniforms.iGlobalTime.value;
|
||||
},
|
||||
set: function(value) {
|
||||
this.uniforms.iGlobalTime.value = value;
|
||||
}
|
||||
});
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('texture', 'wip/64x64.png');
|
||||
|
||||
}
|
||||
|
||||
var filter;
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
sprite = game.add.sprite(0, 0, 'texture');
|
||||
sprite.width = 800;
|
||||
sprite.height = 600;
|
||||
|
||||
filter = new PIXI.PlasmaBeamFilter(sprite.width, sprite.height);
|
||||
|
||||
sprite.filters = [filter];
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
filter.iGlobalTime = game.time.totalElapsedSeconds();
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
}
|
100
examples/wip/plasmaFilter.js
Normal file
|
@ -0,0 +1,100 @@
|
|||
PIXI.PlasmaFilter = function(width, height)
|
||||
{
|
||||
PIXI.AbstractFilter.call( this );
|
||||
|
||||
this.passes = [this];
|
||||
|
||||
var d = new Date();
|
||||
|
||||
var dates = [
|
||||
d.getFullYear(), // the year (four digits)
|
||||
d.getMonth(), // the month (from 0-11)
|
||||
d.getDate(), // the day of the month (from 1-31)
|
||||
d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds()
|
||||
];
|
||||
|
||||
this.uniforms = {
|
||||
iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }},
|
||||
iGlobalTime: { type: 'f', value: 1 },
|
||||
iDate: { type: 'f4', value: dates }
|
||||
};
|
||||
|
||||
// Shader by TriggerHLM (https://www.shadertoy.com/view/MdXGDH)
|
||||
this.fragmentSrc = [
|
||||
"precision mediump float;",
|
||||
"uniform vec3 iResolution;",
|
||||
"uniform float iGlobalTime;",
|
||||
"uniform float iChannelTime[4];",
|
||||
"uniform vec4 iMouse;",
|
||||
"uniform vec4 iDate;",
|
||||
"uniform vec3 iChannelResolution[4];",
|
||||
"// add any extra uniforms here",
|
||||
|
||||
"const float PI = 3.14159265;",
|
||||
|
||||
"float time = iGlobalTime *0.2;",
|
||||
|
||||
"void main(void ) {",
|
||||
|
||||
"float color1, color2, color;",
|
||||
|
||||
"color1 = (sin(dot(gl_FragCoord.xy,vec2(sin(time*3.0),cos(time*3.0)))*0.02+time*3.0)+1.0)/2.0;",
|
||||
|
||||
"vec2 center = vec2(640.0/2.0, 360.0/2.0) + vec2(640.0/2.0*sin(-time*3.0),360.0/2.0*cos(-time*3.0));",
|
||||
|
||||
"color2 = (cos(length(gl_FragCoord.xy - center)*0.03)+1.0)/2.0;",
|
||||
|
||||
"color = (color1+ color2)/2.0;",
|
||||
|
||||
"float red = (cos(PI*color/0.5+time*3.0)+1.0)/2.0;",
|
||||
"float green = (sin(PI*color/0.5+time*3.0)+1.0)/2.0;",
|
||||
"float blue = (sin(+time*3.0)+1.0)/2.0;",
|
||||
|
||||
"gl_FragColor = vec4(red, green, blue, 1.0);",
|
||||
"}"
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
PIXI.PlasmaFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
|
||||
PIXI.PlasmaFilter.prototype.constructor = PIXI.PlasmaFilter;
|
||||
|
||||
Object.defineProperty(PIXI.PlasmaFilter.prototype, 'iGlobalTime', {
|
||||
get: function() {
|
||||
return this.uniforms.iGlobalTime.value;
|
||||
},
|
||||
set: function(value) {
|
||||
this.uniforms.iGlobalTime.value = value;
|
||||
}
|
||||
});
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('texture', 'wip/64x64.png');
|
||||
|
||||
}
|
||||
|
||||
var plasma;
|
||||
var container;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#000000';
|
||||
|
||||
container = game.add.sprite(0, 0, 'texture');
|
||||
container.width = 800;
|
||||
container.height = 600;
|
||||
|
||||
plasma = new PIXI.PlasmaFilter(container.width, container.height);
|
||||
|
||||
container.filters = [plasma];
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
plasma.iGlobalTime = game.time.totalElapsedSeconds();
|
||||
|
||||
}
|
112
examples/wip/plasmaFlowerFilter.js
Normal file
|
@ -0,0 +1,112 @@
|
|||
PIXI.PlasmaFlowerFilter = function(width, height)
|
||||
{
|
||||
PIXI.AbstractFilter.call( this );
|
||||
|
||||
this.passes = [this];
|
||||
|
||||
var d = new Date();
|
||||
|
||||
var dates = [
|
||||
d.getFullYear(), // the year (four digits)
|
||||
d.getMonth(), // the month (from 0-11)
|
||||
d.getDate(), // the day of the month (from 1-31)
|
||||
d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds()
|
||||
];
|
||||
|
||||
this.uniforms = {
|
||||
iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }},
|
||||
iGlobalTime: { type: 'f', value: 1 },
|
||||
iDate: { type: 'f4', value: dates }
|
||||
};
|
||||
|
||||
// Shader by epsilum (https://www.shadertoy.com/view/Xdf3zH)
|
||||
this.fragmentSrc = [
|
||||
"precision mediump float;",
|
||||
"uniform vec3 iResolution;",
|
||||
"uniform float iGlobalTime;",
|
||||
"uniform float iChannelTime[4];",
|
||||
"uniform vec4 iMouse;",
|
||||
"uniform vec4 iDate;",
|
||||
"uniform vec3 iChannelResolution[4];",
|
||||
"// add any extra uniforms here",
|
||||
|
||||
"float addFlower(float x, float y, float ax, float ay, float fx, float fy)",
|
||||
"{",
|
||||
"float xx=(x+sin(iGlobalTime*fx)*ax)*8.0;",
|
||||
"float yy=(y+cos(iGlobalTime*fy)*ay)*8.0;",
|
||||
"float angle = atan(yy,xx);",
|
||||
"float zz = 1.5*(cos(18.0*angle)*0.5+0.5) / (0.7 * 3.141592) + 1.2*(sin(15.0*angle)*0.5+0.5)/ (0.7 * 3.141592);",
|
||||
|
||||
"return zz;",
|
||||
"}",
|
||||
|
||||
"void main(void)",
|
||||
"{",
|
||||
"vec2 xy=(gl_FragCoord.xy/iResolution.x)*2.0-vec2(1.0,iResolution.y/iResolution.x);",
|
||||
|
||||
"float x=xy.x;",
|
||||
"float y=xy.y;",
|
||||
|
||||
"float p1 = addFlower(x, y, 0.8, 0.9, 0.95, 0.85);",
|
||||
"float p2 = addFlower(x, y, 0.7, 0.9, 0.42, 0.71);",
|
||||
"float p3 = addFlower(x, y, 0.5, 1.0, 0.23, 0.97);",
|
||||
"float p4 = addFlower(x, y, 0.8, 0.5, 0.81, 1.91);",
|
||||
|
||||
"float p=clamp((p1+p2+p3+p4)*0.25, 0.0, 1.0);",
|
||||
|
||||
"vec4 col;",
|
||||
"if (p < 0.5)",
|
||||
"col=vec4(mix(0.0,1.0,p*2.0), mix(0.0,0.63,p*2.0), 0.0, 1.0);",
|
||||
"else if (p >= 0.5 && p <= 0.75)",
|
||||
"col=vec4(mix(1.0, 1.0-0.32, (p-0.5)*4.0), mix(0.63, 0.0, (p-0.5)*4.0), mix(0.0,0.24,(p-0.5)*4.0), 1.0);",
|
||||
"else",
|
||||
"col=vec4(mix(0.68, 0.0, (p-0.75)*4.0), 0.0, mix(0.24, 0.0, (p-0.75)*4.0), 1.0);",
|
||||
|
||||
"gl_FragColor = col;",
|
||||
"}"];
|
||||
|
||||
}
|
||||
|
||||
PIXI.PlasmaFlowerFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
|
||||
PIXI.PlasmaFlowerFilter.prototype.constructor = PIXI.PlasmaFlowerFilter;
|
||||
|
||||
Object.defineProperty(PIXI.PlasmaFlowerFilter.prototype, 'iGlobalTime', {
|
||||
get: function() {
|
||||
return this.uniforms.iGlobalTime.value;
|
||||
},
|
||||
set: function(value) {
|
||||
this.uniforms.iGlobalTime.value = value;
|
||||
}
|
||||
});
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('texture', 'wip/64x64.png');
|
||||
|
||||
}
|
||||
|
||||
var filter;
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
sprite = game.add.sprite(0, 0, 'texture');
|
||||
sprite.width = 800;
|
||||
sprite.height = 600;
|
||||
|
||||
filter = new PIXI.PlasmaFlowerFilter(sprite.width, sprite.height);
|
||||
|
||||
sprite.filters = [filter];
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
filter.iGlobalTime = game.time.totalElapsedSeconds();
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
}
|
117
examples/wip/retroPlasmaFilter.js
Normal file
|
@ -0,0 +1,117 @@
|
|||
PIXI.RetroPlasmaFilter = function(width, height)
|
||||
{
|
||||
PIXI.AbstractFilter.call( this );
|
||||
|
||||
this.passes = [this];
|
||||
|
||||
var d = new Date();
|
||||
|
||||
var dates = [
|
||||
d.getFullYear(), // the year (four digits)
|
||||
d.getMonth(), // the month (from 0-11)
|
||||
d.getDate(), // the day of the month (from 1-31)
|
||||
d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds()
|
||||
];
|
||||
|
||||
this.uniforms = {
|
||||
iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }},
|
||||
iGlobalTime: { type: 'f', value: 1 },
|
||||
iDate: { type: 'f4', value: dates }
|
||||
};
|
||||
|
||||
// Oldskool plasm shader. (c) Victor Korsun, bitekas@gmail.com; 1996-2013.
|
||||
this.fragmentSrc = [
|
||||
"precision mediump float;",
|
||||
"uniform vec3 iResolution;",
|
||||
"uniform float iGlobalTime;",
|
||||
"uniform float iChannelTime[4];",
|
||||
"uniform vec4 iMouse;",
|
||||
"uniform vec4 iDate;",
|
||||
"uniform vec3 iChannelResolution[4];",
|
||||
"// add any extra uniforms here",
|
||||
|
||||
"// Oldskool plasm shader. (c) Victor Korsun, bitekas@gmail.com; 1996-2013.",
|
||||
"//",
|
||||
"// Attribution-ShareAlike CC License.",
|
||||
|
||||
"//----------------",
|
||||
"const int ps = 10; // use values > 1..10 for oldskool",
|
||||
"//----------------",
|
||||
|
||||
|
||||
"void main(void)",
|
||||
"{",
|
||||
"float x = gl_FragCoord.x / iResolution.x * 640.;",
|
||||
"float y = gl_FragCoord.y / iResolution.y * 480.;",
|
||||
|
||||
"if (ps > 0)",
|
||||
"{",
|
||||
"x = float(int(x / float(ps)) * ps);",
|
||||
"y = float(int(y / float(ps)) * ps);",
|
||||
"}",
|
||||
|
||||
"float mov0 = x+y+sin(iGlobalTime)*10.+sin(x/90.)*70.+iGlobalTime*2.;",
|
||||
"float mov1 = (mov0 / 5. + sin(mov0 / 30.))/ 10. + iGlobalTime * 3.;",
|
||||
"float mov2 = mov1 + sin(mov1)*5. + iGlobalTime*1.0;",
|
||||
"float cl1 = sin(sin(mov1/4. + iGlobalTime)+mov1);",
|
||||
"float c1 = cl1 +mov2/2.-mov1-mov2+iGlobalTime;",
|
||||
"float c2 = sin(c1+sin(mov0/100.+iGlobalTime)+sin(y/57.+iGlobalTime/50.)+sin((x+y)/200.)*2.);",
|
||||
"float c3 = abs(sin(c2+cos((mov1+mov2+c2) / 10.)+cos((mov2) / 10.)+sin(x/80.)));",
|
||||
|
||||
"float dc = float(16-ps);",
|
||||
|
||||
"if (ps > 0)",
|
||||
"{",
|
||||
"cl1 = float(int(cl1*dc))/dc;",
|
||||
"c2 = float(int(c2*dc))/dc;",
|
||||
"c3 = float(int(c3*dc))/dc;",
|
||||
"}",
|
||||
|
||||
"gl_FragColor = vec4( cl1,c2,c3,1.0);",
|
||||
"}"];
|
||||
|
||||
}
|
||||
|
||||
PIXI.RetroPlasmaFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
|
||||
PIXI.RetroPlasmaFilter.prototype.constructor = PIXI.RetroPlasmaFilter;
|
||||
|
||||
Object.defineProperty(PIXI.RetroPlasmaFilter.prototype, 'iGlobalTime', {
|
||||
get: function() {
|
||||
return this.uniforms.iGlobalTime.value;
|
||||
},
|
||||
set: function(value) {
|
||||
this.uniforms.iGlobalTime.value = value;
|
||||
}
|
||||
});
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('texture', 'wip/64x64.png');
|
||||
|
||||
}
|
||||
|
||||
var filter;
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
sprite = game.add.sprite(0, 0, 'texture');
|
||||
sprite.width = 800;
|
||||
sprite.height = 600;
|
||||
|
||||
filter = new PIXI.RetroPlasmaFilter(sprite.width, sprite.height);
|
||||
|
||||
sprite.filters = [filter];
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
filter.iGlobalTime = game.time.totalElapsedSeconds();
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
}
|
145
examples/wip/starNestFilter.js
Normal file
|
@ -0,0 +1,145 @@
|
|||
PIXI.StarNestFilter = function(width, height, texture)
|
||||
{
|
||||
PIXI.AbstractFilter.call( this );
|
||||
|
||||
this.passes = [this];
|
||||
|
||||
var d = new Date();
|
||||
|
||||
var dates = [
|
||||
d.getFullYear(), // the year (four digits)
|
||||
d.getMonth(), // the month (from 0-11)
|
||||
d.getDate(), // the day of the month (from 1-31)
|
||||
d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds()
|
||||
];
|
||||
|
||||
this.uniforms = {
|
||||
iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }},
|
||||
iGlobalTime: { type: 'f', value: 1 },
|
||||
iDate: { type: 'f4', value: dates },
|
||||
iChannel0: { type: 'sampler2D', value: texture }
|
||||
};
|
||||
|
||||
// Shader by Kali (https://www.shadertoy.com/view/4dfGDM)
|
||||
this.fragmentSrc = [
|
||||
"precision mediump float;",
|
||||
"uniform vec3 iResolution;",
|
||||
"uniform float iGlobalTime;",
|
||||
"uniform float iChannelTime[4];",
|
||||
"uniform vec4 iMouse;",
|
||||
"uniform vec4 iDate;",
|
||||
"uniform vec3 iChannelResolution[4];",
|
||||
"// add any extra uniforms here",
|
||||
|
||||
"// Star Nest by Pablo Román Andrioli",
|
||||
|
||||
"// This content is under the MIT License.",
|
||||
|
||||
"#define iterations 17",
|
||||
"#define formuparam 0.530",
|
||||
|
||||
"#define volsteps 18",
|
||||
"#define stepsize 0.100",
|
||||
|
||||
"#define zoom 0.800",
|
||||
"#define tile 0.850",
|
||||
"#define speed 0.010",
|
||||
|
||||
"#define brightness 0.0015",
|
||||
"#define darkmatter 0.300",
|
||||
"#define distfading 0.760",
|
||||
"#define saturation 0.800",
|
||||
|
||||
|
||||
"void main(void)",
|
||||
"{",
|
||||
"//get coords and direction",
|
||||
"vec2 uv=gl_FragCoord.xy/iResolution.xy-.5;",
|
||||
"uv.y*=iResolution.y/iResolution.x;",
|
||||
"vec3 dir=vec3(uv*zoom,1.);",
|
||||
"float time=iGlobalTime*speed+.25;",
|
||||
|
||||
"//mouse rotation",
|
||||
"float a1=.5+iMouse.x/iResolution.x*2.;",
|
||||
"float a2=.8+iMouse.y/iResolution.y*2.;",
|
||||
"mat2 rot1=mat2(cos(a1),sin(a1),-sin(a1),cos(a1));",
|
||||
"mat2 rot2=mat2(cos(a2),sin(a2),-sin(a2),cos(a2));",
|
||||
"dir.xz*=rot1;",
|
||||
"dir.xy*=rot2;",
|
||||
"vec3 from=vec3(1.,.5,0.5);",
|
||||
"from+=vec3(time*2.,time,-2.);",
|
||||
"from.xz*=rot1;",
|
||||
"from.xy*=rot2;",
|
||||
|
||||
"//volumetric rendering",
|
||||
"float s=0.1,fade=1.;",
|
||||
"vec3 v=vec3(0.);",
|
||||
"for (int r=0; r<volsteps; r++) {",
|
||||
"vec3 p=from+s*dir*.5;",
|
||||
"p = abs(vec3(tile)-mod(p,vec3(tile*2.))); // tiling fold",
|
||||
"float pa,a=pa=0.;",
|
||||
"for (int i=0; i<iterations; i++) {",
|
||||
"p=abs(p)/dot(p,p)-formuparam; // the magic formula",
|
||||
"a+=abs(length(p)-pa); // absolute sum of average change",
|
||||
"pa=length(p);",
|
||||
"}",
|
||||
"float dm=max(0.,darkmatter-a*a*.001); //dark matter",
|
||||
"a*=a*a; // add contrast",
|
||||
"if (r>3) fade*=1.-dm; // dark matter, don't render near",
|
||||
"//v+=vec3(dm,dm*.5,0.);",
|
||||
"v+=fade;",
|
||||
"v+=vec3(s,s*s,s*s*s*s)*a*brightness*fade; // coloring based on distance",
|
||||
"fade*=distfading; // distance fading",
|
||||
"s+=stepsize;",
|
||||
"}",
|
||||
"v=mix(vec3(length(v)),v,saturation); //color adjust",
|
||||
"gl_FragColor = vec4(v*.01,1.);",
|
||||
|
||||
"}"];
|
||||
|
||||
}
|
||||
|
||||
PIXI.StarNestFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
|
||||
PIXI.StarNestFilter.prototype.constructor = PIXI.StarNestFilter;
|
||||
|
||||
Object.defineProperty(PIXI.StarNestFilter.prototype, 'iGlobalTime', {
|
||||
get: function() {
|
||||
return this.uniforms.iGlobalTime.value;
|
||||
},
|
||||
set: function(value) {
|
||||
this.uniforms.iGlobalTime.value = value;
|
||||
}
|
||||
});
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
// game.load.image('texture', 'wip/64x64.png');
|
||||
game.load.image('texture', 'wip/tex16.png');
|
||||
|
||||
}
|
||||
|
||||
var filter;
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
sprite = game.add.sprite(0, 0, 'texture');
|
||||
sprite.width = 800;
|
||||
sprite.height = 600;
|
||||
|
||||
filter = new PIXI.StarNestFilter(sprite.width, sprite.height, sprite.texture);
|
||||
|
||||
sprite.filters = [filter];
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
filter.iGlobalTime = game.time.totalElapsedSeconds();
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
}
|
235
examples/wip/starNurseryFilter.js
Normal file
|
@ -0,0 +1,235 @@
|
|||
PIXI.StarNurseryFilter = function(width, height, texture)
|
||||
{
|
||||
PIXI.AbstractFilter.call( this );
|
||||
|
||||
this.passes = [this];
|
||||
|
||||
var d = new Date();
|
||||
|
||||
var dates = [
|
||||
d.getFullYear(), // the year (four digits)
|
||||
d.getMonth(), // the month (from 0-11)
|
||||
d.getDate(), // the day of the month (from 1-31)
|
||||
d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds()
|
||||
];
|
||||
|
||||
this.uniforms = {
|
||||
iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }},
|
||||
iGlobalTime: { type: 'f', value: 1 },
|
||||
iDate: { type: 'f4', value: dates },
|
||||
iChannel0: { type: 'sampler2D', value: texture }
|
||||
};
|
||||
|
||||
// Shader by Dave Hoskins (https://www.shadertoy.com/view/XsfGzH)
|
||||
this.fragmentSrc = [
|
||||
"precision mediump float;",
|
||||
"uniform vec3 iResolution;",
|
||||
"uniform float iGlobalTime;",
|
||||
"uniform float iChannelTime[4];",
|
||||
"uniform vec4 iMouse;",
|
||||
"uniform vec4 iDate;",
|
||||
"uniform vec3 iChannelResolution[4];",
|
||||
"uniform sampler2D iChannel0;",
|
||||
"// add any extra uniforms here",
|
||||
|
||||
"// Built from the basics of'Clouds' Created by inigo quilez - iq/2013",
|
||||
"// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.",
|
||||
|
||||
"// Edited by Dave Hoskins into Star Nursery",
|
||||
"// V.1.1 Some speed up in the ray-marching loop.",
|
||||
"// V.1.2 Added Shadertoy's fast 3D noise for better, smaller step size.",
|
||||
|
||||
"mat3 m = mat3( 0.00, 0.90, 0.60,",
|
||||
"-0.90, 0.36, -0.48,",
|
||||
"-0.60, -0.48, 0.34 );",
|
||||
"float time = iGlobalTime+46.0;",
|
||||
|
||||
"//----------------------------------------------------------------------",
|
||||
"float hash( float n )",
|
||||
"{",
|
||||
"return fract(sin(n)*43758.5453123);",
|
||||
"}",
|
||||
|
||||
"//----------------------------------------------------------------------",
|
||||
"float noise( in vec2 x )",
|
||||
"{",
|
||||
"vec2 p = floor(x);",
|
||||
"vec2 f = fract(x);",
|
||||
|
||||
"f = f*f*(3.0-2.0*f);",
|
||||
|
||||
"float n = p.x + p.y*57.0;",
|
||||
|
||||
"float res = mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x),",
|
||||
"mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y);",
|
||||
|
||||
"return res;",
|
||||
"}",
|
||||
|
||||
"//----------------------------------------------------------------------",
|
||||
"float noise( in vec3 x )",
|
||||
"{",
|
||||
"vec3 p = floor(x);",
|
||||
"vec3 f = fract(x);",
|
||||
"f = f*f*(3.0-2.0*f);",
|
||||
|
||||
"vec2 uv = (p.xy+vec2(37.0,17.0)*p.z) + f.xy;",
|
||||
"vec2 rg = texture2D( iChannel0, (uv+ 0.5)/256.0, -100.0 ).yx;",
|
||||
"return mix( rg.x, rg.y, f.z );",
|
||||
"}",
|
||||
|
||||
"//----------------------------------------------------------------------",
|
||||
"float fbm( vec3 p )",
|
||||
"{",
|
||||
"float f;",
|
||||
"f = 1.600*noise( p ); p = m*p*2.02;",
|
||||
"f += 0.3500*noise( p ); p = m*p*2.33;",
|
||||
"f += 0.2250*noise( p ); p = m*p*2.01;",
|
||||
"f += 0.0825*noise( p ); p = m*p*2.01;",
|
||||
"return f;",
|
||||
"}",
|
||||
|
||||
"//----------------------------------------------------------------------",
|
||||
"vec4 map( in vec3 p )",
|
||||
"{",
|
||||
"float d = 0.01- p.y;",
|
||||
|
||||
"float f= fbm( p*1.0 - vec3(.4,0.3,-0.3)*time);",
|
||||
"d += 4.0 * f;",
|
||||
|
||||
"d = clamp( d, 0.0, 1.0 );",
|
||||
|
||||
"vec4 res = vec4( d );",
|
||||
"res.w = pow(res.y, .1);",
|
||||
|
||||
"res.xyz = mix( .7*vec3(1.0,0.4,0.2), vec3(0.2,0.0,0.2), res.y * 1.);",
|
||||
"res.xyz = res.xyz + pow(abs(.95-f), 26.0) * 1.85;",
|
||||
"return res;",
|
||||
"}",
|
||||
|
||||
|
||||
"//----------------------------------------------------------------------",
|
||||
"vec3 sundir = vec3(1.0,0.4,0.0);",
|
||||
"vec4 raymarch( in vec3 ro, in vec3 rd )",
|
||||
"{",
|
||||
"vec4 sum = vec4(0, 0, 0, 0);",
|
||||
|
||||
"float t = 0.0;",
|
||||
"vec3 pos = vec3(0.0, 0.0, 0.0);",
|
||||
"for(int i=0; i<100; i++)",
|
||||
"{",
|
||||
"if (sum.a > 0.8 || pos.y > 9.0 || pos.y < -2.0) continue;",
|
||||
"pos = ro + t*rd;",
|
||||
|
||||
"vec4 col = map( pos );",
|
||||
|
||||
"// Accumulate the alpha with the colour...",
|
||||
"col.a *= 0.08;",
|
||||
"col.rgb *= col.a;",
|
||||
|
||||
"sum = sum + col*(1.0 - sum.a);",
|
||||
"t += max(0.1,0.04*t);",
|
||||
"}",
|
||||
"sum.xyz /= (0.003+sum.w);",
|
||||
|
||||
"return clamp( sum, 0.0, 1.0 );",
|
||||
"}",
|
||||
|
||||
"//----------------------------------------------------------------------",
|
||||
"void main(void)",
|
||||
"{",
|
||||
"vec2 q = gl_FragCoord.xy / iResolution.xy;",
|
||||
"vec2 p = -1.0 + 2.0*q;",
|
||||
"p.x *= iResolution.x/ iResolution.y;",
|
||||
"vec2 mo = (-1.0 + 2.0 + iMouse.xy) / iResolution.xy;",
|
||||
|
||||
"// Camera code...",
|
||||
"vec3 ro = 5.6*normalize(vec3(cos(2.75-3.0*mo.x), .4-1.3*(mo.y-2.4), sin(2.75-2.0*mo.x)));",
|
||||
"vec3 ta = vec3(.0, 5.6, 2.4);",
|
||||
"vec3 ww = normalize( ta - ro);",
|
||||
"vec3 uu = normalize(cross( vec3(0.0,1.0,0.0), ww ));",
|
||||
"vec3 vv = normalize(cross(ww,uu));",
|
||||
"vec3 rd = normalize( p.x*uu + p.y*vv + 1.5*ww );",
|
||||
|
||||
"// Ray march into the clouds adding up colour...",
|
||||
"vec4 res = raymarch( ro, rd );",
|
||||
|
||||
|
||||
"float sun = clamp( dot(sundir,rd), 0.0, 2.0 );",
|
||||
"vec3 col = mix(vec3(.3,0.0,0.05), vec3(0.2,0.2,0.3), sqrt(max(rd.y, 0.001)));",
|
||||
"col += .4*vec3(.4,.2,0.67)*sun;",
|
||||
"col = clamp(col, 0.0, 1.0);",
|
||||
"col += 0.43*vec3(.4,0.4,0.2)*pow( sun, 21.0 );",
|
||||
|
||||
"// Do the stars...",
|
||||
"float v = 1.0/( 2. * ( 1. + rd.z ) );",
|
||||
"vec2 xy = vec2(rd.y * v, rd.x * v);",
|
||||
"float s = noise(rd.xz*134.);",
|
||||
"s += noise(rd.xz*370.);",
|
||||
"s += noise(rd.xz*870.);",
|
||||
"s = pow(s,19.0) * 0.00000001 * max(rd.y, 0.0);",
|
||||
"if (s > 0.0)",
|
||||
"{",
|
||||
"vec3 backStars = vec3((1.0-sin(xy.x*20.0+time*13.0*rd.x+xy.y*30.0))*.5*s,s, s);",
|
||||
"col += backStars;",
|
||||
"}",
|
||||
|
||||
"// Mix in the clouds...",
|
||||
"col = mix( col, res.xyz, res.w*1.3);",
|
||||
|
||||
"#define CONTRAST 1.1",
|
||||
"#define SATURATION 1.15",
|
||||
"#define BRIGHTNESS 1.03",
|
||||
"col = mix(vec3(.5), mix(vec3(dot(vec3(.2125, .7154, .0721), col*BRIGHTNESS)), col*BRIGHTNESS, SATURATION), CONTRAST);",
|
||||
|
||||
"gl_FragColor = vec4( col, 1.0 );",
|
||||
"}"];
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
PIXI.StarNurseryFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
|
||||
PIXI.StarNurseryFilter.prototype.constructor = PIXI.StarNurseryFilter;
|
||||
|
||||
Object.defineProperty(PIXI.StarNurseryFilter.prototype, 'iGlobalTime', {
|
||||
get: function() {
|
||||
return this.uniforms.iGlobalTime.value;
|
||||
},
|
||||
set: function(value) {
|
||||
this.uniforms.iGlobalTime.value = value;
|
||||
}
|
||||
});
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
// game.load.image('texture', 'wip/64x64.png');
|
||||
game.load.image('texture', 'wip/tex16.png');
|
||||
|
||||
}
|
||||
|
||||
var filter;
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
sprite = game.add.sprite(0, 0, 'texture');
|
||||
sprite.width = 800;
|
||||
sprite.height = 600;
|
||||
|
||||
filter = new PIXI.StarNurseryFilter(sprite.width, sprite.height, sprite.texture);
|
||||
|
||||
sprite.filters = [filter];
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
filter.iGlobalTime = game.time.totalElapsedSeconds();
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
}
|
144
examples/wip/starfieldFilter.js
Normal file
|
@ -0,0 +1,144 @@
|
|||
PIXI.StarFieldFilter = function(width, height, texture)
|
||||
{
|
||||
PIXI.AbstractFilter.call( this );
|
||||
|
||||
this.passes = [this];
|
||||
|
||||
var d = new Date();
|
||||
|
||||
var dates = [
|
||||
d.getFullYear(), // the year (four digits)
|
||||
d.getMonth(), // the month (from 0-11)
|
||||
d.getDate(), // the day of the month (from 1-31)
|
||||
d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds()
|
||||
];
|
||||
|
||||
this.uniforms = {
|
||||
iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }},
|
||||
iGlobalTime: { type: 'f', value: 1 },
|
||||
iDate: { type: 'f4', value: dates },
|
||||
iChannel0: { type: 'sampler2D', value: texture }
|
||||
};
|
||||
|
||||
// Shader by Rebb / TRSI (https://www.shadertoy.com/view/XdX3Wn)
|
||||
this.fragmentSrc = [
|
||||
"precision mediump float;",
|
||||
"uniform vec3 iResolution;",
|
||||
"uniform float iGlobalTime;",
|
||||
"uniform float iChannelTime[4];",
|
||||
"uniform vec4 iMouse;",
|
||||
"uniform vec4 iDate;",
|
||||
"uniform vec3 iChannelResolution[4];",
|
||||
"uniform sampler2D iChannel0;",
|
||||
|
||||
"// add any extra uniforms here",
|
||||
|
||||
"const float tau = 6.28318530717958647692;",
|
||||
|
||||
"// Gamma correction",
|
||||
"#define GAMMA (2.2)",
|
||||
|
||||
"vec3 ToLinear( in vec3 col )",
|
||||
"{",
|
||||
"// simulate a monitor, converting colour values into light values",
|
||||
"return pow( col, vec3(GAMMA) );",
|
||||
"}",
|
||||
|
||||
"vec3 ToGamma( in vec3 col )",
|
||||
"{",
|
||||
"// convert back into colour values, so the correct light will come out of the monitor",
|
||||
"return pow( col, vec3(1.0/GAMMA) );",
|
||||
"}",
|
||||
|
||||
"vec4 Noise( in ivec2 x )",
|
||||
"{",
|
||||
"return texture2D( iChannel0, (vec2(x)+0.5)/256.0, -100.0 );",
|
||||
"}",
|
||||
|
||||
"vec4 Rand( in int x )",
|
||||
"{",
|
||||
"vec2 uv;",
|
||||
"uv.x = (float(x)+0.5)/256.0;",
|
||||
"uv.y = (floor(uv.x)+0.5)/256.0;",
|
||||
"return texture2D( iChannel0, uv, -100.0 );",
|
||||
"}",
|
||||
|
||||
|
||||
"void main(void)",
|
||||
"{",
|
||||
"vec3 ray;",
|
||||
"ray.xy = 2.0*(gl_FragCoord.xy-iResolution.xy*.5)/iResolution.x;",
|
||||
"ray.z = 1.0;",
|
||||
|
||||
"float offset = iGlobalTime*.5;",
|
||||
"float speed2 = (cos(offset)+1.0)*2.0;",
|
||||
"float speed = speed2+.1;",
|
||||
"offset += sin(offset)*.96;",
|
||||
"offset *= 2.0;",
|
||||
|
||||
|
||||
"vec3 col = vec3(0);",
|
||||
|
||||
"vec3 stp = ray/max(abs(ray.x),abs(ray.y));",
|
||||
|
||||
"vec3 pos = 2.0*stp+.5;",
|
||||
"for ( int i=0; i < 20; i++ )",
|
||||
"{",
|
||||
"float z = Noise(ivec2(pos.xy)).x;",
|
||||
"z = fract(z-offset);",
|
||||
"float d = 50.0*z-pos.z;",
|
||||
"float w = pow(max(0.0,1.0-8.0*length(fract(pos.xy)-.5)),2.0);",
|
||||
"vec3 c = max(vec3(0),vec3(1.0-abs(d+speed2*.5)/speed,1.0-abs(d)/speed,1.0-abs(d-speed2*.5)/speed));",
|
||||
"col += 1.5*(1.0-z)*c*w;",
|
||||
"pos += stp;",
|
||||
"}",
|
||||
|
||||
"gl_FragColor = vec4(ToGamma(col),1.0);",
|
||||
"}"];
|
||||
|
||||
}
|
||||
|
||||
PIXI.StarFieldFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
|
||||
PIXI.StarFieldFilter.prototype.constructor = PIXI.StarFieldFilter;
|
||||
|
||||
Object.defineProperty(PIXI.StarFieldFilter.prototype, 'iGlobalTime', {
|
||||
get: function() {
|
||||
return this.uniforms.iGlobalTime.value;
|
||||
},
|
||||
set: function(value) {
|
||||
this.uniforms.iGlobalTime.value = value;
|
||||
}
|
||||
});
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
// game.load.image('texture', 'wip/64x64.png');
|
||||
game.load.image('texture', 'wip/tex16.png');
|
||||
|
||||
}
|
||||
|
||||
var filter;
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
sprite = game.add.sprite(0, 0, 'texture');
|
||||
sprite.width = 512;
|
||||
sprite.height = 512;
|
||||
|
||||
filter = new PIXI.StarFieldFilter(sprite.width, sprite.height, sprite.texture);
|
||||
|
||||
sprite.filters = [filter];
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
filter.iGlobalTime = game.time.totalElapsedSeconds();
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
}
|
117
examples/wip/starsBackgroundFilter.js
Normal file
|
@ -0,0 +1,117 @@
|
|||
PIXI.StarsBackgroundFilter = function(width, height, texture)
|
||||
{
|
||||
PIXI.AbstractFilter.call( this );
|
||||
|
||||
this.passes = [this];
|
||||
|
||||
var d = new Date();
|
||||
|
||||
var dates = [
|
||||
d.getFullYear(), // the year (four digits)
|
||||
d.getMonth(), // the month (from 0-11)
|
||||
d.getDate(), // the day of the month (from 1-31)
|
||||
d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds()
|
||||
];
|
||||
|
||||
this.uniforms = {
|
||||
iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }},
|
||||
iGlobalTime: { type: 'f', value: 1 },
|
||||
iDate: { type: 'f4', value: dates },
|
||||
iChannel0: { type: 'sampler2D', value: texture }
|
||||
};
|
||||
|
||||
// Shader by urraka (https://www.shadertoy.com/view/lsfGWH)
|
||||
this.fragmentSrc = [
|
||||
"precision mediump float;",
|
||||
"uniform vec3 iResolution;",
|
||||
"uniform float iGlobalTime;",
|
||||
"uniform float iChannelTime[4];",
|
||||
"uniform vec4 iMouse;",
|
||||
"uniform vec4 iDate;",
|
||||
"uniform vec3 iChannelResolution[4];",
|
||||
"uniform sampler2D iChannel0;",
|
||||
"// add any extra uniforms here",
|
||||
|
||||
"#define M_PI 3.1415926535897932384626433832795",
|
||||
|
||||
"float rand(vec2 co)",
|
||||
"{",
|
||||
"return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);",
|
||||
"}",
|
||||
|
||||
"void main(void)",
|
||||
"{",
|
||||
"float size = 30.0;",
|
||||
"float prob = 0.95;",
|
||||
|
||||
"vec2 pos = floor(1.0 / size * gl_FragCoord.xy);",
|
||||
|
||||
"float color = 0.0;",
|
||||
"float starValue = rand(pos);",
|
||||
|
||||
"if (starValue > prob)",
|
||||
"{",
|
||||
"vec2 center = size * pos + vec2(size, size) * 0.5;",
|
||||
|
||||
"float t = 0.9 + 0.2 * sin(iGlobalTime + (starValue - prob) / (1.0 - prob) * 45.0);",
|
||||
|
||||
"color = 1.0 - distance(gl_FragCoord.xy, center) / (0.5 * size);",
|
||||
"color = color * t / (abs(gl_FragCoord.y - center.y)) * t / (abs(gl_FragCoord.x - center.x));",
|
||||
"}",
|
||||
"else if (rand(gl_FragCoord.xy / iResolution.xy) > 0.996)",
|
||||
"{",
|
||||
"float r = rand(gl_FragCoord.xy);",
|
||||
"color = r * (0.25 * sin(iGlobalTime * (r * 5.0) + 720.0 * r) + 0.75);",
|
||||
"}",
|
||||
|
||||
"gl_FragColor = vec4(vec3(color), 1.0);",
|
||||
"}"];
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
PIXI.StarsBackgroundFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
|
||||
PIXI.StarsBackgroundFilter.prototype.constructor = PIXI.StarsBackgroundFilter;
|
||||
|
||||
Object.defineProperty(PIXI.StarsBackgroundFilter.prototype, 'iGlobalTime', {
|
||||
get: function() {
|
||||
return this.uniforms.iGlobalTime.value;
|
||||
},
|
||||
set: function(value) {
|
||||
this.uniforms.iGlobalTime.value = value;
|
||||
}
|
||||
});
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
// game.load.image('texture', 'wip/64x64.png');
|
||||
game.load.image('texture', 'wip/tex08.jpg');
|
||||
|
||||
}
|
||||
|
||||
var filter;
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
sprite = game.add.sprite(0, 0, 'texture');
|
||||
sprite.width = 800;
|
||||
sprite.height = 600;
|
||||
|
||||
filter = new PIXI.StarsBackgroundFilter(sprite.width, sprite.height, sprite.texture);
|
||||
|
||||
sprite.filters = [filter];
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
filter.iGlobalTime = game.time.totalElapsedSeconds();
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
}
|
BIN
examples/wip/tex00.jpg
Normal file
After Width: | Height: | Size: 67 KiB |
BIN
examples/wip/tex01.jpg
Normal file
After Width: | Height: | Size: 179 KiB |
BIN
examples/wip/tex02.jpg
Normal file
After Width: | Height: | Size: 48 KiB |
BIN
examples/wip/tex03.jpg
Normal file
After Width: | Height: | Size: 86 KiB |
BIN
examples/wip/tex04.jpg
Normal file
After Width: | Height: | Size: 86 KiB |
BIN
examples/wip/tex05.jpg
Normal file
After Width: | Height: | Size: 151 KiB |
BIN
examples/wip/tex06.jpg
Normal file
After Width: | Height: | Size: 200 KiB |
BIN
examples/wip/tex07.jpg
Normal file
After Width: | Height: | Size: 110 KiB |
BIN
examples/wip/tex08.jpg
Normal file
After Width: | Height: | Size: 146 KiB |
BIN
examples/wip/tex09.jpg
Normal file
After Width: | Height: | Size: 171 KiB |
BIN
examples/wip/tex10.png
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
examples/wip/tex11.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
examples/wip/tex12.png
Normal file
After Width: | Height: | Size: 66 KiB |
BIN
examples/wip/tex14.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
examples/wip/tex15.png
Normal file
After Width: | Height: | Size: 241 B |
BIN
examples/wip/tex16.png
Normal file
After Width: | Height: | Size: 258 KiB |
132
examples/wip/trippyLinesFilter.js
Normal file
|
@ -0,0 +1,132 @@
|
|||
PIXI.TrippyLinesFilter = function(width, height)
|
||||
{
|
||||
PIXI.AbstractFilter.call( this );
|
||||
|
||||
this.passes = [this];
|
||||
|
||||
var d = new Date();
|
||||
|
||||
var dates = [
|
||||
d.getFullYear(), // the year (four digits)
|
||||
d.getMonth(), // the month (from 0-11)
|
||||
d.getDate(), // the day of the month (from 1-31)
|
||||
d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds()
|
||||
];
|
||||
|
||||
this.uniforms = {
|
||||
iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }},
|
||||
iGlobalTime: { type: 'f', value: 1 },
|
||||
iDate: { type: 'f4', value: dates }
|
||||
};
|
||||
|
||||
// Shader by aji (https://www.shadertoy.com/view/lslGRj)
|
||||
this.fragmentSrc = [
|
||||
"precision mediump float;",
|
||||
"uniform vec3 iResolution;",
|
||||
"uniform float iGlobalTime;",
|
||||
"uniform float iChannelTime[4];",
|
||||
"uniform vec4 iMouse;",
|
||||
"uniform vec4 iDate;",
|
||||
"uniform vec3 iChannelResolution[4];",
|
||||
"// add any extra uniforms here",
|
||||
|
||||
|
||||
|
||||
"int schedule = 0;",
|
||||
|
||||
"vec4 hue(float rad)",
|
||||
"{",
|
||||
"rad /= 2.0;",
|
||||
"return vec4(abs(cos(rad)), abs(cos(rad+1.05)),",
|
||||
"abs(cos(rad+2.09)), 1.0);",
|
||||
"}",
|
||||
|
||||
"vec4 gradient(float f)",
|
||||
"{",
|
||||
"f = mod(f, 1.0) * 3.14;",
|
||||
"if (schedule == 0) {",
|
||||
"return vec4(sin(f) * sin(f));",
|
||||
"} else if (schedule == 1) {",
|
||||
"float r = pow(.5 + .5 * sin(2.0 * (f + 0.00)), 20.0);",
|
||||
"float g = pow(.5 + .5 * sin(2.0 * (f + 1.05)), 20.0);",
|
||||
"float b = pow(.5 + .5 * sin(2.0 * (f + 2.09)), 20.0);",
|
||||
"return vec4(r, g, b, 1.0);",
|
||||
"} else if (schedule == 2) {",
|
||||
"return vec4(0.0, .5+.5*sin(f), 0.0, 1.0);",
|
||||
"}",
|
||||
"return vec4(0.0);",
|
||||
"}",
|
||||
|
||||
"float offset(float th)",
|
||||
"{",
|
||||
"float mt = mod(iGlobalTime, 4.0);",
|
||||
"float x = sin(iGlobalTime + th) + sin(iGlobalTime + 2.0 * th)",
|
||||
"+ .3 * cos(iGlobalTime + 8.0 * th);",
|
||||
"if (schedule == 0) {",
|
||||
"return x + .2 * sin(10.0 * iGlobalTime + 20.0 * th);",
|
||||
"} else if (schedule == 1) {",
|
||||
"return x + floor(iGlobalTime * 3.0) * .333;",
|
||||
"} else if (schedule == 2) {",
|
||||
"return x + .1 * sin(60.0 * th);",
|
||||
"}",
|
||||
"return 0.0;",
|
||||
"}",
|
||||
|
||||
"vec4 tunnel(float th, float radius)",
|
||||
"{",
|
||||
"return gradient(offset(th) + log(6.0 * radius));",
|
||||
"}",
|
||||
|
||||
"void main()",
|
||||
"{",
|
||||
"vec2 uv = gl_FragCoord.xy / iResolution.x +",
|
||||
"vec2(-.5, -.5 * iResolution.y / iResolution.x);",
|
||||
"schedule = int(mod(iGlobalTime + 2.0, 6.0) / 2.0);",
|
||||
"gl_FragColor = tunnel(atan(uv.y, uv.x), 2.0 * length(uv));",
|
||||
"}"];
|
||||
|
||||
}
|
||||
|
||||
PIXI.TrippyLinesFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
|
||||
PIXI.TrippyLinesFilter.prototype.constructor = PIXI.TrippyLinesFilter;
|
||||
|
||||
Object.defineProperty(PIXI.TrippyLinesFilter.prototype, 'iGlobalTime', {
|
||||
get: function() {
|
||||
return this.uniforms.iGlobalTime.value;
|
||||
},
|
||||
set: function(value) {
|
||||
this.uniforms.iGlobalTime.value = value;
|
||||
}
|
||||
});
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('texture', 'wip/64x64.png');
|
||||
|
||||
}
|
||||
|
||||
var filter;
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
sprite = game.add.sprite(0, 0, 'texture');
|
||||
sprite.width = 800;
|
||||
sprite.height = 600;
|
||||
|
||||
filter = new PIXI.TrippyLinesFilter(sprite.width, sprite.height);
|
||||
|
||||
sprite.filters = [filter];
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
filter.iGlobalTime = game.time.totalElapsedSeconds();
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
}
|
|
@ -58,7 +58,14 @@ Phaser.BitmapData = function (game, width, height) {
|
|||
/**
|
||||
* @property {UInt8Clamped} pixels - A reference to the context imageData buffer.
|
||||
*/
|
||||
this.pixels = this.imageData.data.buffer;
|
||||
if (this.imageData.data.buffer)
|
||||
{
|
||||
this.pixels = this.imageData.data.buffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.pixels = this.imageData.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @property {PIXI.BaseTexture} baseTexture - The PIXI.BaseTexture.
|
||||
|
|
|
@ -474,6 +474,7 @@ PIXI.DisplayObject.prototype.removeFilter = function(data)
|
|||
{
|
||||
//if(!this.filter)return;
|
||||
//this.filter = false;
|
||||
console.log("YUOIO")
|
||||
// modify the list..
|
||||
var startBlock = data.start;
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/**
|
||||
*
|
||||
* This turns your displayObjects to black and white.
|
||||
* @class GreyFilter
|
||||
* @class ColorStepFilter
|
||||
* @contructor
|
||||
*/
|
||||
PIXI.ColorStepFilter = function()
|
||||
|
|
51
src/pixi/filters/GrayFilter.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* @author Mat Groves http://matgroves.com/ @Doormat23
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* This turns your displayObjects to black and white.
|
||||
* @class GrayFilter
|
||||
* @contructor
|
||||
*/
|
||||
PIXI.GrayFilter = function()
|
||||
{
|
||||
PIXI.AbstractFilter.call( this );
|
||||
|
||||
this.passes = [this];
|
||||
|
||||
// set the uniforms
|
||||
this.uniforms = {
|
||||
gray: {type: 'f', value: 1},
|
||||
};
|
||||
|
||||
this.fragmentSrc = [
|
||||
"precision mediump float;",
|
||||
"varying vec2 vTextureCoord;",
|
||||
"varying float 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);",
|
||||
"gl_FragColor = gl_FragColor * vColor;",
|
||||
"}"
|
||||
];
|
||||
}
|
||||
|
||||
PIXI.GrayFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
|
||||
PIXI.GrayFilter.prototype.constructor = PIXI.GrayFilter;
|
||||
|
||||
/**
|
||||
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(PIXI.GrayFilter.prototype, 'gray', {
|
||||
get: function() {
|
||||
return this.uniforms.gray.value;
|
||||
},
|
||||
set: function(value) {
|
||||
this.uniforms.gray.value = value;
|
||||
}
|
||||
});
|
|
@ -85,7 +85,7 @@ PIXI.AssetLoader.prototype.load = function()
|
|||
for (var i=0; i < this.assetURLs.length; i++)
|
||||
{
|
||||
var fileName = this.assetURLs[i];
|
||||
var fileType = fileName.split(".").pop().toLowerCase();
|
||||
var fileType = fileName.split("?").shift().split(".").pop().toLowerCase();
|
||||
|
||||
var loaderClass = this.loadersByType[fileType];
|
||||
if(!loaderClass)
|
||||
|
|
|
@ -25,7 +25,7 @@ PIXI.PixiShader.prototype.init = function()
|
|||
var program = PIXI.compileProgram(this.vertexSrc || PIXI.PixiShader.defaultVertexSrc, this.fragmentSrc)
|
||||
|
||||
var gl = PIXI.gl;
|
||||
|
||||
|
||||
gl.useProgram(program);
|
||||
|
||||
// get and store the uniforms for the shader
|
||||
|
@ -63,6 +63,44 @@ PIXI.PixiShader.prototype.syncUniforms = function()
|
|||
var type = this.uniforms[key].type;
|
||||
|
||||
// need to grow this!
|
||||
|
||||
/*
|
||||
http://www.khronos.org/registry/webgl/specs/latest/1.0/
|
||||
http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf
|
||||
|
||||
void uniform1f(WebGLUniformLocation? location, GLfloat x);
|
||||
void uniform1fv(WebGLUniformLocation? location, Float32Array v);
|
||||
void uniform1fv(WebGLUniformLocation? location, sequence<GLfloat> v);
|
||||
void uniform1i(WebGLUniformLocation? location, GLint x);
|
||||
void uniform1iv(WebGLUniformLocation? location, Int32Array v);
|
||||
void uniform1iv(WebGLUniformLocation? location, sequence<long> v);
|
||||
void uniform2f(WebGLUniformLocation? location, GLfloat x, GLfloat y);
|
||||
void uniform2fv(WebGLUniformLocation? location, Float32Array v);
|
||||
void uniform2fv(WebGLUniformLocation? location, sequence<GLfloat> v);
|
||||
void uniform2i(WebGLUniformLocation? location, GLint x, GLint y);
|
||||
void uniform2iv(WebGLUniformLocation? location, Int32Array v);
|
||||
void uniform2iv(WebGLUniformLocation? location, sequence<long> v);
|
||||
void uniform3f(WebGLUniformLocation? location, GLfloat x, GLfloat y, GLfloat z);
|
||||
void uniform3fv(WebGLUniformLocation? location, Float32Array v);
|
||||
void uniform3fv(WebGLUniformLocation? location, sequence<GLfloat> v);
|
||||
void uniform3i(WebGLUniformLocation? location, GLint x, GLint y, GLint z);
|
||||
void uniform3iv(WebGLUniformLocation? location, Int32Array v);
|
||||
void uniform3iv(WebGLUniformLocation? location, sequence<long> v);
|
||||
void uniform4f(WebGLUniformLocation? location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
|
||||
void uniform4fv(WebGLUniformLocation? location, Float32Array v);
|
||||
void uniform4fv(WebGLUniformLocation? location, sequence<GLfloat> v);
|
||||
void uniform4i(WebGLUniformLocation? location, GLint x, GLint y, GLint z, GLint w);
|
||||
void uniform4iv(WebGLUniformLocation? location, Int32Array v);
|
||||
void uniform4iv(WebGLUniformLocation? location, sequence<long> v);
|
||||
|
||||
void uniformMatrix2fv(WebGLUniformLocation? location, GLboolean transpose, Float32Array value);
|
||||
void uniformMatrix2fv(WebGLUniformLocation? location, GLboolean transpose, sequence<GLfloat> value);
|
||||
void uniformMatrix3fv(WebGLUniformLocation? location, GLboolean transpose, Float32Array value);
|
||||
void uniformMatrix3fv(WebGLUniformLocation? location, GLboolean transpose, sequence<GLfloat> value);
|
||||
void uniformMatrix4fv(WebGLUniformLocation? location, GLboolean transpose, Float32Array value);
|
||||
void uniformMatrix4fv(WebGLUniformLocation? location, GLboolean transpose, sequence<GLfloat> value);
|
||||
*/
|
||||
|
||||
if(type == "f")
|
||||
{
|
||||
gl.uniform1f(this.uniforms[key].uniformLocation, this.uniforms[key].value);
|
||||
|
@ -72,6 +110,16 @@ PIXI.PixiShader.prototype.syncUniforms = function()
|
|||
// console.log(this.program[key])
|
||||
gl.uniform2f(this.uniforms[key].uniformLocation, this.uniforms[key].value.x, this.uniforms[key].value.y);
|
||||
}
|
||||
else if(type == "f3")
|
||||
{
|
||||
// console.log(this.uniforms[key].value)
|
||||
gl.uniform3f(this.uniforms[key].uniformLocation, this.uniforms[key].value.x, this.uniforms[key].value.y, this.uniforms[key].value.z);
|
||||
}
|
||||
else if(type == "f3v")
|
||||
{
|
||||
// console.log(this.uniforms[key].value)
|
||||
gl.uniform3fv(this.uniforms[key].uniformLocation, this.uniforms[key].value);
|
||||
}
|
||||
else if(type == "f4")
|
||||
{
|
||||
// console.log(this.uniforms[key].value)
|
||||
|
|
|
@ -25,6 +25,7 @@ PIXI.WebGLRenderGroup = function(gl, transparent)
|
|||
|
||||
this.batchs = [];
|
||||
this.toRemove = [];
|
||||
console.log(this.transparent)
|
||||
this.filterManager = new PIXI.WebGLFilterManager(this.transparent);
|
||||
}
|
||||
|
||||
|
|
|
@ -93,6 +93,7 @@ PIXI._CompileShader = function(gl, shaderSrc, shaderType)
|
|||
gl.compileShader(shader);
|
||||
|
||||
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
||||
console.log(gl.getShaderInfoLog(shader));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
/**
|
||||
* Sound Manager constructor.
|
||||
* The Sound Manager is responsible for playing back audio via either the Legacy HTML Audio tag or via Web Audio if the browser supports it.
|
||||
* Note: On Firefox 25+ on Linux if you have media.gstreamer disabled in about:config then it cannot play back mp3 or m4a files.
|
||||
*
|
||||
* @class Phaser.SoundManager
|
||||
* @classdesc Phaser Sound Manager.
|
||||
|
|
|
@ -126,67 +126,78 @@ Phaser.Device = function () {
|
|||
*/
|
||||
this.pointerLock = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} typedArray - Does the browser support TypedArrays?
|
||||
* @default
|
||||
*/
|
||||
this.typedArray = false;
|
||||
|
||||
// Browser
|
||||
|
||||
/**
|
||||
* @property {boolean} arora - Is running in arora?
|
||||
* @property {boolean} arora - Set to true if running in Arora.
|
||||
* @default
|
||||
*/
|
||||
this.arora = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} chrome - Is running in chrome?
|
||||
* @property {boolean} chrome - Set to true if running in Chrome.
|
||||
* @default
|
||||
*/
|
||||
this.chrome = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} epiphany - Is running in epiphany?
|
||||
* @property {boolean} epiphany - Set to true if running in Epiphany.
|
||||
* @default
|
||||
*/
|
||||
this.epiphany = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} firefox - Is running in firefox?
|
||||
* @property {boolean} firefox - Set to true if running in Firefox.
|
||||
* @default
|
||||
*/
|
||||
this.firefox = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} ie - Is running in ie?
|
||||
* @property {boolean} ie - Set to true if running in Internet Explorer.
|
||||
* @default
|
||||
*/
|
||||
this.ie = false;
|
||||
|
||||
/**
|
||||
* @property {number} ieVersion - Version of ie?
|
||||
* @property {number} ieVersion - If running in Internet Explorer this will contain the major version number.
|
||||
* @default
|
||||
*/
|
||||
this.ieVersion = 0;
|
||||
|
||||
/**
|
||||
* @property {boolean} mobileSafari - Is running in mobileSafari?
|
||||
* @property {boolean} mobileSafari - Set to true if running in Mobile Safari.
|
||||
* @default
|
||||
*/
|
||||
this.mobileSafari = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} midori - Is running in midori?
|
||||
* @property {boolean} midori - Set to true if running in Midori.
|
||||
* @default
|
||||
*/
|
||||
this.midori = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} opera - Is running in opera?
|
||||
* @property {boolean} opera - Set to true if running in Opera.
|
||||
* @default
|
||||
*/
|
||||
this.opera = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} safari - Is running in safari?
|
||||
* @property {boolean} safari - Set to true if running in Safari.
|
||||
* @default
|
||||
*/
|
||||
this.safari = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} webApp - Set to true if running as a WebApp, i.e. within a WebView
|
||||
* @default
|
||||
*/
|
||||
this.webApp = false;
|
||||
|
||||
// Audio
|
||||
|
@ -226,6 +237,7 @@ Phaser.Device = function () {
|
|||
* @default
|
||||
*/
|
||||
this.wav = false;
|
||||
|
||||
/**
|
||||
* Can this device play m4a files?
|
||||
* @property {boolean} m4a - True if this device can play m4a files.
|
||||
|
@ -453,6 +465,12 @@ Phaser.Device.prototype = {
|
|||
if (typeof Int8Array !== 'undefined')
|
||||
{
|
||||
this.littleEndian = new Int8Array(new Int16Array([1]).buffer)[0] > 0;
|
||||
this.typedArray = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.littleEndian = false;
|
||||
this.typedArray = false;
|
||||
}
|
||||
|
||||
},
|
||||
|
|
|
@ -135,6 +135,16 @@ Phaser.StageScaleMode = function (game, width, height) {
|
|||
*/
|
||||
this.enterPortrait = new Phaser.Signal();
|
||||
|
||||
/**
|
||||
* @property {Phaser.Signal} enterIncorrectOrientation - The event that is dispatched when the browser enters an incorrect orientation, as defined by forceOrientation.
|
||||
*/
|
||||
this.enterIncorrectOrientation = new Phaser.Signal();
|
||||
|
||||
/**
|
||||
* @property {Phaser.Signal} leaveIncorrectOrientation - The event that is dispatched when the browser leaves an incorrect orientation, as defined by forceOrientation.
|
||||
*/
|
||||
this.leaveIncorrectOrientation = new Phaser.Signal();
|
||||
|
||||
if (window['orientation'])
|
||||
{
|
||||
this.orientation = window['orientation'];
|
||||
|
@ -365,6 +375,7 @@ Phaser.StageScaleMode.prototype = {
|
|||
// Back to normal
|
||||
this.game.paused = false;
|
||||
this.incorrectOrientation = false;
|
||||
this.leaveIncorrectOrientation.dispatch();
|
||||
|
||||
if (this.orientationSprite)
|
||||
{
|
||||
|
@ -382,6 +393,7 @@ Phaser.StageScaleMode.prototype = {
|
|||
// Show orientation screen
|
||||
this.game.paused = true;
|
||||
this.incorrectOrientation = true;
|
||||
this.enterIncorrectOrientation.dispatch();
|
||||
|
||||
if (this.orientationSprite && this.orientationSprite.visible == false)
|
||||
{
|
||||
|
|
|
@ -195,19 +195,54 @@ Phaser.Utils = {
|
|||
|
||||
// Global functions that PIXI needs
|
||||
|
||||
/**
|
||||
* Converts a hex color number to an [R, G, B] array
|
||||
*
|
||||
* @param {number} hex
|
||||
* @return {array}
|
||||
*/
|
||||
(function() {
|
||||
var consoleDisabled = false;
|
||||
if (consoleDisabled) {
|
||||
window.console = undefined;
|
||||
}
|
||||
if (window.console == undefined) {
|
||||
window.console = {
|
||||
debug: function() {
|
||||
return true;
|
||||
},
|
||||
info: function() {
|
||||
return false;
|
||||
},
|
||||
warn: function() {
|
||||
return false;
|
||||
},
|
||||
log: function() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
debug = (function(args) {
|
||||
window.console.debug(args);
|
||||
});
|
||||
info = (function(args) {
|
||||
window.console.info(args);
|
||||
});
|
||||
warn = (function(args) {
|
||||
window.console.warn(args);
|
||||
});
|
||||
log = (function(args) {
|
||||
window.console.log(args);
|
||||
});
|
||||
})();
|
||||
|
||||
/**
|
||||
* Converts a hex color number to an [R, G, B] array
|
||||
*
|
||||
* @param {number} hex
|
||||
* @return {array}
|
||||
*/
|
||||
function HEXtoRGB(hex) {
|
||||
return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255];
|
||||
}
|
||||
|
||||
/**
|
||||
* A polyfill for Function.prototype.bind
|
||||
*/
|
||||
/**
|
||||
* A polyfill for Function.prototype.bind
|
||||
*/
|
||||
if (typeof Function.prototype.bind != 'function') {
|
||||
Function.prototype.bind = (function () {
|
||||
var slice = Array.prototype.slice;
|
||||
|
|