2017-09-23 05:59:50 +00:00
|
|
|
#version 420 core
|
|
|
|
|
|
|
|
#include "clip.frag.glsl"
|
|
|
|
|
|
|
|
layout(location = 0) in vec2 inPos;
|
|
|
|
layout(location = 1) in vec2 inStartTexCoord;
|
|
|
|
layout(location = 2) in vec2 inEndTexCoord;
|
|
|
|
layout(location = 3) flat in uint inBlendMode;
|
|
|
|
|
|
|
|
layout(set = 0, binding = 0) uniform sampler2D startTexture;
|
|
|
|
layout(set = 1, binding = 0) uniform sampler2D endTexture;
|
|
|
|
|
2017-09-23 12:59:06 +00:00
|
|
|
layout(location = 0) out vec4 outColor;
|
2017-09-23 05:59:50 +00:00
|
|
|
|
2017-10-09 01:12:22 +00:00
|
|
|
float
|
|
|
|
combine (float source, float backdrop)
|
2017-09-23 05:59:50 +00:00
|
|
|
{
|
2017-10-09 01:12:22 +00:00
|
|
|
return source + backdrop * (1 - source);
|
2017-09-23 05:59:50 +00:00
|
|
|
}
|
|
|
|
|
2017-10-09 01:12:22 +00:00
|
|
|
vec4
|
|
|
|
composite (vec4 Cs, vec4 Cb, vec3 B)
|
2017-09-23 05:59:50 +00:00
|
|
|
{
|
2017-10-09 01:12:22 +00:00
|
|
|
float ao = Cs.a + Cb.a * (1 - Cs.a);
|
|
|
|
vec3 Co = (Cs.a*(1 - Cb.a)*Cs.rgb + Cs.a*Cb.a*B + (1 - Cs.a)*Cb.a*Cb.rgb) / ao;
|
|
|
|
return vec4(Co, ao);
|
2017-09-23 05:59:50 +00:00
|
|
|
}
|
|
|
|
|
2017-10-09 01:12:22 +00:00
|
|
|
vec4
|
|
|
|
normal (vec4 Cs, vec4 Cb)
|
|
|
|
{
|
|
|
|
return composite (Cs, Cb, Cs.rgb);
|
|
|
|
}
|
|
|
|
|
|
|
|
vec4
|
|
|
|
multiply (vec4 Cs, vec4 Cb)
|
2017-09-23 05:59:50 +00:00
|
|
|
{
|
2017-10-09 01:12:22 +00:00
|
|
|
return composite (Cs, Cb, Cs.rgb * Cb.rgb);
|
|
|
|
}
|
|
|
|
|
|
|
|
vec4
|
|
|
|
difference (vec4 Cs, vec4 Cb)
|
|
|
|
{
|
|
|
|
return composite (Cs, Cb, abs(Cs.rgb - Cb.rgb));
|
|
|
|
}
|
|
|
|
|
|
|
|
vec4
|
|
|
|
screen (vec4 Cs, vec4 Cb)
|
|
|
|
{
|
|
|
|
return composite (Cs, Cb, Cs.rgb + Cb.rgb - Cs.rgb * Cb.rgb);
|
2017-09-23 05:59:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
hard_light (float source, float backdrop)
|
|
|
|
{
|
|
|
|
if (source <= 0.5)
|
|
|
|
return 2 * backdrop * source;
|
|
|
|
else
|
|
|
|
return 2 * (backdrop + source - backdrop * source) - 1;
|
|
|
|
}
|
|
|
|
|
2017-10-09 01:12:22 +00:00
|
|
|
vec4
|
|
|
|
hard_light (vec4 Cs, vec4 Cb)
|
2017-09-23 05:59:50 +00:00
|
|
|
{
|
2017-10-09 01:12:22 +00:00
|
|
|
vec3 B = vec3 (hard_light (Cs.r, Cb.r),
|
|
|
|
hard_light (Cs.g, Cb.g),
|
|
|
|
hard_light (Cs.b, Cb.b));
|
|
|
|
return composite (Cs, Cb, B);
|
2017-09-23 05:59:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
soft_light (float source, float backdrop)
|
|
|
|
{
|
|
|
|
float db;
|
|
|
|
|
|
|
|
if (backdrop <= 0.25)
|
|
|
|
db = ((16 * backdrop - 12) * backdrop + 4) * backdrop;
|
|
|
|
else
|
|
|
|
db = sqrt (backdrop);
|
|
|
|
|
|
|
|
if (source <= 0.5)
|
|
|
|
return backdrop - (1 - 2 * source) * backdrop * (1 - backdrop);
|
|
|
|
else
|
|
|
|
return backdrop + (2 * source - 1) * (db - backdrop);
|
|
|
|
}
|
|
|
|
|
2017-10-09 01:12:22 +00:00
|
|
|
vec4
|
|
|
|
soft_light (vec4 Cs, vec4 Cb)
|
2017-09-23 05:59:50 +00:00
|
|
|
{
|
2017-10-09 01:12:22 +00:00
|
|
|
vec3 B = vec3 (soft_light (Cs.r, Cb.r),
|
|
|
|
soft_light (Cs.g, Cb.g),
|
|
|
|
soft_light (Cs.b, Cb.b));
|
|
|
|
return composite (Cs, Cb, B);
|
2017-09-23 05:59:50 +00:00
|
|
|
}
|
|
|
|
|
2017-10-09 01:12:22 +00:00
|
|
|
vec4
|
|
|
|
overlay (vec4 Cs, vec4 Cb)
|
2017-09-23 05:59:50 +00:00
|
|
|
{
|
2017-10-09 01:12:22 +00:00
|
|
|
vec3 B = vec3 (hard_light (Cb.r, Cs.r),
|
|
|
|
hard_light (Cb.g, Cs.g),
|
|
|
|
hard_light (Cb.b, Cs.b));
|
|
|
|
return composite (Cs, Cb, B);
|
2017-09-23 05:59:50 +00:00
|
|
|
}
|
|
|
|
|
2017-10-09 01:12:22 +00:00
|
|
|
vec4
|
|
|
|
darken (vec4 Cs, vec4 Cb)
|
2017-09-23 05:59:50 +00:00
|
|
|
{
|
2017-10-09 01:12:22 +00:00
|
|
|
vec3 B = min (Cs.rgb, Cb.rgb);
|
|
|
|
return composite (Cs, Cb, B);
|
2017-09-23 05:59:50 +00:00
|
|
|
}
|
|
|
|
|
2017-10-09 01:12:22 +00:00
|
|
|
vec4
|
|
|
|
lighten (vec4 Cs, vec4 Cb)
|
2017-09-23 05:59:50 +00:00
|
|
|
{
|
2017-10-09 01:12:22 +00:00
|
|
|
vec3 B = max (Cs.rgb, Cb.rgb);
|
|
|
|
return composite (Cs, Cb, B);
|
2017-09-23 05:59:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
color_dodge (float source, float backdrop)
|
|
|
|
{
|
|
|
|
return (source == 1.0) ? source : min (backdrop / (1.0 - source), 1.0);
|
|
|
|
}
|
|
|
|
|
2017-10-09 01:12:22 +00:00
|
|
|
vec4
|
|
|
|
color_dodge (vec4 Cs, vec4 Cb)
|
2017-09-23 05:59:50 +00:00
|
|
|
{
|
2017-10-09 01:12:22 +00:00
|
|
|
vec3 B = vec3 (color_dodge (Cs.r, Cb.r),
|
|
|
|
color_dodge (Cs.g, Cb.g),
|
|
|
|
color_dodge (Cs.b, Cb.b));
|
|
|
|
return composite (Cs, Cb, B);
|
2017-09-23 05:59:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
float
|
|
|
|
color_burn (float source, float backdrop)
|
|
|
|
{
|
|
|
|
return (source == 0.0) ? source : max ((1.0 - ((1.0 - backdrop) / source)), 0.0);
|
|
|
|
}
|
|
|
|
|
2017-10-09 01:12:22 +00:00
|
|
|
vec4
|
|
|
|
color_burn (vec4 Cs, vec4 Cb)
|
2017-09-23 05:59:50 +00:00
|
|
|
{
|
2017-10-09 01:12:22 +00:00
|
|
|
vec3 B = vec3 (color_burn (Cs.r, Cb.r),
|
|
|
|
color_burn (Cs.g, Cb.g),
|
|
|
|
color_burn (Cs.b, Cb.b));
|
|
|
|
return composite (Cs, Cb, B);
|
2017-09-23 05:59:50 +00:00
|
|
|
}
|
|
|
|
|
2017-10-09 01:12:22 +00:00
|
|
|
vec4
|
|
|
|
exclusion (vec4 Cs, vec4 Cb)
|
2017-09-23 05:59:50 +00:00
|
|
|
{
|
2017-10-09 01:12:22 +00:00
|
|
|
vec3 B = Cb.rgb + Cs.rgb - 2.0 * Cb.rgb * Cs.rgb;
|
|
|
|
return composite (Cs, Cb, B);
|
2017-09-23 05:59:50 +00:00
|
|
|
}
|
|
|
|
|
2017-09-23 12:59:06 +00:00
|
|
|
float
|
|
|
|
lum (vec3 c)
|
|
|
|
{
|
|
|
|
return 0.3 * c.r + 0.59 * c.g + 0.11 * c.b;
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3
|
|
|
|
clip_color (vec3 c)
|
|
|
|
{
|
|
|
|
float l = lum (c);
|
|
|
|
float n = min (c.r, min (c.g, c.b));
|
|
|
|
float x = max (c.r, max (c.g, c.b));
|
|
|
|
if (n < 0) c = l + (((c - l) * l) / (l - n));
|
|
|
|
if (x > 1) c = l + (((c - l) * (1 - l)) / (x - l));
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3
|
|
|
|
set_lum (vec3 c, float l)
|
|
|
|
{
|
|
|
|
float d = l - lum (c);
|
|
|
|
return clip_color (vec3 (c.r + d, c.g + d, c.b + d));
|
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
sat (vec3 c)
|
|
|
|
{
|
|
|
|
return max (c.r, max (c.g, c.b)) - min (c.r, min (c.g, c.b));
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3
|
|
|
|
set_sat (vec3 c, float s)
|
|
|
|
{
|
|
|
|
float cmin = min (c.r, min (c.g, c.b));
|
|
|
|
float cmax = max (c.r, max (c.g, c.b));
|
|
|
|
vec3 res;
|
|
|
|
|
|
|
|
if (cmax == cmin)
|
|
|
|
res = vec3 (0, 0, 0);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (c.r == cmax)
|
|
|
|
{
|
|
|
|
if (c.g == cmin)
|
|
|
|
{
|
|
|
|
res.b = ((c.b - cmin) * s) / (cmax - cmin);
|
|
|
|
res.g = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res.g = ((c.g - cmin) * s) / (cmax - cmin);
|
|
|
|
res.b = 0;
|
|
|
|
}
|
|
|
|
res.r = s;
|
|
|
|
}
|
|
|
|
else if (c.g == cmax)
|
|
|
|
{
|
|
|
|
if (c.r == cmin)
|
|
|
|
{
|
|
|
|
res.b = ((c.b - cmin) * s) / (cmax - cmin);
|
|
|
|
res.r = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res.r = ((c.r - cmin) * s) / (cmax - cmin);
|
|
|
|
res.b = 0;
|
|
|
|
}
|
|
|
|
res.g = s;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (c.r == cmin)
|
|
|
|
{
|
|
|
|
res.g = ((c.g - cmin) * s) / (cmax - cmin);
|
|
|
|
res.r = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res.r = ((c.r - cmin) * s) / (cmax - cmin);
|
|
|
|
res.g = 0;
|
|
|
|
}
|
|
|
|
res.b = s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2017-10-09 01:12:22 +00:00
|
|
|
vec4
|
|
|
|
color (vec4 Cs, vec4 Cb)
|
2017-09-23 12:59:06 +00:00
|
|
|
{
|
2017-10-09 01:12:22 +00:00
|
|
|
vec3 B = set_lum (Cs.rgb, lum (Cb.rgb));
|
|
|
|
return composite (Cs, Cb, B);
|
2017-09-23 12:59:06 +00:00
|
|
|
}
|
|
|
|
|
2017-10-09 01:12:22 +00:00
|
|
|
vec4
|
|
|
|
hue (vec4 Cs, vec4 Cb)
|
2017-09-23 12:59:06 +00:00
|
|
|
{
|
2017-10-09 01:12:22 +00:00
|
|
|
vec3 B = set_lum (set_sat (Cs.rgb, sat (Cb.rgb)), lum (Cb.rgb));
|
|
|
|
return composite (Cs, Cb, B);
|
2017-09-23 12:59:06 +00:00
|
|
|
}
|
|
|
|
|
2017-10-09 01:12:22 +00:00
|
|
|
vec4
|
|
|
|
saturation (vec4 Cs, vec4 Cb)
|
2017-09-23 12:59:06 +00:00
|
|
|
{
|
2017-10-09 01:12:22 +00:00
|
|
|
vec3 B = set_lum (set_sat (Cb.rgb, sat (Cs.rgb)), lum (Cb.rgb));
|
|
|
|
return composite (Cs, Cb, B);
|
2017-09-23 12:59:06 +00:00
|
|
|
}
|
|
|
|
|
2017-10-09 01:12:22 +00:00
|
|
|
vec4
|
|
|
|
luminosity (vec4 Cs, vec4 Cb)
|
2017-09-23 05:59:50 +00:00
|
|
|
{
|
2017-10-09 01:12:22 +00:00
|
|
|
vec3 B = set_lum (Cb.rgb, lum (Cs.rgb));
|
|
|
|
return composite (Cs, Cb, B);
|
2017-09-23 05:59:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
vec4 source = texture (startTexture, inStartTexCoord);
|
|
|
|
vec4 backdrop = texture (endTexture, inEndTexCoord);
|
2017-10-09 01:12:22 +00:00
|
|
|
vec4 result;
|
2017-09-23 05:59:50 +00:00
|
|
|
|
2017-10-09 01:12:22 +00:00
|
|
|
if (inBlendMode == 0)
|
|
|
|
result = normal (source, backdrop);
|
2017-09-23 05:59:50 +00:00
|
|
|
else if (inBlendMode == 1)
|
2017-10-09 01:12:22 +00:00
|
|
|
result = multiply (source, backdrop);
|
2017-09-23 05:59:50 +00:00
|
|
|
else if (inBlendMode == 2)
|
2017-10-09 01:12:22 +00:00
|
|
|
result = screen (source, backdrop);
|
2017-09-23 05:59:50 +00:00
|
|
|
else if (inBlendMode == 3)
|
2017-10-09 01:12:22 +00:00
|
|
|
result = overlay (source, backdrop);
|
2017-09-23 05:59:50 +00:00
|
|
|
else if (inBlendMode == 4)
|
2017-10-09 01:12:22 +00:00
|
|
|
result = darken (source, backdrop);
|
2017-09-23 05:59:50 +00:00
|
|
|
else if (inBlendMode == 5)
|
2017-10-09 01:12:22 +00:00
|
|
|
result = lighten (source, backdrop);
|
2017-09-23 05:59:50 +00:00
|
|
|
else if (inBlendMode == 6)
|
2017-10-09 01:12:22 +00:00
|
|
|
result = color_dodge (source, backdrop);
|
2017-09-23 05:59:50 +00:00
|
|
|
else if (inBlendMode == 7)
|
2017-10-09 01:12:22 +00:00
|
|
|
result = color_burn (source, backdrop);
|
2017-09-23 05:59:50 +00:00
|
|
|
else if (inBlendMode == 8)
|
2017-10-09 01:12:22 +00:00
|
|
|
result = hard_light (source, backdrop);
|
2017-09-23 05:59:50 +00:00
|
|
|
else if (inBlendMode == 9)
|
2017-10-09 01:12:22 +00:00
|
|
|
result = soft_light (source, backdrop);
|
2017-09-23 05:59:50 +00:00
|
|
|
else if (inBlendMode == 10)
|
2017-10-09 01:12:22 +00:00
|
|
|
result = difference (source, backdrop);
|
2017-09-23 05:59:50 +00:00
|
|
|
else if (inBlendMode == 11)
|
2017-10-09 01:12:22 +00:00
|
|
|
result = exclusion (source, backdrop);
|
2017-09-23 12:59:06 +00:00
|
|
|
else if (inBlendMode == 12)
|
2017-10-09 01:12:22 +00:00
|
|
|
result = color (source, backdrop);
|
2017-09-23 12:59:06 +00:00
|
|
|
else if (inBlendMode == 13)
|
2017-10-09 01:12:22 +00:00
|
|
|
result = hue (source, backdrop);
|
2017-09-23 12:59:06 +00:00
|
|
|
else if (inBlendMode == 14)
|
2017-10-09 01:12:22 +00:00
|
|
|
result = saturation (source, backdrop);
|
2017-09-23 12:59:06 +00:00
|
|
|
else if (inBlendMode == 15)
|
2017-10-09 01:12:22 +00:00
|
|
|
result = luminosity (source, backdrop);
|
2017-09-23 05:59:50 +00:00
|
|
|
else
|
|
|
|
discard;
|
|
|
|
|
2017-10-09 01:12:22 +00:00
|
|
|
outColor = clip (inPos, result);
|
2017-09-23 05:59:50 +00:00
|
|
|
}
|