Skip to content

Commit 72af4a2

Browse files
committed
Default shader
1 parent 9b4309b commit 72af4a2

4 files changed

Lines changed: 126 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module.exports = [
2+
'#define SHADER_NAME PHASER_QUAD_SHADER_FS',
3+
'',
4+
'precision mediump float;',
5+
'',
6+
'uniform float time;',
7+
'uniform vec2 resolution;',
8+
'uniform vec2 mouse;',
9+
'',
10+
'varying vec2 fragCoord;',
11+
'',
12+
'vec3 hsv2rgb (vec3 c)',
13+
'{',
14+
' vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);',
15+
' vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);',
16+
' return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);',
17+
'}',
18+
'',
19+
'void main (void)',
20+
'{',
21+
' // Normalized pixel coordinates (from 0 to 1)',
22+
' // vec2 uv = fragCoord / resolution.xy;',
23+
'',
24+
' // Time varying pixel color',
25+
' // vec3 col = 0.5 + 0.5 * cos(time + uv.xyx + vec3(0,2,4));',
26+
'',
27+
' // gl_FragColor = vec4(col, 1.0);',
28+
'',
29+
' // vec2 gg = gl_FragCoord.xy;',
30+
' vec2 gg = fragCoord.xy;',
31+
' float bins = 10.0;',
32+
' vec2 pos = (gg / resolution.xy);',
33+
'',
34+
' // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl_FragCoord.xhtml',
35+
'',
36+
' // vec2 pos = vec2(resolution.x / gl_FragCoord.x, resolution.y / gl_FragCoord.y);',
37+
'',
38+
' float bin = floor(pos.x * bins);',
39+
'',
40+
' gl_FragColor = vec4(hsv2rgb(vec3(bin/bins, 0.5, 1.0)), 1.0);',
41+
'}',
42+
''
43+
].join('\n');
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = [
2+
'#define SHADER_NAME PHASER_QUAD_SHADER_VS',
3+
'',
4+
'precision mediump float;',
5+
'',
6+
'// These are set in ModelViewProjection.mvpUpdate',
7+
'uniform mat4 uProjectionMatrix;',
8+
'uniform mat4 uViewMatrix;',
9+
'uniform mat4 uModelMatrix;',
10+
'',
11+
'// These are set in QuadShaderPipeline',
12+
'attribute vec2 inPosition;',
13+
'',
14+
'varying vec2 fragCoord;',
15+
'',
16+
'void main ()',
17+
'{',
18+
' gl_Position = uProjectionMatrix * uViewMatrix * uModelMatrix * vec4(inPosition, 1.0, 1.0);',
19+
'',
20+
' fragCoord = inPosition;',
21+
'}',
22+
''
23+
].join('\n');
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#define SHADER_NAME PHASER_QUAD_SHADER_FS
2+
3+
precision mediump float;
4+
5+
uniform float time;
6+
uniform vec2 resolution;
7+
uniform vec2 mouse;
8+
9+
varying vec2 fragCoord;
10+
11+
vec3 hsv2rgb (vec3 c)
12+
{
13+
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
14+
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
15+
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
16+
}
17+
18+
void main (void)
19+
{
20+
// Normalized pixel coordinates (from 0 to 1)
21+
// vec2 uv = fragCoord / resolution.xy;
22+
23+
// Time varying pixel color
24+
// vec3 col = 0.5 + 0.5 * cos(time + uv.xyx + vec3(0,2,4));
25+
26+
// gl_FragColor = vec4(col, 1.0);
27+
28+
// vec2 gg = gl_FragCoord.xy;
29+
vec2 gg = fragCoord.xy;
30+
float bins = 10.0;
31+
vec2 pos = (gg / resolution.xy);
32+
33+
// https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl_FragCoord.xhtml
34+
35+
// vec2 pos = vec2(resolution.x / gl_FragCoord.x, resolution.y / gl_FragCoord.y);
36+
37+
float bin = floor(pos.x * bins);
38+
39+
gl_FragColor = vec4(hsv2rgb(vec3(bin/bins, 0.5, 1.0)), 1.0);
40+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#define SHADER_NAME PHASER_QUAD_SHADER_VS
2+
3+
precision mediump float;
4+
5+
// These are set in ModelViewProjection.mvpUpdate
6+
uniform mat4 uProjectionMatrix;
7+
uniform mat4 uViewMatrix;
8+
uniform mat4 uModelMatrix;
9+
10+
// These are set in QuadShaderPipeline
11+
attribute vec2 inPosition;
12+
13+
varying vec2 fragCoord;
14+
15+
void main ()
16+
{
17+
gl_Position = uProjectionMatrix * uViewMatrix * uModelMatrix * vec4(inPosition, 1.0, 1.0);
18+
19+
fragCoord = inPosition;
20+
}

0 commit comments

Comments
 (0)