Added new utility shaders

This commit is contained in:
Richard Davey 2020-11-11 09:35:02 +00:00
parent 24406d2d4f
commit d677b57ee4
10 changed files with 179 additions and 0 deletions

View file

@ -0,0 +1,20 @@
module.exports = [
'#define SHADER_NAME PHASER_ADD_BLEND_FS',
'',
'precision mediump float;',
'',
'uniform sampler2D uMainSampler1;',
'uniform sampler2D uMainSampler2;',
'uniform float uStrength;',
'',
'varying vec2 outTexCoord;',
'',
'void main ()',
'{',
' vec4 frame1 = texture2D(uMainSampler1, outTexCoord);',
' vec4 frame2 = texture2D(uMainSampler2, outTexCoord);',
'',
' gl_FragColor = frame1 + frame2 * uStrength;',
'}',
''
].join('\n');

View file

@ -0,0 +1,21 @@
module.exports = [
'#define SHADER_NAME PHASER_COLORMATRIX_FS',
'',
'precision mediump float;',
'',
'uniform sampler2D uMainSampler;',
'uniform float uColorMatrix[20];',
'',
'varying vec2 outTexCoord;',
'',
'void main ()',
'{',
' vec4 c = texture2D(uMainSampler, outTexCoord);',
'',
' gl_FragColor.r = uColorMatrix[0] * c.r + uColorMatrix[1] * c.g + uColorMatrix[2] * c.b + uColorMatrix[4];',
' gl_FragColor.g = uColorMatrix[5] * c.r + uColorMatrix[6] * c.g + uColorMatrix[7] * c.b + uColorMatrix[9];',
' gl_FragColor.b = uColorMatrix[10] * c.r + uColorMatrix[11] * c.g + uColorMatrix[12] * c.b + uColorMatrix[14];',
' gl_FragColor.a = c.a;',
'}',
''
].join('\n');

View file

@ -0,0 +1,16 @@
module.exports = [
'#define SHADER_NAME PHASER_COPY_FS',
'',
'precision mediump float;',
'',
'uniform sampler2D uMainSampler;',
'uniform float uBrightness;',
'',
'varying vec2 outTexCoord;',
'',
'void main()',
'{',
' gl_FragColor = texture2D(uMainSampler, outTexCoord) * uBrightness;',
'}',
''
].join('\n');

View file

@ -0,0 +1,20 @@
module.exports = [
'#define SHADER_NAME PHASER_LINEAR_BLEND_FS',
'',
'precision mediump float;',
'',
'uniform sampler2D uMainSampler1;',
'uniform sampler2D uMainSampler2;',
'uniform float uStrength;',
'',
'varying vec2 outTexCoord;',
'',
'void main ()',
'{',
' vec4 frame1 = texture2D(uMainSampler1, outTexCoord);',
' vec4 frame2 = texture2D(uMainSampler2, outTexCoord);',
'',
' gl_FragColor = mix(frame1, frame2 * uStrength, 0.5);',
'}',
''
].join('\n');

View file

@ -0,0 +1,20 @@
module.exports = [
'#define SHADER_NAME PHASER_QUAD_VS',
'',
'precision mediump float;',
'',
'uniform mat4 uProjectionMatrix;',
'',
'attribute vec2 inPosition;',
'attribute vec2 inTexCoord;',
'',
'varying vec2 outTexCoord;',
'',
'void main ()',
'{',
' gl_Position = uProjectionMatrix * vec4(inPosition, 1.0, 1.0);',
'',
' outTexCoord = gl_Position.xy * 0.5 + 0.5;',
'}',
''
].join('\n');

View file

@ -0,0 +1,17 @@
#define SHADER_NAME PHASER_ADD_BLEND_FS
precision mediump float;
uniform sampler2D uMainSampler1;
uniform sampler2D uMainSampler2;
uniform float uStrength;
varying vec2 outTexCoord;
void main ()
{
vec4 frame1 = texture2D(uMainSampler1, outTexCoord);
vec4 frame2 = texture2D(uMainSampler2, outTexCoord);
gl_FragColor = frame1 + frame2 * uStrength;
}

View file

@ -0,0 +1,18 @@
#define SHADER_NAME PHASER_COLORMATRIX_FS
precision mediump float;
uniform sampler2D uMainSampler;
uniform float uColorMatrix[20];
varying vec2 outTexCoord;
void main ()
{
vec4 c = texture2D(uMainSampler, outTexCoord);
gl_FragColor.r = uColorMatrix[0] * c.r + uColorMatrix[1] * c.g + uColorMatrix[2] * c.b + uColorMatrix[4];
gl_FragColor.g = uColorMatrix[5] * c.r + uColorMatrix[6] * c.g + uColorMatrix[7] * c.b + uColorMatrix[9];
gl_FragColor.b = uColorMatrix[10] * c.r + uColorMatrix[11] * c.g + uColorMatrix[12] * c.b + uColorMatrix[14];
gl_FragColor.a = c.a;
}

View file

@ -0,0 +1,13 @@
#define SHADER_NAME PHASER_COPY_FS
precision mediump float;
uniform sampler2D uMainSampler;
uniform float uBrightness;
varying vec2 outTexCoord;
void main()
{
gl_FragColor = texture2D(uMainSampler, outTexCoord) * uBrightness;
}

View file

@ -0,0 +1,17 @@
#define SHADER_NAME PHASER_LINEAR_BLEND_FS
precision mediump float;
uniform sampler2D uMainSampler1;
uniform sampler2D uMainSampler2;
uniform float uStrength;
varying vec2 outTexCoord;
void main ()
{
vec4 frame1 = texture2D(uMainSampler1, outTexCoord);
vec4 frame2 = texture2D(uMainSampler2, outTexCoord);
gl_FragColor = mix(frame1, frame2 * uStrength, 0.5);
}

View file

@ -0,0 +1,17 @@
#define SHADER_NAME PHASER_QUAD_VS
precision mediump float;
uniform mat4 uProjectionMatrix;
attribute vec2 inPosition;
attribute vec2 inTexCoord;
varying vec2 outTexCoord;
void main ()
{
gl_Position = uProjectionMatrix * vec4(inPosition, 1.0, 1.0);
outTexCoord = gl_Position.xy * 0.5 + 0.5;
}