2020-10-12 16:33:27 +00:00
|
|
|
|
|
|
|
out vec4 sk_FragColor;
|
2021-01-15 20:54:02 +00:00
|
|
|
uniform vec4 color;
|
2021-03-22 15:43:11 +00:00
|
|
|
vec4 blend_src_in_h4h4h4(vec4 src, vec4 dst) {
|
2020-10-12 16:33:27 +00:00
|
|
|
return src * dst.w;
|
|
|
|
}
|
2021-03-22 15:43:11 +00:00
|
|
|
vec4 blend_dst_in_h4h4h4(vec4 src, vec4 dst) {
|
2020-12-17 19:38:56 +00:00
|
|
|
return dst * src.w;
|
2020-10-12 16:33:27 +00:00
|
|
|
}
|
2021-03-22 15:43:11 +00:00
|
|
|
vec3 _blend_set_color_luminance_h3h3hh3(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
|
|
|
}
|
|
|
|
}
|
2021-03-22 15:43:11 +00:00
|
|
|
vec3 _blend_set_color_saturation_helper_h3h3h(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
|
|
|
}
|
2021-03-22 15:43:11 +00:00
|
|
|
vec3 _blend_set_color_saturation_h3h3h3(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) {
|
2021-03-22 15:43:11 +00:00
|
|
|
return _blend_set_color_saturation_helper_h3h3h(hueLumColor, sat);
|
2020-10-12 16:33:27 +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;
|
2020-10-12 16:33:27 +00:00
|
|
|
} else {
|
2021-03-22 15:43:11 +00:00
|
|
|
return _blend_set_color_saturation_helper_h3h3h(hueLumColor.zxy, sat).yzx;
|
2020-10-12 16:33:27 +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;
|
2020-10-12 16:33:27 +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;
|
2020-10-12 16:33:27 +00:00
|
|
|
} else {
|
2021-03-22 15:43:11 +00:00
|
|
|
return _blend_set_color_saturation_helper_h3h3h(hueLumColor.zyx, sat).zyx;
|
2020-10-12 16:33:27 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-22 15:43:11 +00:00
|
|
|
vec4 blend_hue_h4h4h4(vec4 src, vec4 dst) {
|
2020-10-12 16:33:27 +00:00
|
|
|
float alpha = dst.w * src.w;
|
|
|
|
vec3 sda = src.xyz * dst.w;
|
|
|
|
vec3 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(sda, dsa), alpha, dsa) + dst.xyz) - dsa) + src.xyz) - sda, (src.w + dst.w) - alpha);
|
2020-10-12 16:33:27 +00:00
|
|
|
}
|
2021-03-22 15:43:11 +00:00
|
|
|
float singleuse_h() {
|
2020-11-18 20:38:39 +00:00
|
|
|
return 1.25;
|
|
|
|
}
|
2021-03-22 15:43:11 +00:00
|
|
|
float add_hhh(float a, float b) {
|
2020-11-18 20:38:39 +00:00
|
|
|
float c = a + b;
|
|
|
|
return c;
|
|
|
|
}
|
2021-03-22 15:43:11 +00:00
|
|
|
float mul_hhh(float a, float b) {
|
2020-11-18 20:38:39 +00:00
|
|
|
return a * b;
|
|
|
|
}
|
2021-03-22 15:43:11 +00:00
|
|
|
float fma_hhhh(float a, float b, float c) {
|
|
|
|
return add_hhh(mul_hhh(a, b), c);
|
2020-11-18 20:38:39 +00:00
|
|
|
}
|
2020-10-12 16:33:27 +00:00
|
|
|
void main() {
|
2021-03-22 15:43:11 +00:00
|
|
|
sk_FragColor = vec4(fma_hhhh(color.x, color.y, color.z));
|
|
|
|
sk_FragColor *= singleuse_h();
|
|
|
|
sk_FragColor *= blend_src_in_h4h4h4(color.xxyy, color.zzww);
|
|
|
|
sk_FragColor *= blend_dst_in_h4h4h4(color.xxyy, color.zzww);
|
|
|
|
sk_FragColor *= blend_hue_h4h4h4(color, color.wwww);
|
|
|
|
sk_FragColor *= blend_hue_h4h4h4(color, color.wzyx);
|
2020-10-12 16:33:27 +00:00
|
|
|
}
|