move shaders into .glsl files and add #include feature

This commit is contained in:
2019-02-21 19:26:40 +01:00
parent 16eb9de358
commit eaab9c79e5
47 changed files with 1124 additions and 777 deletions

View File

@@ -0,0 +1,9 @@
mediump float blend_stroke(mediump float base, mediump float stroke, int mode)
{
if (mode == 0) /* normal */ return (base + stroke) * 0.5;
else if (mode == 1) /* multiply */ return base * stroke;
else if (mode == 2) /* screen */ return 1.0-(1.0-base)*(1.0-stroke);
else if (mode == 3) /* color-dodge */ return base/(1.0-stroke);
else if (mode == 4) /* overlay */ return mix(2.0*base*stroke, 1.0-2.0*(1.0-base)*(1.0-stroke), floor(base*2.0));
else return 1.0;
}

View File

@@ -0,0 +1,20 @@
mediump vec3 blend_normal(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot)
{ return mix(base.rgb, stroke.rgb, stroke.a/alpha_tot); }
mediump vec3 blend_multiply(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot)
{ return mix(stroke.rgb, mix(base.rgb, base.rgb*stroke.rgb, stroke.a/alpha_tot), base.a/alpha_tot); }
mediump vec3 blend_screen(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot)
{ return mix(stroke.rgb, mix(base.rgb, 1.0-(1.0-base.rgb)*(1.0-stroke.rgb), stroke.a/alpha_tot), base.a/alpha_tot); }
mediump vec3 blend_colorDodge(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot)
{ return mix(stroke.rgb, mix(base.rgb, base.rgb/(1.0-stroke.rgb), stroke.a/alpha_tot), base.a/alpha_tot); }
mediump vec3 blend_overlay(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot)
{ return mix(stroke.rgb, mix(base.rgb, mix(2.0*base.rgb*stroke.rgb, 1.0-2.0*(1.0-base.rgb)*(1.0-stroke.rgb), floor(base.rgb*2.0)), stroke.a/alpha_tot), base.a/alpha_tot); }
mediump vec4 blend(mediump vec4 base, mediump vec4 stroke, int mode) {
mediump float contribution = (1.0 - base.a) * stroke.a;
mediump float alpha_tot = base.a + contribution;
if (mode == 0) return vec4(blend_normal(base, stroke, alpha_tot), alpha_tot);
else if (mode == 1) return vec4(blend_multiply(base, stroke, alpha_tot), alpha_tot);
else if (mode == 2) return vec4(blend_screen(base, stroke, alpha_tot), alpha_tot);
else if (mode == 3) return vec4(blend_colorDodge(base, stroke, alpha_tot), alpha_tot);
else if (mode == 4) return vec4(blend_overlay(base, stroke, alpha_tot), alpha_tot);
else return vec4(1.0, 0.0, 0.0, 1.0);
}

View File

@@ -0,0 +1,13 @@
mediump vec4 blur(sampler2D t, mediump vec2 uv)
{
mediump vec4 sum = texture(t, uv);
sum += textureOffset(t, uv, ivec2(-1, -1));
sum += textureOffset(t, uv, ivec2(-1, 0));
sum += textureOffset(t, uv, ivec2(-1, 1));
sum += textureOffset(t, uv, ivec2( 0, -1));
sum += textureOffset(t, uv, ivec2( 0, 1));
sum += textureOffset(t, uv, ivec2( 1, -1));
sum += textureOffset(t, uv, ivec2( 1, 0));
sum += textureOffset(t, uv, ivec2( 1, 1));
return sum / vec4(9.0);
}

View File

@@ -0,0 +1,20 @@
mediump vec3 brightness3(mediump vec3 c, mediump float val)
{
return clamp(c + vec3(val * 2.0 - 1.0), vec3(0), vec3(1));
}
mediump vec3 contrast3(mediump vec3 c, mediump float val)
{
val = val * 2.0 - 1.0;
mediump float factor = ((259.0 / 255.0) * (val + 1.0)) / (1.0 * ((259.0 / 255.0) - val));
return clamp(factor * (c - 0.5) + 0.5, vec3(0), vec3(1));
}
mediump float brightness1(mediump float c, mediump float val)
{
return clamp(c + (val * 2.0 - 1.0), 0.0, 1.0);
}
mediump float contrast1(mediump float c, mediump float val)
{
val = val * 2.0 - 1.0;
mediump float factor = ((259.0 / 255.0) * (val + 1.0)) / (1.0 * ((259.0 / 255.0) - val));
return clamp(factor * (c - 0.5) + 0.5, 0.0, 1.0);
}

View File

@@ -0,0 +1,5 @@
#if defined(GL_EXT_shader_framebuffer_fetch)
#extension GL_EXT_shader_framebuffer_fetch : enable
#elif defined(GL_ARM_shader_framebuffer_fetch)
#extension GL_ARM_shader_framebuffer_fetch : enable
#endif

View File

@@ -0,0 +1,15 @@
mediump vec3 rgb2hsv(mediump vec3 c)
{
mediump vec4 k = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
mediump vec4 p = mix(vec4(c.bg, k.wz), vec4(c.gb, k.xy), step(c.b, c.g));
mediump vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
mediump float d = q.x - min(q.w, q.y);
mediump float e = 1.0e-10;
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
mediump vec3 hsv2rgb(mediump vec3 c)
{
mediump vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
mediump vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}

View File

@@ -0,0 +1,10 @@
// http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/
highp float rand(mediump vec2 co)
{
highp float a = 12.9898;
highp float b = 78.233;
highp float c = 43758.5453;
highp float dt= dot(co.xy, vec2(a,b));
highp float sn= mod(dt, 3.14);
return fract(sin(sn) * c);
}