Skip to content

Commit d677b57

Browse files
committed
Added new utility shaders
1 parent 24406d2 commit d677b57

10 files changed

Lines changed: 179 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = [
2+
'#define SHADER_NAME PHASER_ADD_BLEND_FS',
3+
'',
4+
'precision mediump float;',
5+
'',
6+
'uniform sampler2D uMainSampler1;',
7+
'uniform sampler2D uMainSampler2;',
8+
'uniform float uStrength;',
9+
'',
10+
'varying vec2 outTexCoord;',
11+
'',
12+
'void main ()',
13+
'{',
14+
' vec4 frame1 = texture2D(uMainSampler1, outTexCoord);',
15+
' vec4 frame2 = texture2D(uMainSampler2, outTexCoord);',
16+
'',
17+
' gl_FragColor = frame1 + frame2 * uStrength;',
18+
'}',
19+
''
20+
].join('\n');
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = [
2+
'#define SHADER_NAME PHASER_COLORMATRIX_FS',
3+
'',
4+
'precision mediump float;',
5+
'',
6+
'uniform sampler2D uMainSampler;',
7+
'uniform float uColorMatrix[20];',
8+
'',
9+
'varying vec2 outTexCoord;',
10+
'',
11+
'void main ()',
12+
'{',
13+
' vec4 c = texture2D(uMainSampler, outTexCoord);',
14+
'',
15+
' gl_FragColor.r = uColorMatrix[0] * c.r + uColorMatrix[1] * c.g + uColorMatrix[2] * c.b + uColorMatrix[4];',
16+
' gl_FragColor.g = uColorMatrix[5] * c.r + uColorMatrix[6] * c.g + uColorMatrix[7] * c.b + uColorMatrix[9];',
17+
' gl_FragColor.b = uColorMatrix[10] * c.r + uColorMatrix[11] * c.g + uColorMatrix[12] * c.b + uColorMatrix[14];',
18+
' gl_FragColor.a = c.a;',
19+
'}',
20+
''
21+
].join('\n');
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = [
2+
'#define SHADER_NAME PHASER_COPY_FS',
3+
'',
4+
'precision mediump float;',
5+
'',
6+
'uniform sampler2D uMainSampler;',
7+
'uniform float uBrightness;',
8+
'',
9+
'varying vec2 outTexCoord;',
10+
'',
11+
'void main()',
12+
'{',
13+
' gl_FragColor = texture2D(uMainSampler, outTexCoord) * uBrightness;',
14+
'}',
15+
''
16+
].join('\n');
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = [
2+
'#define SHADER_NAME PHASER_LINEAR_BLEND_FS',
3+
'',
4+
'precision mediump float;',
5+
'',
6+
'uniform sampler2D uMainSampler1;',
7+
'uniform sampler2D uMainSampler2;',
8+
'uniform float uStrength;',
9+
'',
10+
'varying vec2 outTexCoord;',
11+
'',
12+
'void main ()',
13+
'{',
14+
' vec4 frame1 = texture2D(uMainSampler1, outTexCoord);',
15+
' vec4 frame2 = texture2D(uMainSampler2, outTexCoord);',
16+
'',
17+
' gl_FragColor = mix(frame1, frame2 * uStrength, 0.5);',
18+
'}',
19+
''
20+
].join('\n');
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = [
2+
'#define SHADER_NAME PHASER_QUAD_VS',
3+
'',
4+
'precision mediump float;',
5+
'',
6+
'uniform mat4 uProjectionMatrix;',
7+
'',
8+
'attribute vec2 inPosition;',
9+
'attribute vec2 inTexCoord;',
10+
'',
11+
'varying vec2 outTexCoord;',
12+
'',
13+
'void main ()',
14+
'{',
15+
' gl_Position = uProjectionMatrix * vec4(inPosition, 1.0, 1.0);',
16+
'',
17+
' outTexCoord = gl_Position.xy * 0.5 + 0.5;',
18+
'}',
19+
''
20+
].join('\n');
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#define SHADER_NAME PHASER_ADD_BLEND_FS
2+
3+
precision mediump float;
4+
5+
uniform sampler2D uMainSampler1;
6+
uniform sampler2D uMainSampler2;
7+
uniform float uStrength;
8+
9+
varying vec2 outTexCoord;
10+
11+
void main ()
12+
{
13+
vec4 frame1 = texture2D(uMainSampler1, outTexCoord);
14+
vec4 frame2 = texture2D(uMainSampler2, outTexCoord);
15+
16+
gl_FragColor = frame1 + frame2 * uStrength;
17+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#define SHADER_NAME PHASER_COLORMATRIX_FS
2+
3+
precision mediump float;
4+
5+
uniform sampler2D uMainSampler;
6+
uniform float uColorMatrix[20];
7+
8+
varying vec2 outTexCoord;
9+
10+
void main ()
11+
{
12+
vec4 c = texture2D(uMainSampler, outTexCoord);
13+
14+
gl_FragColor.r = uColorMatrix[0] * c.r + uColorMatrix[1] * c.g + uColorMatrix[2] * c.b + uColorMatrix[4];
15+
gl_FragColor.g = uColorMatrix[5] * c.r + uColorMatrix[6] * c.g + uColorMatrix[7] * c.b + uColorMatrix[9];
16+
gl_FragColor.b = uColorMatrix[10] * c.r + uColorMatrix[11] * c.g + uColorMatrix[12] * c.b + uColorMatrix[14];
17+
gl_FragColor.a = c.a;
18+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#define SHADER_NAME PHASER_COPY_FS
2+
3+
precision mediump float;
4+
5+
uniform sampler2D uMainSampler;
6+
uniform float uBrightness;
7+
8+
varying vec2 outTexCoord;
9+
10+
void main()
11+
{
12+
gl_FragColor = texture2D(uMainSampler, outTexCoord) * uBrightness;
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#define SHADER_NAME PHASER_LINEAR_BLEND_FS
2+
3+
precision mediump float;
4+
5+
uniform sampler2D uMainSampler1;
6+
uniform sampler2D uMainSampler2;
7+
uniform float uStrength;
8+
9+
varying vec2 outTexCoord;
10+
11+
void main ()
12+
{
13+
vec4 frame1 = texture2D(uMainSampler1, outTexCoord);
14+
vec4 frame2 = texture2D(uMainSampler2, outTexCoord);
15+
16+
gl_FragColor = mix(frame1, frame2 * uStrength, 0.5);
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#define SHADER_NAME PHASER_QUAD_VS
2+
3+
precision mediump float;
4+
5+
uniform mat4 uProjectionMatrix;
6+
7+
attribute vec2 inPosition;
8+
attribute vec2 inTexCoord;
9+
10+
varying vec2 outTexCoord;
11+
12+
void main ()
13+
{
14+
gl_Position = uProjectionMatrix * vec4(inPosition, 1.0, 1.0);
15+
16+
outTexCoord = gl_Position.xy * 0.5 + 0.5;
17+
}

0 commit comments

Comments
 (0)