2020-10-12 16:33:27 +00:00
|
|
|
|
|
|
|
out vec4 sk_FragColor;
|
2021-01-15 20:54:02 +00:00
|
|
|
uniform vec4 color;
|
2020-10-12 16:33:27 +00:00
|
|
|
vec4 blend_src_in(vec4 src, vec4 dst) {
|
|
|
|
return src * dst.w;
|
|
|
|
}
|
|
|
|
vec4 blend_dst_in(vec4 src, vec4 dst) {
|
2020-12-17 19:38:56 +00:00
|
|
|
return dst * src.w;
|
2020-10-12 16:33:27 +00:00
|
|
|
}
|
|
|
|
vec3 _blend_set_color_luminance(vec3 hueSatColor, float alpha, vec3 lumColor) {
|
2020-12-17 19:38:56 +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;
|
2020-10-12 16:33:27 +00:00
|
|
|
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-02-10 17:03:42 +00:00
|
|
|
}
|
|
|
|
if (maxComp > alpha && maxComp != lum) {
|
2021-03-19 13:39:44 +00:00
|
|
|
return lum + ((result - lum) * (alpha - lum)) / (maxComp - lum);
|
2021-02-10 17:03:42 +00:00
|
|
|
} else {
|
|
|
|
return result;
|
2020-10-12 16:33:27 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-23 19:48:06 +00:00
|
|
|
vec3 _blend_set_color_saturation_helper(vec3 minMidMax, float sat) {
|
2021-02-10 17:03:42 +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-02-10 17:03:42 +00:00
|
|
|
} else {
|
|
|
|
return vec3(0.0);
|
|
|
|
}
|
2020-11-23 19:48:06 +00:00
|
|
|
}
|
2020-10-12 16:33:27 +00:00
|
|
|
vec3 _blend_set_color_saturation(vec3 hueLumColor, vec3 satColor) {
|
2020-12-17 19:38:56 +00:00
|
|
|
float sat = max(max(satColor.x, satColor.y), satColor.z) - min(min(satColor.x, satColor.y), satColor.z);
|
2020-10-12 16:33:27 +00:00
|
|
|
if (hueLumColor.x <= hueLumColor.y) {
|
|
|
|
if (hueLumColor.y <= hueLumColor.z) {
|
2020-11-24 03:19:04 +00:00
|
|
|
return _blend_set_color_saturation_helper(hueLumColor, sat);
|
2020-10-12 16:33:27 +00:00
|
|
|
} else if (hueLumColor.x <= hueLumColor.z) {
|
2020-11-24 03:19:04 +00:00
|
|
|
return _blend_set_color_saturation_helper(hueLumColor.xzy, sat).xzy;
|
2020-10-12 16:33:27 +00:00
|
|
|
} else {
|
2020-11-24 03:19:04 +00:00
|
|
|
return _blend_set_color_saturation_helper(hueLumColor.zxy, sat).yzx;
|
2020-10-12 16:33:27 +00:00
|
|
|
}
|
|
|
|
} else if (hueLumColor.x <= hueLumColor.z) {
|
2020-11-24 03:19:04 +00:00
|
|
|
return _blend_set_color_saturation_helper(hueLumColor.yxz, sat).yxz;
|
2020-10-12 16:33:27 +00:00
|
|
|
} else if (hueLumColor.y <= hueLumColor.z) {
|
2020-11-24 03:19:04 +00:00
|
|
|
return _blend_set_color_saturation_helper(hueLumColor.yzx, sat).zxy;
|
2020-10-12 16:33:27 +00:00
|
|
|
} else {
|
2020-11-24 03:19:04 +00:00
|
|
|
return _blend_set_color_saturation_helper(hueLumColor.zyx, sat).zyx;
|
2020-10-12 16:33:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
vec4 blend_hue(vec4 src, vec4 dst) {
|
|
|
|
float alpha = dst.w * src.w;
|
|
|
|
vec3 sda = src.xyz * dst.w;
|
|
|
|
vec3 dsa = dst.xyz * src.w;
|
|
|
|
return vec4((((_blend_set_color_luminance(_blend_set_color_saturation(sda, dsa), alpha, dsa) + dst.xyz) - dsa) + src.xyz) - sda, (src.w + dst.w) - alpha);
|
|
|
|
}
|
2020-11-18 20:38:39 +00:00
|
|
|
float singleuse() {
|
|
|
|
return 1.25;
|
|
|
|
}
|
|
|
|
float add(float a, float b) {
|
|
|
|
float c = a + b;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
float mul(float a, float b) {
|
|
|
|
return a * b;
|
|
|
|
}
|
|
|
|
float fma(float a, float b, float c) {
|
|
|
|
return add(mul(a, b), c);
|
|
|
|
}
|
2020-10-12 16:33:27 +00:00
|
|
|
void main() {
|
|
|
|
sk_FragColor = vec4(fma(color.x, color.y, color.z));
|
|
|
|
sk_FragColor *= singleuse();
|
|
|
|
sk_FragColor *= blend_src_in(color.xxyy, color.zzww);
|
|
|
|
sk_FragColor *= blend_dst_in(color.xxyy, color.zzww);
|
|
|
|
sk_FragColor *= blend_hue(color, color.wwww);
|
|
|
|
sk_FragColor *= blend_hue(color, color.wzyx);
|
|
|
|
}
|