Instantly share code, notes, and snippets.
Last active
November 23, 2022 21:11
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save jonahwilliams/2194d45d671991f3eb0b030bf27a9068 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <metal_stdlib> | |
#include <simd/simd.h> | |
using namespace metal; | |
struct BlendInfo | |
{ | |
float dst_input_alpha; | |
float dst_y_coord_scale; | |
float src_y_coord_scale; | |
float color_factor; | |
float4 color; | |
}; | |
struct advanced_blend_saturation_fragment_main_out | |
{ | |
float4 frag_color [[color(0)]]; | |
}; | |
struct advanced_blend_saturation_fragment_main_in | |
{ | |
float2 v_dst_texture_coords [[user(locn0)]]; | |
float2 v_src_texture_coords [[user(locn1)]]; | |
}; | |
fragment advanced_blend_saturation_fragment_main_out advanced_blend_saturation_fragment_main(advanced_blend_saturation_fragment_main_in in [[stage_in]], constant BlendInfo& blend_info [[buffer(0)]], texture2d<float> texture_sampler_dst [[texture(0)]], texture2d<float> texture_sampler_src [[texture(1)]], sampler texture_sampler_dstSmplr [[sampler(0)]], sampler texture_sampler_srcSmplr [[sampler(1)]]) | |
{ | |
advanced_blend_saturation_fragment_main_out out = {}; | |
float2 _436 = in.v_dst_texture_coords; | |
float4 _1147; | |
do | |
{ | |
bool _546 = _436.x < 0.0; | |
bool _553; | |
if (!_546) | |
{ | |
_553 = _436.x >= 1.0; | |
} | |
else | |
{ | |
_553 = _546; | |
} | |
bool _574; | |
if (!_553) | |
{ | |
bool _563 = _436.y < 0.0; | |
bool _570; | |
if (!_563) | |
{ | |
_570 = _436.y >= 1.0; | |
} | |
else | |
{ | |
_570 = _563; | |
} | |
_574 = _570; | |
} | |
else | |
{ | |
_574 = _553; | |
} | |
if (_574) | |
{ | |
_1147 = float4(0.0); | |
break; | |
} | |
float2 _1146; | |
if (blend_info.dst_y_coord_scale < 0.0) | |
{ | |
float2 _1095 = _436; | |
_1095.y = 1.0 - _436.y; | |
_1146 = _1095; | |
} | |
else | |
{ | |
_1146 = _436; | |
} | |
_1147 = texture_sampler_dst.sample(texture_sampler_dstSmplr, _1146); | |
break; | |
} while(false); | |
float4 _446 = _1147 * blend_info.dst_input_alpha; | |
float4 _1148; | |
do | |
{ | |
float _687 = _446.w; | |
if (_687 == 0.0) | |
{ | |
_1148 = float4(0.0); | |
break; | |
} | |
_1148 = float4(_446.xyz / float3(_687), _687); | |
break; | |
} while(false); | |
float4 _1158; | |
if (blend_info.color_factor > 0.0) | |
{ | |
_1158 = blend_info.color; | |
} | |
else | |
{ | |
float2 _468 = in.v_src_texture_coords; | |
float4 _1156; | |
do | |
{ | |
bool _731 = _468.x < 0.0; | |
bool _738; | |
if (!_731) | |
{ | |
_738 = _468.x >= 1.0; | |
} | |
else | |
{ | |
_738 = _731; | |
} | |
bool _759; | |
if (!_738) | |
{ | |
bool _748 = _468.y < 0.0; | |
bool _755; | |
if (!_748) | |
{ | |
_755 = _468.y >= 1.0; | |
} | |
else | |
{ | |
_755 = _748; | |
} | |
_759 = _755; | |
} | |
else | |
{ | |
_759 = _738; | |
} | |
if (_759) | |
{ | |
_1156 = float4(0.0); | |
break; | |
} | |
float2 _1155; | |
if (blend_info.src_y_coord_scale < 0.0) | |
{ | |
float2 _1107 = _468; | |
_1107.y = 1.0 - _468.y; | |
_1155 = _1107; | |
} | |
else | |
{ | |
_1155 = _468; | |
} | |
_1156 = texture_sampler_src.sample(texture_sampler_srcSmplr, _1155); | |
break; | |
} while(false); | |
float4 _1157; | |
do | |
{ | |
if (_1156.w == 0.0) | |
{ | |
_1157 = float4(0.0); | |
break; | |
} | |
_1157 = float4(_1156.xyz / float3(_1156.w), _1156.w); | |
break; | |
} while(false); | |
_1158 = _1157; | |
} | |
half3 _480 = half3(_1148.xyz); | |
half3 _483 = half3(_1158.xyz); | |
half _915 = _483.x; | |
half _917 = _483.y; | |
half _920 = _483.z; | |
half _937 = _480.x; | |
half _939 = _480.y; | |
half _942 = _480.z; | |
half _943 = min(min(_937, _939), _942); | |
half _951 = max(max(_937, _939), _942); | |
half3 _1159; | |
if (_943 < _951) | |
{ | |
_1159 = ((_480 - half3(_943)) * (max(max(_915, _917), _920) - min(min(_915, _917), _920))) / half3(_951 - _943); | |
} | |
else | |
{ | |
_1159 = half3(half(0.0)); | |
} | |
half3 _995 = _1159 + half3(fma(_942, half(0.1099853515625), fma(_937, half(0.2998046875), _939 * half(0.58984375))) - fma(_1159.z, half(0.1099853515625), fma(_1159.x, half(0.2998046875), _1159.y * half(0.58984375)))); | |
half _1077 = _995.x; | |
half _1080 = _995.y; | |
half _1084 = _995.z; | |
half _1086 = fma(_1084, half(0.1099853515625), fma(_1077, half(0.2998046875), _1080 * half(0.58984375))); | |
half _1025 = min(min(_1077, _1080), _1084); | |
half _1033 = max(max(_1077, _1080), _1084); | |
half3 _1160; | |
if (_1025 < half(0.0)) | |
{ | |
half3 _1040 = half3(_1086); | |
_1160 = _1040 + (((_995 - _1040) * _1086) / half3((_1086 - _1025) + half(9.5367431640625e-07))); | |
} | |
else | |
{ | |
_1160 = _995; | |
} | |
half3 _1161; | |
if (_1033 > half(1.0)) | |
{ | |
half3 _1059 = half3(_1086); | |
_1161 = _1059 + (((_1160 - _1059) * (half(1.0) - _1086)) / half3((_1033 - _1086) + half(9.5367431640625e-07))); | |
} | |
else | |
{ | |
_1161 = _1160; | |
} | |
out.frag_color = mix(_446, float4(float3(_1161), 1.0) * _1148.w, float4(_1158.w)); | |
return out; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <metal_stdlib> | |
#include <simd/simd.h> | |
using namespace metal; | |
struct BlendInfo | |
{ | |
float dst_input_alpha; | |
float dst_y_coord_scale; | |
float src_y_coord_scale; | |
float color_factor; | |
float4 color; | |
}; | |
struct advanced_blend_saturation_fragment_main_out | |
{ | |
float4 frag_color [[color(0)]]; | |
}; | |
struct advanced_blend_saturation_fragment_main_in | |
{ | |
float2 v_dst_texture_coords [[user(locn0)]]; | |
float2 v_src_texture_coords [[user(locn1)]]; | |
}; | |
fragment advanced_blend_saturation_fragment_main_out advanced_blend_saturation_fragment_main(advanced_blend_saturation_fragment_main_in in [[stage_in]], constant BlendInfo& blend_info [[buffer(0)]], texture2d<float> texture_sampler_dst [[texture(0)]], texture2d<float> texture_sampler_src [[texture(1)]], sampler texture_sampler_dstSmplr [[sampler(0)]], sampler texture_sampler_srcSmplr [[sampler(1)]]) | |
{ | |
advanced_blend_saturation_fragment_main_out out = {}; | |
float2 _431 = in.v_dst_texture_coords; | |
float4 _1138; | |
do | |
{ | |
bool _537 = _431.x < 0.0; | |
bool _544; | |
if (!_537) | |
{ | |
_544 = _431.x >= 1.0; | |
} | |
else | |
{ | |
_544 = _537; | |
} | |
bool _565; | |
if (!_544) | |
{ | |
bool _554 = _431.y < 0.0; | |
bool _561; | |
if (!_554) | |
{ | |
_561 = _431.y >= 1.0; | |
} | |
else | |
{ | |
_561 = _554; | |
} | |
_565 = _561; | |
} | |
else | |
{ | |
_565 = _544; | |
} | |
if (_565) | |
{ | |
_1138 = float4(0.0); | |
break; | |
} | |
float2 _1137; | |
if (blend_info.dst_y_coord_scale < 0.0) | |
{ | |
float2 _1086 = _431; | |
_1086.y = 1.0 - _431.y; | |
_1137 = _1086; | |
} | |
else | |
{ | |
_1137 = _431; | |
} | |
_1138 = texture_sampler_dst.sample(texture_sampler_dstSmplr, _1137); | |
break; | |
} while(false); | |
float4 _441 = _1138 * blend_info.dst_input_alpha; | |
float4 _1139; | |
do | |
{ | |
float _678 = _441.w; | |
if (_678 == 0.0) | |
{ | |
_1139 = float4(0.0); | |
break; | |
} | |
_1139 = float4(_441.xyz / float3(_678), _678); | |
break; | |
} while(false); | |
float4 _1149; | |
if (blend_info.color_factor > 0.0) | |
{ | |
_1149 = blend_info.color; | |
} | |
else | |
{ | |
float2 _463 = in.v_src_texture_coords; | |
float4 _1147; | |
do | |
{ | |
bool _722 = _463.x < 0.0; | |
bool _729; | |
if (!_722) | |
{ | |
_729 = _463.x >= 1.0; | |
} | |
else | |
{ | |
_729 = _722; | |
} | |
bool _750; | |
if (!_729) | |
{ | |
bool _739 = _463.y < 0.0; | |
bool _746; | |
if (!_739) | |
{ | |
_746 = _463.y >= 1.0; | |
} | |
else | |
{ | |
_746 = _739; | |
} | |
_750 = _746; | |
} | |
else | |
{ | |
_750 = _729; | |
} | |
if (_750) | |
{ | |
_1147 = float4(0.0); | |
break; | |
} | |
float2 _1146; | |
if (blend_info.src_y_coord_scale < 0.0) | |
{ | |
float2 _1098 = _463; | |
_1098.y = 1.0 - _463.y; | |
_1146 = _1098; | |
} | |
else | |
{ | |
_1146 = _463; | |
} | |
_1147 = texture_sampler_src.sample(texture_sampler_srcSmplr, _1146); | |
break; | |
} while(false); | |
float4 _1148; | |
do | |
{ | |
if (_1147.w == 0.0) | |
{ | |
_1148 = float4(0.0); | |
break; | |
} | |
_1148 = float4(_1147.xyz / float3(_1147.w), _1147.w); | |
break; | |
} while(false); | |
_1149 = _1148; | |
} | |
float _934 = fast::min(fast::min(_1139.x, _1139.y), _1139.z); | |
float _942 = fast::max(fast::max(_1139.x, _1139.y), _1139.z); | |
float3 _1150; | |
if (_934 < _942) | |
{ | |
_1150 = ((_1139.xyz - float3(_934)) * (fast::max(fast::max(_1149.x, _1149.y), _1149.z) - fast::min(fast::min(_1149.x, _1149.y), _1149.z))) / float3(_942 - _934); | |
} | |
else | |
{ | |
_1150 = float3(0.0); | |
} | |
float3 _986 = _1150 + float3(fma(_1139.z, 0.10999999940395355224609375, fma(_1139.x, 0.300000011920928955078125, _1139.y * 0.589999973773956298828125)) - fma(_1150.z, 0.10999999940395355224609375, fma(_1150.x, 0.300000011920928955078125, _1150.y * 0.589999973773956298828125))); | |
float _1068 = _986.x; | |
float _1071 = _986.y; | |
float _1075 = _986.z; | |
float _1077 = fma(_1075, 0.10999999940395355224609375, fma(_1068, 0.300000011920928955078125, _1071 * 0.589999973773956298828125)); | |
float _1016 = fast::min(fast::min(_1068, _1071), _1075); | |
float _1024 = fast::max(fast::max(_1068, _1071), _1075); | |
float3 _1151; | |
if (_1016 < 0.0) | |
{ | |
float3 _1031 = float3(_1077); | |
_1151 = _1031 + (((_986 - _1031) * _1077) / float3((_1077 - _1016) + 9.9999999747524270787835121154785e-07)); | |
} | |
else | |
{ | |
_1151 = _986; | |
} | |
float3 _1152; | |
if (_1024 > 1.0) | |
{ | |
float3 _1050 = float3(_1077); | |
_1152 = _1050 + (((_1151 - _1050) * (1.0 - _1077)) / float3((_1024 - _1077) + 9.9999999747524270787835121154785e-07)); | |
} | |
else | |
{ | |
_1152 = _1151; | |
} | |
out.frag_color = mix(_441, float4(_1152, 1.0) * _1139.w, float4(_1149.w)); | |
return out; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment