2021-03-16 14:40:11 +00:00
|
|
|
#include <metal_stdlib>
|
|
|
|
#include <simd/simd.h>
|
|
|
|
using namespace metal;
|
2021-03-15 18:58:57 +00:00
|
|
|
struct Uniforms {
|
2021-10-30 02:34:51 +00:00
|
|
|
half4 src;
|
|
|
|
half4 dst;
|
2020-09-25 17:35:58 +00:00
|
|
|
};
|
2021-03-15 18:58:57 +00:00
|
|
|
struct Inputs {
|
|
|
|
};
|
2020-09-25 17:35:58 +00:00
|
|
|
struct Outputs {
|
2021-10-30 02:34:51 +00:00
|
|
|
half4 sk_FragColor [[color(0)]];
|
2020-09-25 17:35:58 +00:00
|
|
|
};
|
2021-10-30 02:34:51 +00:00
|
|
|
half _soft_light_component_hh2h2(half2 s, half2 d) {
|
|
|
|
if (2.0h * s.x <= s.y) {
|
|
|
|
return (((d.x * d.x) * (s.y - 2.0h * s.x)) / d.y + (1.0h - d.y) * s.x) + d.x * ((-s.y + 2.0h * s.x) + 1.0h);
|
|
|
|
} else if (4.0h * d.x <= d.y) {
|
|
|
|
half DSqd = d.x * d.x;
|
|
|
|
half DCub = DSqd * d.x;
|
|
|
|
half DaSqd = d.y * d.y;
|
|
|
|
half DaCub = DaSqd * d.y;
|
|
|
|
return (((DaSqd * (s.x - d.x * ((3.0h * s.y - 6.0h * s.x) - 1.0h)) + ((12.0h * d.y) * DSqd) * (s.y - 2.0h * s.x)) - (16.0h * DCub) * (s.y - 2.0h * s.x)) - DaCub * s.x) / DaSqd;
|
2020-09-25 17:35:58 +00:00
|
|
|
} else {
|
2021-10-30 02:34:51 +00:00
|
|
|
return ((d.x * ((s.y - 2.0h * s.x) + 1.0h) + s.x) - sqrt(d.y * d.x) * (s.y - 2.0h * s.x)) - d.y * s.x;
|
2020-09-25 17:35:58 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-15 18:58:57 +00:00
|
|
|
fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
|
2021-01-19 18:07:55 +00:00
|
|
|
Outputs _out;
|
2021-01-22 03:24:28 +00:00
|
|
|
(void)_out;
|
2021-10-30 02:34:51 +00:00
|
|
|
_out.sk_FragColor = _uniforms.dst.w == 0.0h ? _uniforms.src : half4(_soft_light_component_hh2h2(_uniforms.src.xw, _uniforms.dst.xw), _soft_light_component_hh2h2(_uniforms.src.yw, _uniforms.dst.yw), _soft_light_component_hh2h2(_uniforms.src.zw, _uniforms.dst.zw), _uniforms.src.w + (1.0h - _uniforms.src.w) * _uniforms.dst.w);
|
2021-01-19 18:07:55 +00:00
|
|
|
return _out;
|
2020-09-25 17:35:58 +00:00
|
|
|
}
|