Skip to content

Commit e620c99

Browse files
committed
ShaderToy convertor up and working, lots of shaders being turned into Pixi filters :)
1 parent 40e1b4b commit e620c99

50 files changed

Lines changed: 2600 additions & 60 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Version 1.1.3 - in build
7878
* Updated: Sprite will now check the exists property of the Group it is in, if the Group.exists = false the Sprite won't update.
7979
* Updated: Lots of documentation tweaks across various files such as Pointer and Color.
8080
* Updated: If you specify 'null' as a Group parent it will now revert to using the World as the parent (before only 'undefined' worked)
81+
* Updated: Skip preupdate/update for PIXI hierarchies in which an ancestor doesn't exist (thanks cocoademon)
8182

8283

8384

examples/wip/64x64.png

196 Bytes
Loading

examples/wip/TRSIPlasmaFilter.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
PIXI.TRSIPlasmaFilter = function(width, height)
2+
{
3+
PIXI.AbstractFilter.call( this );
4+
5+
this.passes = [this];
6+
7+
var d = new Date();
8+
9+
var dates = [
10+
d.getFullYear(), // the year (four digits)
11+
d.getMonth(), // the month (from 0-11)
12+
d.getDate(), // the day of the month (from 1-31)
13+
d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds()
14+
];
15+
16+
this.uniforms = {
17+
iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }},
18+
iGlobalTime: { type: 'f', value: 1 },
19+
iDate: { type: 'f4', value: dates }
20+
};
21+
22+
// Shader by Rebb / TRSI (https://www.shadertoy.com/view/XdX3Wn)
23+
this.fragmentSrc = [
24+
"precision mediump float;",
25+
"uniform vec3 iResolution;",
26+
"uniform float iGlobalTime;",
27+
"uniform float iChannelTime[4];",
28+
"uniform vec4 iMouse;",
29+
"uniform vec4 iDate;",
30+
"uniform vec3 iChannelResolution[4];",
31+
"// add any extra uniforms here",
32+
33+
"// Rebb/TRSi^Paradise",
34+
35+
"float an= sin(iGlobalTime)/3.14157;",
36+
"float as= sin(an);",
37+
"float zoo = .23232+.38*sin(.7*iGlobalTime);",
38+
"void main(void)",
39+
"{",
40+
"vec2 position = ( gl_FragCoord.xy / iResolution.xy *3.3 );",
41+
42+
"float color = 0.0;",
43+
"color += sin(position.x - position.y) ;",
44+
"color += sin(iGlobalTime)* cos(sin(iGlobalTime)*position.y*position.x*sin(position.x))+.008;",
45+
"color += sin(iGlobalTime)+position.x*sin(position.y*sin(sin(tan(cos (iGlobalTime)))));",
46+
"gl_FragColor = vec4( vec3(sin(color*color)*4.0, sin(color*color) , color )*sin(iGlobalTime+position.x/(iGlobalTime*3.14)),iGlobalTime/10.828 );",
47+
48+
"}"];
49+
50+
}
51+
52+
PIXI.TRSIPlasmaFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
53+
PIXI.TRSIPlasmaFilter.prototype.constructor = PIXI.TRSIPlasmaFilter;
54+
55+
Object.defineProperty(PIXI.TRSIPlasmaFilter.prototype, 'iGlobalTime', {
56+
get: function() {
57+
return this.uniforms.iGlobalTime.value;
58+
},
59+
set: function(value) {
60+
this.uniforms.iGlobalTime.value = value;
61+
}
62+
});
63+
64+
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
65+
66+
function preload() {
67+
68+
game.load.image('texture', 'wip/64x64.png');
69+
70+
}
71+
72+
var filter;
73+
var sprite;
74+
75+
function create() {
76+
77+
sprite = game.add.sprite(0, 0, 'texture');
78+
sprite.width = 800;
79+
sprite.height = 600;
80+
81+
filter = new PIXI.TRSIPlasmaFilter(sprite.width, sprite.height);
82+
83+
sprite.filters = [filter];
84+
85+
}
86+
87+
function update() {
88+
89+
filter.iGlobalTime = game.time.totalElapsedSeconds();
90+
91+
}
92+
93+
function render() {
94+
}

examples/wip/c64PlasmaFilter.js

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
PIXI.C64PlasmaFilter = function(width, height)
2+
{
3+
PIXI.AbstractFilter.call( this );
4+
5+
this.passes = [this];
6+
7+
var d = new Date();
8+
9+
var dates = [
10+
d.getFullYear(), // the year (four digits)
11+
d.getMonth(), // the month (from 0-11)
12+
d.getDate(), // the day of the month (from 1-31)
13+
d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds()
14+
];
15+
16+
this.uniforms = {
17+
iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }},
18+
iGlobalTime: { type: 'f', value: 1 },
19+
iDate: { type: 'f4', value: dates }
20+
};
21+
22+
// Shader by ssdsa (https://www.shadertoy.com/view/MslGzN)
23+
this.fragmentSrc = [
24+
"precision mediump float;",
25+
"uniform vec3 iResolution;",
26+
"uniform float iGlobalTime;",
27+
"uniform float iChannelTime[4];",
28+
"uniform vec4 iMouse;",
29+
"uniform vec4 iDate;",
30+
"uniform vec3 iChannelResolution[4];",
31+
"// add any extra uniforms here",
32+
33+
"// 2D plasma in C64 graphics style",
34+
"//",
35+
"// Version 1.0 (2013-03-31)",
36+
"// Simon Stelling-de San Antonio",
37+
38+
"float camtime = 1.23*iGlobalTime;",
39+
40+
"void main(void)",
41+
"{",
42+
"vec2 p = gl_FragCoord.xy / iResolution.xy;",
43+
"p.y = 1.0 - p.y;",
44+
"p *= 200.0;",
45+
"p.x *= (iResolution.x / iResolution.y);",
46+
"p.x /= 2.0;",
47+
"p = floor(p);",
48+
"p.x *= 2.0;",
49+
"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;",
50+
"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;",
51+
"float e = floor((length(vec2(a,b))",
52+
"+4.0*mod(floor((p.x+p.y+p.y)/2.0),2.0))/13.0);",
53+
"float c;",
54+
"if (e == 0.0) { c = 9.0;",
55+
"} else if (e == 1.0) { c = 2.0;",
56+
"} else if (e == 2.0) { c = 8.0;",
57+
"} else if (e == 3.0) { c = 10.0;",
58+
"} else if (e == 4.0) { c = 15.0;",
59+
"} else if (e == 5.0) { c = 7.0;",
60+
"} else if (e == 6.0) { c = 1.0;",
61+
"} else if (e == 7.0) { c = 13.0;",
62+
"} else if (e == 8.0) { c = 3.0;",
63+
"} else if (e == 9.0) { c = 14.0;",
64+
"} else if (e == 10.0) { c = 4.0;",
65+
"} else if (e == 11.0) { c = 6.0;",
66+
"} else if (e == 12.0) { c = 0.0;",
67+
"} else if (e == 13.0) { c = 11.0;",
68+
"} else if (e == 14.0) { c = 5.0;",
69+
"} else { c = 12.0;",
70+
"}",
71+
"vec3 col;",
72+
"if (c == 0.0) { col = vec3(0.0);",
73+
"} else if (c == 1.0) { col = vec3(1.0);",
74+
"} else if (c == 2.0) { col = vec3(137.0, 64.0, 54.0)/256.0;",
75+
"} else if (c == 3.0) { col = vec3(122.0, 191.0, 199.0)/256.0;",
76+
"} else if (c == 4.0) { col = vec3(138.0, 70.0, 174.0)/256.0;",
77+
"} else if (c == 5.0) { col = vec3(104.0, 169.0, 65.0)/256.0;",
78+
"} else if (c == 6.0) { col = vec3( 62.0, 49.0, 162.0)/256.0;",
79+
"} else if (c == 7.0) { col = vec3(208.0, 220.0, 113.0)/256.0;",
80+
"} else if (c == 8.0) { col = vec3(144.0, 95.0, 37.0)/256.0;",
81+
"} else if (c == 9.0) { col = vec3( 92.0, 71.0, 0.0)/256.0;",
82+
"} else if (c == 10.0) { col = vec3(187.0, 119.0, 109.0)/256.0;",
83+
"} else if (c == 11.0) { col = vec3( 85.0, 85.0, 85.0)/256.0;",
84+
"} else if (c == 12.0) { col = vec3(128.0, 128.0, 128.0)/256.0;",
85+
"} else if (c == 13.0) { col = vec3(172.0, 234.0, 136.0)/256.0;",
86+
"} else if (c == 14.0) { col = vec3(124.0, 112.0, 218.0)/256.0;",
87+
"} else { col = vec3(171.0, 171.0, 171.0)/256.0;",
88+
"}",
89+
"gl_FragColor = vec4(col,1.0);",
90+
"}"];
91+
92+
}
93+
94+
PIXI.C64PlasmaFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
95+
PIXI.C64PlasmaFilter.prototype.constructor = PIXI.C64PlasmaFilter;
96+
97+
Object.defineProperty(PIXI.C64PlasmaFilter.prototype, 'iGlobalTime', {
98+
get: function() {
99+
return this.uniforms.iGlobalTime.value;
100+
},
101+
set: function(value) {
102+
this.uniforms.iGlobalTime.value = value;
103+
}
104+
});
105+
106+
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
107+
108+
function preload() {
109+
110+
game.load.image('texture', 'wip/64x64.png');
111+
112+
}
113+
114+
var filter;
115+
var sprite;
116+
117+
function create() {
118+
119+
sprite = game.add.sprite(0, 0, 'texture');
120+
sprite.width = 800;
121+
sprite.height = 600;
122+
123+
filter = new PIXI.C64PlasmaFilter(sprite.width, sprite.height);
124+
125+
sprite.filters = [filter];
126+
127+
}
128+
129+
function update() {
130+
131+
filter.iGlobalTime = game.time.totalElapsedSeconds();
132+
133+
}
134+
135+
function render() {
136+
}

examples/wip/colorBoxFilter.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
PIXI.ColorBoxFilter = function()
2+
{
3+
PIXI.AbstractFilter.call( this );
4+
5+
this.passes = [this];
6+
7+
var d = new Date();
8+
9+
var dates = [
10+
d.getFullYear(), // the year (four digits)
11+
d.getMonth(), // the month (from 0-11)
12+
d.getDate(), // the day of the month (from 1-31)
13+
d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds()
14+
];
15+
16+
this.uniforms = {
17+
iResolution: { type: 'f3', value: { x: 800, y: 600, z: 0 }},
18+
iGlobalTime: { type: 'f', value: 1 },
19+
iDate: { type: 'f4', value: dates }
20+
};
21+
22+
this.fragmentSrc = [
23+
"precision mediump float;",
24+
"uniform vec3 iResolution;",
25+
"uniform float iGlobalTime;",
26+
"uniform float iChannelTime[4];",
27+
"uniform vec4 iMouse;",
28+
"uniform vec4 iDate;",
29+
"uniform vec3 iChannelResolution[4];",
30+
31+
"void main(void) {",
32+
"vec2 uv = gl_FragCoord.xy / iResolution.xy;",
33+
"gl_FragColor = vec4(uv, 0.5 * sin(iGlobalTime), 0.0);",
34+
"}"
35+
];
36+
37+
}
38+
39+
PIXI.ColorBoxFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
40+
PIXI.ColorBoxFilter.prototype.constructor = PIXI.ColorBoxFilter;
41+
42+
Object.defineProperty(PIXI.ColorBoxFilter.prototype, 'iGlobalTime', {
43+
get: function() {
44+
return this.uniforms.iGlobalTime.value;
45+
},
46+
set: function(value) {
47+
this.uniforms.iGlobalTime.value = value;
48+
}
49+
});
50+
51+
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
52+
53+
function preload() {
54+
55+
game.load.image('tex', 'wip/tex16.png');
56+
game.load.image('sea', 'assets/pics/undersea.jpg');
57+
58+
}
59+
60+
var stars;
61+
62+
function create() {
63+
64+
stars = new PIXI.ColorBoxFilter();
65+
66+
var a = game.add.sprite(0, 0, 'sea');
67+
a.filters = [stars];
68+
69+
}
70+
71+
function update() {
72+
73+
stars.iGlobalTime = game.time.totalElapsedSeconds();
74+
75+
}
76+
77+
function render() {
78+
}

0 commit comments

Comments
 (0)