Skip to content

Commit 93fcb7a

Browse files
committed
Loads more shaders and some fixes and enhancements to PixiShader
1 parent e620c99 commit 93fcb7a

13 files changed

Lines changed: 2263 additions & 45 deletions
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
PIXI.TunnelFilter = function(width, height, texture)
2+
{
3+
PIXI.AbstractFilter.call( this );
4+
5+
this.passes = [this];
6+
7+
var d = new Date();
8+
9+
var dates = [
10+
d.getFullYear(), // the year (four digits)
11+
d.getMonth(), // the month (from 0-11)
12+
d.getDate(), // the day of the month (from 1-31)
13+
d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds()
14+
];
15+
16+
this.uniforms = {
17+
iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }},
18+
iGlobalTime: { type: 'f', value: 1 },
19+
iDate: { type: 'f4', value: dates },
20+
iChannel0: { type: 'sampler2D', value: texture, wrap: 'repeat' }
21+
};
22+
23+
// Shader by 4rknova (https://www.shadertoy.com/view/lssGDn)
24+
this.fragmentSrc = [
25+
"precision mediump float;",
26+
"uniform vec3 iResolution;",
27+
"uniform float iGlobalTime;",
28+
"uniform float iChannelTime[4];",
29+
"uniform vec4 iMouse;",
30+
"uniform vec4 iDate;",
31+
"uniform vec3 iChannelResolution[4];",
32+
"uniform sampler2D iChannel0;",
33+
"// add any extra uniforms here",
34+
35+
"#ifdef GL_ES",
36+
"precision highp float;",
37+
"#endif",
38+
39+
"#define S 0.79577471545 // Precalculated 2.5 / PI",
40+
"#define E 0.0001",
41+
42+
"void main(void)",
43+
"{",
44+
"vec2 p = (2.0 * gl_FragCoord.xy / iResolution.xy - 1.0)",
45+
"* vec2(iResolution.x / iResolution.y, 1.0);",
46+
"vec2 t = vec2(S * atan(p.x, p.y), 1.0 / max(length(p), E));",
47+
"vec3 c = texture2D(iChannel0, t + vec2(iGlobalTime * 0.1, iGlobalTime)).xyz;",
48+
"gl_FragColor = vec4(c / (t.y + 0.5), 1.0);",
49+
"}"
50+
];
51+
52+
}
53+
54+
PIXI.TunnelFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
55+
PIXI.TunnelFilter.prototype.constructor = PIXI.TunnelFilter;
56+
57+
Object.defineProperty(PIXI.TunnelFilter.prototype, 'iGlobalTime', {
58+
get: function() {
59+
return this.uniforms.iGlobalTime.value;
60+
},
61+
set: function(value) {
62+
this.uniforms.iGlobalTime.value = value;
63+
}
64+
});
65+
66+
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
67+
68+
function preload() {
69+
70+
game.load.image('texture', 'wip/tex00.jpg');
71+
72+
}
73+
74+
var filter;
75+
var sprite;
76+
77+
function create() {
78+
79+
sprite = game.add.sprite(0, 0, 'texture');
80+
sprite.width = 800;
81+
sprite.height = 600;
82+
83+
filter = new PIXI.TunnelFilter(sprite.width, sprite.height, sprite.texture);
84+
85+
sprite.filters = [filter];
86+
87+
}
88+
89+
function update() {
90+
91+
filter.iGlobalTime = game.time.totalElapsedSeconds();
92+
93+
}
94+
95+
function render() {
96+
}

examples/wip/deformStarFilter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ PIXI.DeformStarFilter = function(width, height, texture)
1717
iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }},
1818
iGlobalTime: { type: 'f', value: 1 },
1919
iDate: { type: 'f4', value: dates },
20-
iChannel0: { type: 'sampler2D', value: texture }
20+
iChannel0: { type: 'sampler2D', value: texture, wrap: 'repeat' }
2121
};
2222

2323
// Shader by iq (https://www.shadertoy.com/view/4dXGRn)

examples/wip/filter.js

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ PIXI.StarNestFilter = function(width, height, texture)
1717
iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }},
1818
iGlobalTime: { type: 'f', value: 1 },
1919
iDate: { type: 'f4', value: dates },
20-
iChannel0: { type: 'sampler2D', value: texture }
20+
iChannel0: { type: 'sampler2D', value: texture, wrap: 'repeat' }
2121
};
2222

2323
// Shader by Kali (https://www.shadertoy.com/view/4dfGDM)
@@ -32,43 +32,38 @@ PIXI.StarNestFilter = function(width, height, texture)
3232
"uniform sampler2D iChannel0;",
3333
"// add any extra uniforms here",
3434

35-
"#define M_PI 3.1415926535897932384626433832795",
35+
"#ifdef GL_ES",
36+
"precision highp float;",
37+
"#endif",
3638

37-
"float rand(vec2 co)",
38-
"{",
39-
"return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);",
40-
"}",
39+
"#define PI 3.1416",
4140

4241
"void main(void)",
4342
"{",
44-
"float size = 30.0;",
45-
"float prob = 0.95;",
43+
"//map the xy pixel co-ordinates to be between -1.0 to +1.0 on x and y axes",
44+
"//and alter the x value according to the aspect ratio so it isn't 'stretched'",
45+
"vec2 p = (2.0 * gl_FragCoord.xy / iResolution.xy - 1.0)",
46+
"* vec2(iResolution.x / iResolution.y, 1.0);",
4647

47-
"vec2 pos = floor(1.0 / size * gl_FragCoord.xy);",
48+
"//now, this is the usual part that uses the formula for texture mapping a ray-",
49+
"//traced cylinder using the vector p that describes the position of the pixel",
50+
"//from the centre.",
51+
"vec2 uv = vec2(atan(p.y, p.x) * 1.0/PI, 1.0 / sqrt(dot(p, p))) * vec2(2.0, 1.0);",
4852

49-
"float color = 0.0;",
50-
"float starValue = rand(pos);",
5153

52-
"if (starValue > prob)",
53-
"{",
54-
"vec2 center = size * pos + vec2(size, size) * 0.5;",
54+
"//now this just 'warps' the texture read by altering the u coordinate depending on",
55+
"//the val of the v coordinate and the current time",
56+
"uv.x += sin(2.0 * uv.y + iGlobalTime * 0.5);",
5557

56-
"float t = 0.9 + 0.2 * sin(iGlobalTime + (starValue - prob) / (1.0 - prob) * 45.0);",
58+
"vec3 c = texture2D(iChannel0, uv).xyz",
5759

58-
"color = 1.0 - distance(gl_FragCoord.xy, center) / (0.5 * size);",
59-
"color = color * t / (abs(gl_FragCoord.y - center.y)) * t / (abs(gl_FragCoord.x - center.x));",
60-
"}",
61-
"else if (rand(gl_FragCoord.xy / iResolution.xy) > 0.996)",
62-
"{",
63-
"float r = rand(gl_FragCoord.xy);",
64-
"color = r * (0.25 * sin(iGlobalTime * (r * 5.0) + 720.0 * r) + 0.75);",
65-
"}",
60+
"//this divison makes the color value 'darker' into the distance, otherwise",
61+
"//everything will be a uniform brightness and no sense of depth will be present.",
62+
"/ (uv.y * 0.5 + 1.0);",
6663

67-
"gl_FragColor = vec4(vec3(color), 1.0);",
64+
"gl_FragColor = vec4(c, 1.0);",
6865
"}"];
6966

70-
71-
7267
}
7368

7469
PIXI.StarNestFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
@@ -87,8 +82,7 @@ var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: p
8782

8883
function preload() {
8984

90-
// game.load.image('texture', 'wip/64x64.png');
91-
game.load.image('texture', 'wip/tex08.jpg');
85+
game.load.image('texture', 'wip/tex00.jpg');
9286

9387
}
9488

examples/wip/hueRotationFilter.js

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
PIXI.HueRotationFilter = function(width, height, texture)
2+
{
3+
PIXI.AbstractFilter.call( this );
4+
5+
this.passes = [this];
6+
7+
var d = new Date();
8+
9+
var dates = [
10+
d.getFullYear(), // the year (four digits)
11+
d.getMonth(), // the month (from 0-11)
12+
d.getDate(), // the day of the month (from 1-31)
13+
d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds()
14+
];
15+
16+
this.uniforms = {
17+
iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }},
18+
iGlobalTime: { type: 'f', value: 1 },
19+
iDate: { type: 'f4', value: dates },
20+
iChannel0: { type: 'sampler2D', value: texture }
21+
};
22+
23+
// Shader by Daniil (https://www.shadertoy.com/view/4sl3DH)
24+
this.fragmentSrc = [
25+
"precision mediump float;",
26+
"uniform vec3 iResolution;",
27+
"uniform float iGlobalTime;",
28+
"uniform float iChannelTime[4];",
29+
"uniform vec4 iMouse;",
30+
"uniform vec4 iDate;",
31+
"uniform vec3 iChannelResolution[4];",
32+
"uniform sampler2D iChannel0;",
33+
"// add any extra uniforms here",
34+
35+
"/* Simple hue rotation filter based on article:",
36+
"http://beesbuzz.biz/code/hsv_color_transforms.php",
37+
"*/",
38+
39+
"#define SPEED 10.0",
40+
41+
"void main(void)",
42+
"{",
43+
"vec2 uv = gl_FragCoord.xy / iResolution.xy;",
44+
45+
"float c = cos(iGlobalTime*SPEED);",
46+
"float s = sin(iGlobalTime*SPEED);",
47+
48+
"mat4 hueRotation =",
49+
"mat4( 0.299, 0.587, 0.114, 0.0,",
50+
"0.299, 0.587, 0.114, 0.0,",
51+
"0.299, 0.587, 0.114, 0.0,",
52+
"0.000, 0.000, 0.000, 1.0) +",
53+
54+
"mat4( 0.701, -0.587, -0.114, 0.0,",
55+
"-0.299, 0.413, -0.114, 0.0,",
56+
"-0.300, -0.588, 0.886, 0.0,",
57+
"0.000, 0.000, 0.000, 0.0) * c +",
58+
59+
"mat4( 0.168, 0.330, -0.497, 0.0,",
60+
"-0.328, 0.035, 0.292, 0.0,",
61+
"1.250, -1.050, -0.203, 0.0,",
62+
"0.000, 0.000, 0.000, 0.0) * s;",
63+
64+
"vec4 pixel = texture2D(iChannel0, uv);",
65+
66+
"gl_FragColor = pixel * hueRotation;",
67+
68+
"}"];
69+
70+
71+
72+
}
73+
74+
PIXI.HueRotationFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
75+
PIXI.HueRotationFilter.prototype.constructor = PIXI.HueRotationFilter;
76+
77+
Object.defineProperty(PIXI.HueRotationFilter.prototype, 'iGlobalTime', {
78+
get: function() {
79+
return this.uniforms.iGlobalTime.value;
80+
},
81+
set: function(value) {
82+
this.uniforms.iGlobalTime.value = value;
83+
}
84+
});
85+
86+
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
87+
88+
function preload() {
89+
90+
// game.load.image('texture', 'wip/64x64.png');
91+
// game.load.image('texture', 'wip/64x64.png');
92+
game.load.image('texture', 'assets/pics/ra_einstein.png');
93+
94+
}
95+
96+
var filter;
97+
var sprite;
98+
99+
function create() {
100+
101+
sprite = game.add.sprite(0, 0, 'texture');
102+
// sprite.width = 800;
103+
// sprite.height = 600;
104+
105+
filter = new PIXI.HueRotationFilter(sprite.width, sprite.height, sprite.texture);
106+
107+
sprite.filters = [filter];
108+
109+
}
110+
111+
function update() {
112+
113+
filter.iGlobalTime = game.time.totalElapsedSeconds();
114+
115+
}
116+
117+
function render() {
118+
}

0 commit comments

Comments
 (0)