2020-11-26 03:39:45 +00:00
|
|
|
#version 400
|
|
|
|
out vec4 sk_FragColor;
|
2021-03-15 18:58:57 +00:00
|
|
|
uniform vec4 src;
|
|
|
|
uniform vec4 dst;
|
2021-03-22 15:43:11 +00:00
|
|
|
float _blend_overlay_component_hh2h2(vec2 s, vec2 d) {
|
2021-03-17 14:58:16 +00:00
|
|
|
return 2.0 * d.x <= d.y ? (2.0 * s.x) * d.x : s.y * d.y - (2.0 * (d.y - d.x)) * (s.y - s.x);
|
|
|
|
}
|
2021-03-22 15:43:11 +00:00
|
|
|
vec4 blend_overlay_h4h4h4(vec4 src, vec4 dst) {
|
|
|
|
vec4 result = vec4(_blend_overlay_component_hh2h2(src.xw, dst.xw), _blend_overlay_component_hh2h2(src.yw, dst.yw), _blend_overlay_component_hh2h2(src.zw, dst.zw), src.w + (1.0 - src.w) * dst.w);
|
2021-03-17 14:58:16 +00:00
|
|
|
result.xyz += dst.xyz * (1.0 - src.w) + src.xyz * (1.0 - dst.w);
|
|
|
|
return result;
|
|
|
|
}
|
2021-03-22 15:43:11 +00:00
|
|
|
float _color_dodge_component_hh2h2(vec2 s, vec2 d) {
|
2021-03-17 14:58:16 +00:00
|
|
|
if (d.x == 0.0) {
|
|
|
|
return s.x * (1.0 - d.y);
|
|
|
|
} else {
|
|
|
|
float delta = s.y - s.x;
|
|
|
|
if (delta == 0.0) {
|
|
|
|
return (s.y * d.y + s.x * (1.0 - d.y)) + d.x * (1.0 - s.y);
|
|
|
|
} else {
|
2021-03-19 13:39:44 +00:00
|
|
|
delta = min(d.y, (d.x * s.y) / delta);
|
2021-03-17 14:58:16 +00:00
|
|
|
return (delta * s.y + s.x * (1.0 - d.y)) + d.x * (1.0 - s.y);
|
2021-03-15 18:30:06 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-17 14:58:16 +00:00
|
|
|
}
|
2021-03-22 15:43:11 +00:00
|
|
|
float _color_burn_component_hh2h2(vec2 s, vec2 d) {
|
2021-03-17 14:58:16 +00:00
|
|
|
if (d.y == d.x) {
|
|
|
|
return (s.y * d.y + s.x * (1.0 - d.y)) + d.x * (1.0 - s.y);
|
|
|
|
} else if (s.x == 0.0) {
|
|
|
|
return d.x * (1.0 - s.y);
|
|
|
|
} else {
|
2021-03-19 13:39:44 +00:00
|
|
|
float delta = max(0.0, d.y - ((d.y - d.x) * s.y) / s.x);
|
2021-03-17 14:58:16 +00:00
|
|
|
return (delta * s.y + s.x * (1.0 - d.y)) + d.x * (1.0 - s.y);
|
|
|
|
}
|
|
|
|
}
|
2021-03-22 15:43:11 +00:00
|
|
|
float _soft_light_component_hh2h2(vec2 s, vec2 d) {
|
2021-03-17 14:58:16 +00:00
|
|
|
if (2.0 * s.x <= s.y) {
|
2021-03-19 13:39:44 +00:00
|
|
|
return (((d.x * d.x) * (s.y - 2.0 * s.x)) / d.y + (1.0 - d.y) * s.x) + d.x * ((-s.y + 2.0 * s.x) + 1.0);
|
2021-03-17 14:58:16 +00:00
|
|
|
} else if (4.0 * d.x <= d.y) {
|
|
|
|
float DSqd = d.x * d.x;
|
|
|
|
float DCub = DSqd * d.x;
|
|
|
|
float DaSqd = d.y * d.y;
|
|
|
|
float DaCub = DaSqd * d.y;
|
2021-03-19 13:39:44 +00:00
|
|
|
return (((DaSqd * (s.x - d.x * ((3.0 * s.y - 6.0 * s.x) - 1.0)) + ((12.0 * d.y) * DSqd) * (s.y - 2.0 * s.x)) - (16.0 * DCub) * (s.y - 2.0 * s.x)) - DaCub * s.x) / DaSqd;
|
2021-03-17 14:58:16 +00:00
|
|
|
} else {
|
|
|
|
return ((d.x * ((s.y - 2.0 * s.x) + 1.0) + s.x) - sqrt(d.y * d.x) * (s.y - 2.0 * s.x)) - d.y * s.x;
|
|
|
|
}
|
|
|
|
}
|
2021-03-22 15:43:11 +00:00
|
|
|
vec3 _blend_set_color_luminance_h3h3hh3(vec3 hueSatColor, float alpha, vec3 lumColor) {
|
2021-03-17 14:58:16 +00:00
|
|
|
float lum = dot(vec3(0.30000001192092896, 0.5899999737739563, 0.10999999940395355), lumColor);
|
|
|
|
vec3 result = (lum - dot(vec3(0.30000001192092896, 0.5899999737739563, 0.10999999940395355), hueSatColor)) + hueSatColor;
|
|
|
|
float minComp = min(min(result.x, result.y), result.z);
|
|
|
|
float maxComp = max(max(result.x, result.y), result.z);
|
|
|
|
if (minComp < 0.0 && lum != minComp) {
|
2021-03-19 13:39:44 +00:00
|
|
|
result = lum + (result - lum) * (lum / (lum - minComp));
|
2021-03-17 14:58:16 +00:00
|
|
|
}
|
|
|
|
if (maxComp > alpha && maxComp != lum) {
|
2021-03-19 13:39:44 +00:00
|
|
|
return lum + ((result - lum) * (alpha - lum)) / (maxComp - lum);
|
2021-03-17 14:58:16 +00:00
|
|
|
} else {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
2021-03-22 15:43:11 +00:00
|
|
|
vec3 _blend_set_color_saturation_helper_h3h3h(vec3 minMidMax, float sat) {
|
2021-03-17 14:58:16 +00:00
|
|
|
if (minMidMax.x < minMidMax.z) {
|
2021-03-19 13:39:44 +00:00
|
|
|
return vec3(0.0, (sat * (minMidMax.y - minMidMax.x)) / (minMidMax.z - minMidMax.x), sat);
|
2021-03-17 14:58:16 +00:00
|
|
|
} else {
|
|
|
|
return vec3(0.0);
|
|
|
|
}
|
|
|
|
}
|
2021-03-22 15:43:11 +00:00
|
|
|
vec3 _blend_set_color_saturation_h3h3h3(vec3 hueLumColor, vec3 satColor) {
|
2021-03-17 14:58:16 +00:00
|
|
|
float sat = max(max(satColor.x, satColor.y), satColor.z) - min(min(satColor.x, satColor.y), satColor.z);
|
|
|
|
if (hueLumColor.x <= hueLumColor.y) {
|
|
|
|
if (hueLumColor.y <= hueLumColor.z) {
|
2021-03-22 15:43:11 +00:00
|
|
|
return _blend_set_color_saturation_helper_h3h3h(hueLumColor, sat);
|
2021-03-17 14:58:16 +00:00
|
|
|
} else if (hueLumColor.x <= hueLumColor.z) {
|
2021-03-22 15:43:11 +00:00
|
|
|
return _blend_set_color_saturation_helper_h3h3h(hueLumColor.xzy, sat).xzy;
|
2021-03-17 14:58:16 +00:00
|
|
|
} else {
|
2021-03-22 15:43:11 +00:00
|
|
|
return _blend_set_color_saturation_helper_h3h3h(hueLumColor.zxy, sat).yzx;
|
2021-03-17 14:58:16 +00:00
|
|
|
}
|
|
|
|
} else if (hueLumColor.x <= hueLumColor.z) {
|
2021-03-22 15:43:11 +00:00
|
|
|
return _blend_set_color_saturation_helper_h3h3h(hueLumColor.yxz, sat).yxz;
|
2021-03-17 14:58:16 +00:00
|
|
|
} else if (hueLumColor.y <= hueLumColor.z) {
|
2021-03-22 15:43:11 +00:00
|
|
|
return _blend_set_color_saturation_helper_h3h3h(hueLumColor.yzx, sat).zxy;
|
2021-03-17 14:58:16 +00:00
|
|
|
} else {
|
2021-03-22 15:43:11 +00:00
|
|
|
return _blend_set_color_saturation_helper_h3h3h(hueLumColor.zyx, sat).zyx;
|
2021-03-17 14:58:16 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-22 15:43:11 +00:00
|
|
|
vec4 blend_h4eh4h4(int mode, vec4 src, vec4 dst) {
|
2021-03-17 14:58:16 +00:00
|
|
|
switch (mode) {
|
|
|
|
case 0:
|
|
|
|
return vec4(0.0);
|
|
|
|
case 1:
|
|
|
|
return src;
|
|
|
|
case 2:
|
|
|
|
return dst;
|
|
|
|
case 3:
|
|
|
|
return src + (1.0 - src.w) * dst;
|
|
|
|
case 4:
|
|
|
|
return (1.0 - dst.w) * src + dst;
|
|
|
|
case 5:
|
|
|
|
return src * dst.w;
|
|
|
|
case 6:
|
|
|
|
return dst * src.w;
|
|
|
|
case 7:
|
|
|
|
return (1.0 - dst.w) * src;
|
|
|
|
case 8:
|
|
|
|
return (1.0 - src.w) * dst;
|
|
|
|
case 9:
|
|
|
|
return dst.w * src + (1.0 - src.w) * dst;
|
|
|
|
case 10:
|
|
|
|
return (1.0 - dst.w) * src + src.w * dst;
|
|
|
|
case 11:
|
|
|
|
return (1.0 - dst.w) * src + (1.0 - src.w) * dst;
|
|
|
|
case 12:
|
|
|
|
return min(src + dst, 1.0);
|
|
|
|
case 13:
|
|
|
|
return src * dst;
|
|
|
|
case 14:
|
|
|
|
return src + (1.0 - src) * dst;
|
|
|
|
case 15:
|
2021-03-22 15:43:11 +00:00
|
|
|
return blend_overlay_h4h4h4(src, dst);
|
2021-03-17 14:58:16 +00:00
|
|
|
case 16:
|
2021-03-19 13:39:44 +00:00
|
|
|
vec4 _0_result = src + (1.0 - src.w) * dst;
|
|
|
|
_0_result.xyz = min(_0_result.xyz, (1.0 - dst.w) * src.xyz + dst.xyz);
|
|
|
|
return _0_result;
|
2021-03-17 14:58:16 +00:00
|
|
|
case 17:
|
2021-03-19 13:39:44 +00:00
|
|
|
vec4 _1_result = src + (1.0 - src.w) * dst;
|
|
|
|
_1_result.xyz = max(_1_result.xyz, (1.0 - dst.w) * src.xyz + dst.xyz);
|
|
|
|
return _1_result;
|
2021-03-17 14:58:16 +00:00
|
|
|
case 18:
|
2021-03-22 15:43:11 +00:00
|
|
|
return vec4(_color_dodge_component_hh2h2(src.xw, dst.xw), _color_dodge_component_hh2h2(src.yw, dst.yw), _color_dodge_component_hh2h2(src.zw, dst.zw), src.w + (1.0 - src.w) * dst.w);
|
2021-03-17 14:58:16 +00:00
|
|
|
case 19:
|
2021-03-22 15:43:11 +00:00
|
|
|
return vec4(_color_burn_component_hh2h2(src.xw, dst.xw), _color_burn_component_hh2h2(src.yw, dst.yw), _color_burn_component_hh2h2(src.zw, dst.zw), src.w + (1.0 - src.w) * dst.w);
|
2021-03-17 14:58:16 +00:00
|
|
|
case 20:
|
2021-03-22 15:43:11 +00:00
|
|
|
return blend_overlay_h4h4h4(dst, src);
|
2021-03-17 14:58:16 +00:00
|
|
|
case 21:
|
2021-03-22 15:43:11 +00:00
|
|
|
return dst.w == 0.0 ? src : vec4(_soft_light_component_hh2h2(src.xw, dst.xw), _soft_light_component_hh2h2(src.yw, dst.yw), _soft_light_component_hh2h2(src.zw, dst.zw), src.w + (1.0 - src.w) * dst.w);
|
2021-03-17 14:58:16 +00:00
|
|
|
case 22:
|
|
|
|
return vec4((src.xyz + dst.xyz) - 2.0 * min(src.xyz * dst.w, dst.xyz * src.w), src.w + (1.0 - src.w) * dst.w);
|
|
|
|
case 23:
|
|
|
|
return vec4((dst.xyz + src.xyz) - (2.0 * dst.xyz) * src.xyz, src.w + (1.0 - src.w) * dst.w);
|
|
|
|
case 24:
|
|
|
|
return vec4(((1.0 - src.w) * dst.xyz + (1.0 - dst.w) * src.xyz) + src.xyz * dst.xyz, src.w + (1.0 - src.w) * dst.w);
|
|
|
|
case 25:
|
2021-03-19 13:39:44 +00:00
|
|
|
float _2_alpha = dst.w * src.w;
|
|
|
|
vec3 _3_sda = src.xyz * dst.w;
|
|
|
|
vec3 _4_dsa = dst.xyz * src.w;
|
2021-03-22 15:43:11 +00:00
|
|
|
return vec4((((_blend_set_color_luminance_h3h3hh3(_blend_set_color_saturation_h3h3h3(_3_sda, _4_dsa), _2_alpha, _4_dsa) + dst.xyz) - _4_dsa) + src.xyz) - _3_sda, (src.w + dst.w) - _2_alpha);
|
2021-03-17 14:58:16 +00:00
|
|
|
case 26:
|
2021-03-19 13:39:44 +00:00
|
|
|
float _5_alpha = dst.w * src.w;
|
|
|
|
vec3 _6_sda = src.xyz * dst.w;
|
|
|
|
vec3 _7_dsa = dst.xyz * src.w;
|
2021-03-22 15:43:11 +00:00
|
|
|
return vec4((((_blend_set_color_luminance_h3h3hh3(_blend_set_color_saturation_h3h3h3(_7_dsa, _6_sda), _5_alpha, _7_dsa) + dst.xyz) - _7_dsa) + src.xyz) - _6_sda, (src.w + dst.w) - _5_alpha);
|
2021-03-17 14:58:16 +00:00
|
|
|
case 27:
|
2021-03-19 13:39:44 +00:00
|
|
|
float _8_alpha = dst.w * src.w;
|
|
|
|
vec3 _9_sda = src.xyz * dst.w;
|
|
|
|
vec3 _10_dsa = dst.xyz * src.w;
|
2021-03-22 15:43:11 +00:00
|
|
|
return vec4((((_blend_set_color_luminance_h3h3hh3(_9_sda, _8_alpha, _10_dsa) + dst.xyz) - _10_dsa) + src.xyz) - _9_sda, (src.w + dst.w) - _8_alpha);
|
2021-03-17 14:58:16 +00:00
|
|
|
case 28:
|
2021-03-19 13:39:44 +00:00
|
|
|
float _11_alpha = dst.w * src.w;
|
|
|
|
vec3 _12_sda = src.xyz * dst.w;
|
|
|
|
vec3 _13_dsa = dst.xyz * src.w;
|
2021-03-22 15:43:11 +00:00
|
|
|
return vec4((((_blend_set_color_luminance_h3h3hh3(_13_dsa, _11_alpha, _12_sda) + dst.xyz) - _13_dsa) + src.xyz) - _12_sda, (src.w + dst.w) - _11_alpha);
|
2021-03-17 14:58:16 +00:00
|
|
|
default:
|
|
|
|
return vec4(0.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void main() {
|
2021-03-22 15:43:11 +00:00
|
|
|
sk_FragColor = blend_h4eh4h4(13, src, dst);
|
2020-11-26 03:39:45 +00:00
|
|
|
}
|