skia2/tests/sksl/blend/BlendLuminosity.metal
Jim Van Verth e7a8f85e4f Only include header once in combined MSL shader.
Bug: skia:11389
Change-Id: I3e24dcaa2cfeddc7efd7985f9f42a59bfc8175f2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/385137
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
2021-03-15 21:42:06 +00:00

38 lines
1.4 KiB
Metal

struct Inputs {
float4 src;
float4 dst;
};
struct Outputs {
float4 sk_FragColor [[color(0)]];
};
float3 _blend_set_color_luminance(float3 hueSatColor, float alpha, float3 lumColor) {
float lum = dot(float3(0.30000001192092896, 0.5899999737739563, 0.10999999940395355), lumColor);
float3 result = (lum - dot(float3(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) {
float _4_d = lum - minComp;
result = lum + (result - lum) * (lum / _4_d);
}
if (maxComp > alpha && maxComp != lum) {
float3 _5_n = (result - lum) * (alpha - lum);
float _6_d = maxComp - lum;
return lum + _5_n / _6_d;
} else {
return result;
}
}
float4 blend_luminosity(float4 src, float4 dst) {
float alpha = dst.w * src.w;
float3 sda = src.xyz * dst.w;
float3 dsa = dst.xyz * src.w;
return float4((((_blend_set_color_luminance(dsa, alpha, sda) + dst.xyz) - dsa) + src.xyz) - sda, (src.w + dst.w) - alpha);
}
fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
Outputs _out;
(void)_out;
_out.sk_FragColor = blend_luminosity(_in.src, _in.dst);
return _out;
}