Optimize size of shaders by removing comments and blank lines

This commit is contained in:
Richard Davey 2023-02-15 00:05:16 +00:00
parent 58576252cb
commit 03104d0a8c
30 changed files with 22 additions and 292 deletions

View file

@ -1,15 +1,5 @@
let fs = require('fs-extra');
/*
BitmapMask.frag
BitmapMask.vert
Light.frag
Single.frag
Single.vert
Multi.frag
Multi.vert
*/
let srcdir = './src/renderer/webgl/shaders/src/';
let destdir = './src/renderer/webgl/shaders/';
@ -29,6 +19,11 @@ files.forEach(function (file) {
{
let line = lines[i].trimRight();
if (line == '' || line.trimStart().startsWith('//'))
{
continue;
}
if (i < lines.length - 1)
{
outputSource = outputSource.concat(" '" + line + "',\n");

View file

@ -1,20 +1,14 @@
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

@ -1,20 +1,15 @@
module.exports = [
'#define SHADER_NAME PHASER_BITMAP_MASK_FS',
'',
'precision mediump float;',
'',
'uniform vec2 uResolution;',
'uniform sampler2D uMainSampler;',
'uniform sampler2D uMaskSampler;',
'uniform bool uInvertMaskAlpha;',
'',
'void main ()',
'{',
' vec2 uv = gl_FragCoord.xy / uResolution;',
'',
' vec4 mainColor = texture2D(uMainSampler, uv);',
' vec4 maskColor = texture2D(uMaskSampler, uv);',
'',
' if (!uInvertMaskAlpha)',
' {',
' mainColor *= maskColor.a;',
@ -23,8 +18,6 @@ module.exports = [
' {',
' mainColor *= (1.0 - maskColor.a);',
' }',
'',
' gl_FragColor = mainColor;',
'}',
''
].join('\n');

View file

@ -1,13 +1,9 @@
module.exports = [
'#define SHADER_NAME PHASER_BITMAP_MASK_VS',
'',
'precision mediump float;',
'',
'attribute vec2 inPosition;',
'',
'void main ()',
'{',
' gl_Position = vec4(inPosition, 0.0, 1.0);',
'}',
''
].join('\n');

View file

@ -1,42 +1,29 @@
module.exports = [
'#define SHADER_NAME PHASER_COLORMATRIX_FS',
'',
'precision mediump float;',
'',
'uniform sampler2D uMainSampler;',
'uniform float uColorMatrix[20];',
'uniform float uAlpha;',
'',
'varying vec2 outTexCoord;',
'',
'void main ()',
'{',
' vec4 c = texture2D(uMainSampler, outTexCoord);',
'',
' if (uAlpha == 0.0)',
' {',
' gl_FragColor = c;',
'',
' return;',
' }',
'',
' if (c.a > 0.0)',
' {',
' c.rgb /= c.a;',
' }',
'',
' vec4 result;',
'',
' result.r = (uColorMatrix[0] * c.r) + (uColorMatrix[1] * c.g) + (uColorMatrix[2] * c.b) + (uColorMatrix[3] * c.a) + uColorMatrix[4];',
' result.g = (uColorMatrix[5] * c.r) + (uColorMatrix[6] * c.g) + (uColorMatrix[7] * c.b) + (uColorMatrix[8] * c.a) + uColorMatrix[9];',
' result.b = (uColorMatrix[10] * c.r) + (uColorMatrix[11] * c.g) + (uColorMatrix[12] * c.b) + (uColorMatrix[13] * c.a) + uColorMatrix[14];',
' result.a = (uColorMatrix[15] * c.r) + (uColorMatrix[16] * c.g) + (uColorMatrix[17] * c.b) + (uColorMatrix[18] * c.a) + uColorMatrix[19];',
'',
' vec3 rgb = mix(c.rgb, result.rgb, uAlpha);',
'',
' rgb *= result.a;',
'',
' gl_FragColor = vec4(rgb, result.a);',
'}',
''
].join('\n');

View file

@ -1,16 +1,11 @@
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

@ -1,25 +1,17 @@
module.exports = [
'#define SHADER_NAME BLOOM_FS',
'',
'precision mediump float;',
'',
'uniform sampler2D uMainSampler;',
'',
'uniform vec2 uOffset;',
'uniform float uStrength;',
'uniform vec3 uColor;',
'',
'varying vec2 outTexCoord;',
'',
'void main ()',
'{',
' vec4 sum = texture2D(uMainSampler, outTexCoord) * 0.204164 * uStrength;',
'',
' sum = sum + texture2D(uMainSampler, outTexCoord + uOffset * 1.407333) * 0.304005;',
' sum = sum + texture2D(uMainSampler, outTexCoord - uOffset * 1.407333) * 0.304005;',
' sum = sum + texture2D(uMainSampler, outTexCoord + uOffset * 3.294215) * 0.093913;',
'',
' gl_FragColor = (sum + texture2D(uMainSampler, outTexCoord - uOffset * 3.294215) * 0.093913) * vec4(uColor, 1);',
'}',
''
].join('\n');

View file

@ -1,26 +1,19 @@
module.exports = [
'#define SHADER_NAME BLUR_HIGH_FS',
'',
'precision mediump float;',
'',
'uniform sampler2D uMainSampler;',
'uniform vec2 resolution;',
'uniform vec2 offset;',
'uniform float strength;',
'uniform vec3 color;',
'',
'varying vec2 outTexCoord;',
'',
'void main ()',
'{',
' vec2 uv = outTexCoord;',
'',
' vec4 col = vec4(0.0);',
'',
' vec2 off1 = vec2(1.411764705882353) * offset * strength;',
' vec2 off2 = vec2(3.2941176470588234) * offset * strength;',
' vec2 off3 = vec2(5.176470588235294) * offset * strength;',
'',
' col += texture2D(uMainSampler, uv) * 0.1964825501511404;',
' col += texture2D(uMainSampler, uv + (off1 / resolution)) * 0.2969069646728344;',
' col += texture2D(uMainSampler, uv - (off1 / resolution)) * 0.2969069646728344;',
@ -28,8 +21,6 @@ module.exports = [
' col += texture2D(uMainSampler, uv - (off2 / resolution)) * 0.09447039785044732;',
' col += texture2D(uMainSampler, uv + (off3 / resolution)) * 0.010381362401148057;',
' col += texture2D(uMainSampler, uv - (off3 / resolution)) * 0.010381362401148057;',
'',
' gl_FragColor = col * vec4(color, 1.0);',
'}',
''
].join('\n');

View file

@ -1,28 +1,19 @@
module.exports = [
'#define SHADER_NAME BLUR_LOW_FS',
'',
'precision mediump float;',
'',
'uniform sampler2D uMainSampler;',
'uniform vec2 resolution;',
'uniform float strength;',
'uniform vec3 color;',
'',
'varying vec2 outTexCoord;',
'',
'void main ()',
'{',
' vec2 uv = outTexCoord;',
'',
' vec4 col = vec4(0.0);',
'',
' vec2 offset = vec2(1.333) * strength;',
'',
' col += texture2D(uMainSampler, uv) * 0.29411764705882354;',
' col += texture2D(uMainSampler, uv + (offset / resolution)) * 0.35294117647058826;',
' col += texture2D(uMainSampler, uv - (offset / resolution)) * 0.35294117647058826;',
'',
' gl_FragColor = col * vec4(color, 1.0);',
'}',
''
].join('\n');

View file

@ -1,32 +1,23 @@
module.exports = [
'#define SHADER_NAME BLUR_MED_FS',
'',
'precision mediump float;',
'',
'uniform sampler2D uMainSampler;',
'uniform vec2 resolution;',
'uniform vec2 offset;',
'uniform float strength;',
'uniform vec3 color;',
'',
'varying vec2 outTexCoord;',
'',
'void main ()',
'{',
' vec2 uv = outTexCoord;',
'',
' vec4 col = vec4(0.0);',
'',
' vec2 off1 = vec2(1.3846153846) * offset * strength;',
' vec2 off2 = vec2(3.2307692308) * offset * strength;',
'',
' col += texture2D(uMainSampler, uv) * 0.2270270270;',
' col += texture2D(uMainSampler, uv + (off1 / resolution)) * 0.3162162162;',
' col += texture2D(uMainSampler, uv - (off1 / resolution)) * 0.3162162162;',
' col += texture2D(uMainSampler, uv + (off2 / resolution)) * 0.0702702703;',
' col += texture2D(uMainSampler, uv - (off2 / resolution)) * 0.0702702703;',
'',
' gl_FragColor = col * vec4(color, 1.0);',
'}',
''
].join('\n');

View file

@ -1,68 +1,48 @@
module.exports = [
'#define SHADER_NAME GLOW_FS',
'',
'precision mediump float;',
'',
'uniform sampler2D uMainSampler;',
'',
'varying vec2 outTexCoord;',
'',
'uniform float distance;',
'uniform float outerStrength;',
'uniform float innerStrength;',
'uniform vec2 resolution;',
'uniform vec4 glowColor;',
'uniform bool knockout;',
'',
'const float PI = 3.14159265358979323846264;',
'const float MAX_DIST = 128.0;',
'const float SIZE = 0.15;',
'',
'void main ()',
'{',
' vec2 px = vec2(1.0 / resolution.x, 1.0 / resolution.y);',
'',
' float totalAlpha = 0.0;',
'',
' vec2 direction;',
' vec2 displaced;',
'',
' for (float angle = 0.0; angle < PI * 2.0; angle += SIZE)',
' {',
' direction = vec2(cos(angle), sin(angle)) * px;',
'',
' for (float curDistance = 0.0; curDistance < MAX_DIST; curDistance++)',
' {',
' if (curDistance >= distance)',
' {',
' break;',
' }',
'',
' displaced = outTexCoord + direction * (curDistance + 1.0);',
'',
' totalAlpha += (distance - curDistance) * texture2D(uMainSampler, displaced).a;',
' }',
' }',
'',
' vec4 curColor = texture2D(uMainSampler, outTexCoord);',
'',
' float maxAlpha = 42.0 * distance * (distance + 1.0) / 2.0;',
' float alphaRatio = (totalAlpha / maxAlpha);',
'',
' float innerGlowAlpha = (1.0 - alphaRatio) * innerStrength * curColor.a;',
' float innerGlowStrength = min(1.0, innerGlowAlpha);',
'',
' vec4 innerColor = mix(curColor, glowColor, innerGlowStrength);',
'',
' float outerGlowAlpha = alphaRatio * outerStrength * (1.0 - curColor.a);',
' float outerGlowStrength = min(1.0 - innerColor.a, outerGlowAlpha);',
'',
' vec4 outerGlowColor = outerGlowStrength * glowColor.rgba;',
'',
' if (knockout)',
' {',
' float resultAlpha = outerGlowAlpha + innerGlowAlpha;',
'',
' gl_FragColor = vec4(glowColor.rgb * resultAlpha, resultAlpha);',
' }',
' else',
@ -70,5 +50,4 @@ module.exports = [
' gl_FragColor = innerColor + outerGlowColor;',
' }',
'}',
''
].join('\n');

View file

@ -1,36 +1,38 @@
module.exports = [
'#define SHADER_NAME LINEAR_GRADIENT_FS',
'#define SHADER_NAME GRADIENT_FS',
'#define SRGB_TO_LINEAR(c) pow((c), vec3(2.2))',
'#define LINEAR_TO_SRGB(c) pow((c), vec3(1.0 / 2.2))',
'#define SRGB(r, g, b) SRGB_TO_LINEAR(vec3(float(r), float(g), float(b)) / 255.0)',
'',
'precision mediump float;',
'',
'uniform sampler2D uMainSampler;',
'',
'uniform vec2 positionFrom;',
'uniform vec2 positionTo;',
'uniform vec3 color1;',
'uniform vec3 color2;',
'uniform float alpha;',
'uniform int size;',
'',
'varying vec2 outTexCoord;',
'',
'float gradientNoise(in vec2 uv)',
'{',
' const vec3 magic = vec3(0.06711056, 0.00583715, 52.9829189);',
' return fract(magic.z * fract(dot(uv, magic.xy)));',
'}',
'float stepped (in float s, in float scale, in int steps)',
'{',
' return steps > 0 ? floor( s / ((1.0 * scale) / float(steps))) * 1.0 / float(steps - 1) : s;',
'}',
'',
'void main ()',
'{',
' float s = stepped(outTexCoord.y, 1.0, size);',
'',
' vec3 color = mix(SRGB(color1.r, color1.g, color1.b), SRGB(color2.r, color2.g, color2.b), s);',
'',
' vec2 a = positionFrom;',
' vec2 b = positionTo;',
' vec2 ba = b - a;',
' float d = dot(outTexCoord - a, ba) / dot(ba, ba);',
' float t = size > 0 ? stepped(d, 1.0, size) : d;',
' t = smoothstep(0.0, 1.0, clamp(t, 0.0, 1.0));',
' vec3 color = mix(SRGB(color1.r, color1.g, color1.b), SRGB(color2.r, color2.g, color2.b), t);',
' color = LINEAR_TO_SRGB(color);',
'',
' color += (1.0 / 255.0) * gradientNoise(outTexCoord) - (0.5 / 255.0);',
' vec4 texture = texture2D(uMainSampler, outTexCoord);',
'',
' gl_FragColor = vec4(mix(texture.rgb, color.rgb, alpha), 1.0) * texture.a;',
' gl_FragColor = vec4(mix(color.rgb, texture.rgb, alpha), 1.0) * texture.a;',
'}',
''
].join('\n');

View file

@ -1,33 +1,23 @@
module.exports = [
'#define SHADER_NAME PIXELATE_FS',
'',
'precision mediump float;',
'',
'uniform sampler2D uMainSampler;',
'uniform vec2 resolution;',
'uniform float amount;',
'',
'varying vec2 outTexCoord;',
'',
'void main ()',
'{',
' float pixelSize = floor(2.0 + amount);',
'',
' vec2 center = pixelSize * floor(outTexCoord * resolution / pixelSize) + pixelSize * vec2(0.5, 0.5);',
'',
' vec2 corner1 = center + pixelSize * vec2(-0.5, -0.5);',
' vec2 corner2 = center + pixelSize * vec2(+0.5, -0.5);',
' vec2 corner3 = center + pixelSize * vec2(+0.5, +0.5);',
' vec2 corner4 = center + pixelSize * vec2(-0.5, +0.5);',
'',
' vec4 pixel = 0.4 * texture2D(uMainSampler, center / resolution);',
'',
' pixel += 0.15 * texture2D(uMainSampler, corner1 / resolution);',
' pixel += 0.15 * texture2D(uMainSampler, corner2 / resolution);',
' pixel += 0.15 * texture2D(uMainSampler, corner3 / resolution);',
' pixel += 0.15 * texture2D(uMainSampler, corner4 / resolution);',
'',
' gl_FragColor = pixel;',
'}',
''
].join('\n');

View file

@ -1,43 +1,30 @@
module.exports = [
'#define SHADER_NAME SHADOW_FS',
'',
'precision mediump float;',
'',
'uniform sampler2D uMainSampler;',
'',
'varying vec2 outTexCoord;',
'',
'uniform vec2 lightPosition;',
'uniform vec4 color;',
'uniform float decay;',
'uniform float power;',
'uniform float intensity;',
'uniform int samples;',
'',
'const int MAX = 12;',
'',
'void main ()',
'{',
' vec4 texture = texture2D(uMainSampler, outTexCoord);',
'',
' vec2 pc = (lightPosition - outTexCoord) * intensity;',
'',
' float shadow = 0.0;',
' float limit = max(float(MAX), float(samples));',
'',
' for (int i = 0; i < MAX; ++i)',
' {',
' if (i >= samples)',
' {',
' break;',
' }',
'',
' shadow += texture2D(uMainSampler, outTexCoord + float(i) * decay / limit * pc).a * power;',
' }',
'',
' float mask = 1.0 - texture.a;',
'',
' gl_FragColor = mix(texture, color, shadow * mask);',
'}',
''
].join('\n');

View file

@ -1,8 +1,6 @@
module.exports = [
'#define SHADER_NAME SHINE_FS',
'',
'precision mediump float;',
'',
'uniform sampler2D uMainSampler;',
'uniform vec2 resolution;',
'uniform bool reveal;',
@ -10,30 +8,20 @@ module.exports = [
'uniform float time;',
'uniform float lineWidth;',
'uniform float gradient;',
'',
'varying vec2 outTexCoord;',
'',
'void main ()',
'{',
' vec2 uv = gl_FragCoord.xy / resolution.xy;',
'',
' vec4 tex = texture2D(uMainSampler, outTexCoord);',
'',
' vec4 col1 = vec4(0.3, 0.0, 0.0, 1.0);',
' vec4 col2 = vec4(0.85, 0.85, 0.85, 1.0);',
'',
' uv.x = uv.x - mod(time * speed, 2.0) + 0.5;',
' float y = uv.x * gradient;',
'',
' float s = smoothstep(y - lineWidth, y, uv.y) - smoothstep(y, y + lineWidth, uv.y);',
'',
' gl_FragColor = (((s * col1) + (s * col2)) * tex);',
'',
' if (!reveal)',
' {',
' // Apply the shine effect',
' gl_FragColor += tex;',
' }',
'}',
''
].join('\n');

View file

@ -1,31 +1,22 @@
module.exports = [
'#define SHADER_NAME VIGNETTE_FS',
'',
'precision mediump float;',
'',
'uniform sampler2D uMainSampler;',
'uniform float radius;',
'uniform float strength;',
'uniform vec2 position;',
'',
'varying vec2 outTexCoord;',
'',
'void main ()',
'{',
' vec4 col = vec4(1.0);',
'',
' float d = length(outTexCoord - position);',
'',
' if (d <= radius)',
' {',
' float g = d / radius;',
' g = sin(g * 3.14 * strength);',
' col = vec4(g * g * g);',
' }',
'',
' vec4 texture = texture2D(uMainSampler, outTexCoord);',
'',
' gl_FragColor = texture * (1.0 - col);',
'}',
''
].join('\n');

View file

@ -1,8 +1,6 @@
module.exports = [
'#define SHADER_NAME PHASER_LIGHT_FS',
'',
'precision mediump float;',
'',
'struct Light',
'{',
' vec2 position;',
@ -10,9 +8,7 @@ module.exports = [
' float intensity;',
' float radius;',
'};',
'',
'const int kMaxLights = %LIGHT_COUNT%;',
'',
'uniform vec4 uCamera; /* x, y, rotation, zoom */',
'uniform vec2 uResolution;',
'uniform sampler2D uMainSampler;',
@ -21,36 +17,27 @@ module.exports = [
'uniform Light uLights[kMaxLights];',
'uniform mat3 uInverseRotationMatrix;',
'uniform int uLightCount;',
'',
'varying vec2 outTexCoord;',
'varying float outTexId;',
'varying float outTintEffect;',
'varying vec4 outTint;',
'',
'void main ()',
'{',
' vec3 finalColor = vec3(0.0, 0.0, 0.0);',
'',
' vec4 texel = vec4(outTint.bgr * outTint.a, outTint.a);',
' vec4 texture = texture2D(uMainSampler, outTexCoord);',
' // Multiply texture tint',
' vec4 color = texture * texel;',
'',
' if (outTintEffect == 1.0)',
' {',
' // Solid color + texture alpha',
' color.rgb = mix(texture.rgb, outTint.bgr * outTint.a, texture.a);',
' }',
' else if (outTintEffect == 2.0)',
' {',
' // Solid color, no texture',
' color = texel;',
' }',
'',
' vec3 normalMap = texture2D(uNormSampler, outTexCoord).rgb;',
' vec3 normal = normalize(uInverseRotationMatrix * vec3(normalMap * 2.0 - 1.0));',
' vec2 res = vec2(min(uResolution.x, uResolution.y)) * uCamera.w;',
'',
' for (int index = 0; index < kMaxLights; ++index)',
' {',
' if (index < uLightCount)',
@ -66,10 +53,7 @@ module.exports = [
' finalColor += (attenuation * diffuse) * light.intensity;',
' }',
' }',
'',
' vec4 colorOutput = vec4(uAmbientLightColor + finalColor, 1.0);',
'',
' gl_FragColor = color * vec4(colorOutput.rgb * colorOutput.a, colorOutput.a);',
'}',
''
].join('\n');

View file

@ -1,20 +1,14 @@
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

@ -1,54 +1,38 @@
module.exports = [
'#define SHADER_NAME PHASER_MESH_FS',
'',
'precision mediump float;',
'',
'uniform vec3 uLightPosition;',
'uniform vec3 uLightAmbient;',
'uniform vec3 uLightDiffuse;',
'uniform vec3 uLightSpecular;',
'',
'uniform vec3 uFogColor;',
'uniform float uFogNear;',
'uniform float uFogFar;',
'',
'uniform vec3 uMaterialAmbient;',
'uniform vec3 uMaterialDiffuse;',
'uniform vec3 uMaterialSpecular;',
'uniform float uMaterialShine;',
'',
'uniform vec3 uCameraPosition;',
'',
'uniform sampler2D uTexture;',
'',
'varying vec2 vTextureCoord;',
'varying vec3 vNormal;',
'varying vec3 vPosition;',
'',
'void main (void)',
'{',
' vec4 color = texture2D(uTexture, vTextureCoord);',
'',
' vec3 ambient = uLightAmbient * uMaterialAmbient;',
'',
' vec3 norm = normalize(vNormal);',
' vec3 lightDir = normalize(uLightPosition - vPosition);',
' float diff = max(dot(norm, lightDir), 0.0);',
' vec3 diffuse = uLightDiffuse * (diff * uMaterialDiffuse);',
'',
' vec3 viewDir = normalize(uCameraPosition - vPosition);',
' vec3 reflectDir = reflect(-lightDir, norm);',
' float spec = pow(max(dot(viewDir, reflectDir), 0.0), uMaterialShine);',
' vec3 specular = uLightSpecular * (spec * uMaterialSpecular);',
'',
' vec3 result = (ambient + diffuse + specular) * color.rgb;',
'',
' float depth = gl_FragCoord.z / gl_FragCoord.w;',
'',
' float fogFactor = smoothstep(uFogNear, uFogFar, depth);',
'',
' gl_FragColor.rgb = mix(result.rgb, uFogColor, fogFactor);',
' gl_FragColor.a = color.a;',
'}',
''
].join('\n');

View file

@ -1,29 +1,20 @@
module.exports = [
'#define SHADER_NAME PHASER_MESH_VS',
'',
'precision mediump float;',
'',
'attribute vec3 aVertexPosition;',
'attribute vec3 aVertexNormal;',
'attribute vec2 aTextureCoord;',
'',
'uniform mat4 uViewProjectionMatrix;',
'uniform mat4 uModelMatrix;',
'uniform mat4 uNormalMatrix;',
'',
'varying vec2 vTextureCoord;',
'varying vec3 vNormal;',
'varying vec3 vPosition;',
'',
'void main ()',
'{',
' vTextureCoord = aTextureCoord;',
'',
' vPosition = vec3(uModelMatrix * vec4(aVertexPosition, 1.0));',
'',
' vNormal = vec3(uNormalMatrix * vec4(aVertexNormal, 1.0));',
'',
' gl_Position = uViewProjectionMatrix * uModelMatrix * vec4(aVertexPosition, 1.0);',
'}',
''
].join('\n');

View file

@ -1,39 +1,27 @@
module.exports = [
'#define SHADER_NAME PHASER_MOBILE_FS',
'',
'#ifdef GL_FRAGMENT_PRECISION_HIGH',
'precision highp float;',
'#else',
'precision mediump float;',
'#endif',
'',
'uniform sampler2D uMainSampler;',
'',
'varying vec2 outTexCoord;',
'varying float outTintEffect;',
'varying vec4 outTint;',
'',
'void main ()',
'{',
' vec4 texel = vec4(outTint.bgr * outTint.a, outTint.a);',
'',
' vec4 texture = texture2D(uMainSampler, outTexCoord);',
'',
' // Multiply texture tint',
' vec4 color = texture * texel;',
'',
' if (outTintEffect == 1.0)',
' {',
' // Solid color + texture alpha',
' color.rgb = mix(texture.rgb, outTint.bgr * outTint.a, texture.a);',
' }',
' else if (outTintEffect == 2.0)',
' {',
' // Solid color, no texture',
' color = texel;',
' }',
'',
' gl_FragColor = color;',
'}',
''
].join('\n');

View file

@ -1,31 +1,24 @@
module.exports = [
'#define SHADER_NAME PHASER_MOBILE_VS',
'',
'#ifdef GL_FRAGMENT_PRECISION_HIGH',
'precision highp float;',
'#else',
'precision mediump float;',
'#endif',
'',
'uniform mat4 uProjectionMatrix;',
'',
'attribute vec2 inPosition;',
'attribute vec2 inTexCoord;',
'attribute float inTexId;',
'attribute float inTintEffect;',
'attribute vec4 inTint;',
'',
'varying vec2 outTexCoord;',
'varying float outTintEffect;',
'varying vec4 outTint;',
'',
'void main ()',
'{',
' gl_Position = uProjectionMatrix * vec4(inPosition, 1.0, 1.0);',
'',
' outTexCoord = inTexCoord;',
' outTint = inTint;',
' outTintEffect = inTintEffect;',
'}',
''
].join('\n');

View file

@ -1,42 +1,29 @@
module.exports = [
'#define SHADER_NAME PHASER_MULTI_FS',
'',
'#ifdef GL_FRAGMENT_PRECISION_HIGH',
'precision highp float;',
'#else',
'precision mediump float;',
'#endif',
'',
'uniform sampler2D uMainSampler[%count%];',
'',
'varying vec2 outTexCoord;',
'varying float outTexId;',
'varying float outTintEffect;',
'varying vec4 outTint;',
'',
'void main ()',
'{',
' vec4 texture;',
'',
' %forloop%',
'',
' vec4 texel = vec4(outTint.bgr * outTint.a, outTint.a);',
'',
' // Multiply texture tint',
' vec4 color = texture * texel;',
'',
' if (outTintEffect == 1.0)',
' {',
' // Solid color + texture alpha',
' color.rgb = mix(texture.rgb, outTint.bgr * outTint.a, texture.a);',
' }',
' else if (outTintEffect == 2.0)',
' {',
' // Solid color, no texture',
' color = texel;',
' }',
'',
' gl_FragColor = color;',
'}',
''
].join('\n');

View file

@ -1,33 +1,26 @@
module.exports = [
'#define SHADER_NAME PHASER_MULTI_VS',
'',
'#ifdef GL_FRAGMENT_PRECISION_HIGH',
'precision highp float;',
'#else',
'precision mediump float;',
'#endif',
'',
'uniform mat4 uProjectionMatrix;',
'',
'attribute vec2 inPosition;',
'attribute vec2 inTexCoord;',
'attribute float inTexId;',
'attribute float inTintEffect;',
'attribute vec4 inTint;',
'',
'varying vec2 outTexCoord;',
'varying float outTexId;',
'varying float outTintEffect;',
'varying vec4 outTint;',
'',
'void main ()',
'{',
' gl_Position = uProjectionMatrix * vec4(inPosition, 1.0, 1.0);',
'',
' outTexCoord = inTexCoord;',
' outTexId = inTexId;',
' outTint = inTint;',
' outTintEffect = inTintEffect;',
'}',
''
].join('\n');

View file

@ -1,29 +1,19 @@
module.exports = [
'#define SHADER_NAME PHASER_POINTLIGHT_FS',
'',
'precision mediump float;',
'',
'uniform vec2 uResolution;',
'uniform float uCameraZoom;',
'',
'varying vec4 lightPosition;',
'varying vec4 lightColor;',
'varying float lightRadius;',
'varying float lightAttenuation;',
'',
'void main ()',
'{',
' vec2 center = (lightPosition.xy + 1.0) * (uResolution.xy * 0.5);',
'',
' float distToSurf = length(center - gl_FragCoord.xy);',
'',
' float radius = 1.0 - distToSurf / (lightRadius * uCameraZoom);',
'',
' float intensity = smoothstep(0.0, 1.0, radius * lightAttenuation);',
'',
' vec4 color = vec4(intensity, intensity, intensity, 0.0) * lightColor;',
'',
' gl_FragColor = vec4(color.rgb * lightColor.a, color.a);',
'}',
''
].join('\n');

View file

@ -1,29 +1,22 @@
module.exports = [
'#define SHADER_NAME PHASER_POINTLIGHT_VS',
'',
'precision mediump float;',
'',
'uniform mat4 uProjectionMatrix;',
'',
'attribute vec2 inPosition;',
'attribute vec2 inLightPosition;',
'attribute vec4 inLightColor;',
'attribute float inLightRadius;',
'attribute float inLightAttenuation;',
'',
'varying vec4 lightPosition;',
'varying vec4 lightColor;',
'varying float lightRadius;',
'varying float lightAttenuation;',
'',
'void main ()',
'{',
' lightColor = inLightColor;',
' lightRadius = inLightRadius;',
' lightAttenuation = inLightAttenuation;',
' lightPosition = uProjectionMatrix * vec4(inLightPosition, 1.0, 1.0);',
'',
' gl_Position = uProjectionMatrix * vec4(inPosition, 1.0, 1.0);',
'}',
''
].join('\n');

View file

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

View file

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

View file

@ -1,38 +1,27 @@
module.exports = [
'#define SHADER_NAME PHASER_SINGLE_FS',
'',
'#ifdef GL_FRAGMENT_PRECISION_HIGH',
'precision highp float;',
'#else',
'precision mediump float;',
'#endif',
'',
'uniform sampler2D uMainSampler;',
'',
'varying vec2 outTexCoord;',
'varying float outTintEffect;',
'varying vec4 outTint;',
'',
'void main ()',
'{',
' vec4 texture = texture2D(uMainSampler, outTexCoord);',
' vec4 texel = vec4(outTint.bgr * outTint.a, outTint.a);',
'',
' // Multiply texture tint',
' vec4 color = texture * texel;',
'',
' if (outTintEffect == 1.0)',
' {',
' // Solid color + texture alpha',
' color.rgb = mix(texture.rgb, outTint.bgr * outTint.a, texture.a);',
' }',
' else if (outTintEffect == 2.0)',
' {',
' // Solid color, no texture',
' color = texel;',
' }',
'',
' gl_FragColor = color;',
'}',
''
].join('\n');

View file

@ -1,27 +1,20 @@
module.exports = [
'#define SHADER_NAME PHASER_SINGLE_VS',
'',
'precision mediump float;',
'',
'uniform mat4 uProjectionMatrix;',
'',
'attribute vec2 inPosition;',
'attribute vec2 inTexCoord;',
'attribute float inTexId;',
'attribute float inTintEffect;',
'attribute vec4 inTint;',
'',
'varying vec2 outTexCoord;',
'varying float outTintEffect;',
'varying vec4 outTint;',
'',
'void main ()',
'{',
' gl_Position = uProjectionMatrix * vec4(inPosition, 1.0, 1.0);',
'',
' outTexCoord = inTexCoord;',
' outTint = inTint;',
' outTintEffect = inTintEffect;',
'}',
''
].join('\n');