diff --git a/README.md b/README.md index 9ced1ff08..321a3967b 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/examples/wip/64x64.png b/examples/wip/64x64.png new file mode 100644 index 000000000..f839a2ee0 Binary files /dev/null and b/examples/wip/64x64.png differ diff --git a/examples/wip/TRSIPlasmaFilter.js b/examples/wip/TRSIPlasmaFilter.js new file mode 100644 index 000000000..3b74be2a5 --- /dev/null +++ b/examples/wip/TRSIPlasmaFilter.js @@ -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() { +} diff --git a/examples/wip/c64PlasmaFilter.js b/examples/wip/c64PlasmaFilter.js new file mode 100644 index 000000000..73cd9769e --- /dev/null +++ b/examples/wip/c64PlasmaFilter.js @@ -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() { +} diff --git a/examples/wip/colorBoxFilter.js b/examples/wip/colorBoxFilter.js new file mode 100644 index 000000000..26e3e8e9a --- /dev/null +++ b/examples/wip/colorBoxFilter.js @@ -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() { +} diff --git a/examples/wip/deformStarFilter.js b/examples/wip/deformStarFilter.js new file mode 100644 index 000000000..b62695e5f --- /dev/null +++ b/examples/wip/deformStarFilter.js @@ -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() { +} diff --git a/examples/wip/filter.js b/examples/wip/filter.js index 10e863ac3..994aa2da0 100644 --- a/examples/wip/filter.js +++ b/examples/wip/filter.js @@ -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() { diff --git a/examples/wip/filterconv.php b/examples/wip/filterconv.php index 852155f07..0475bc501 100644 --- a/examples/wip/filterconv.php +++ b/examples/wip/filterconv.php @@ -1,13 +1,76 @@
-