// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

//!DESC RAVU-Lite-AR (step1, r3)
//!HOOK LUMA
//!BIND HOOKED
//!BIND ravu_lite_lut3
//!SAVE ravu_lite_int
//!WHEN HOOKED.w OUTPUT.w / 0.833333 < HOOKED.h OUTPUT.h / 0.833333 < *
//!COMPONENTS 4
vec4 hook() {
vec4 gather0 = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(-2, -2), 0);
vec4 gather2 = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(-2, 0), 0);
vec2 gather4 = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(-2, 2), 0).wz;
vec4 gather10 = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(0, -2), 0);
vec4 gather12 = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(0, 0), 0);
vec2 gather14 = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(0, 2), 0).wz;
vec2 gather20 = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(2, -2), 0).wx;
vec2 gather22 = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(2, 0), 0).wx;
float luma24 = HOOKED_texOff(vec2(2.0, 2.0)).x;
vec3 abd = vec3(0.0);
float gx, gy;
gx = (gather10.x-gather0.x)/2.0;
gy = (gather2.z-gather0.z)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.1018680644198163;
gx = (gather12.w-gather2.w)/2.0;
gy = (gather2.y-gather0.y)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.11543163961422666;
gx = (gather12.x-gather2.x)/2.0;
gy = (gather4.y-gather2.z)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.1018680644198163;
gx = (gather10.y-gather0.y)/2.0;
gy = (gather12.w-gather10.w)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.11543163961422666;
gx = (gather12.z-gather2.z)/2.0;
gy = (gather12.x-gather10.x)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.13080118386382833;
gx = (gather12.y-gather2.y)/2.0;
gy = (gather14.x-gather12.w)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.11543163961422666;
gx = (gather20.y-gather10.x)/2.0;
gy = (gather12.z-gather10.z)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.1018680644198163;
gx = (gather22.x-gather12.w)/2.0;
gy = (gather12.y-gather10.y)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.11543163961422666;
gx = (gather22.y-gather12.x)/2.0;
gy = (gather14.y-gather12.z)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.1018680644198163;
float a = abd.x, b = abd.y, d = abd.z;
float T = a + d, D = a * d - b * b;
float delta = sqrt(max(T * T / 4.0 - D, 0.0));
float L1 = T / 2.0 + delta, L2 = T / 2.0 - delta;
float sqrtL1 = sqrt(L1), sqrtL2 = sqrt(L2);
float theta = mix(mod(atan(L1 - a, b) + 3.141592653589793, 3.141592653589793), 0.0, abs(b) < 1.192092896e-7);
float lambda = sqrtL1;
float mu = mix((sqrtL1 - sqrtL2) / (sqrtL1 + sqrtL2), 0.0, sqrtL1 + sqrtL2 < 1.192092896e-7);
float angle = floor(theta * 24.0 / 3.141592653589793);
float strength = mix(mix(0.0, 1.0, lambda >= 0.004), mix(2.0, 3.0, lambda >= 0.05), lambda >= 0.016);
float coherence = mix(mix(0.0, 1.0, mu >= 0.25), 2.0, mu >= 0.5);
float coord_y = ((angle * 4.0 + strength) * 3.0 + coherence + 0.5) / 288.0;
vec4 res = vec4(0.0), w;
vec4 lo = vec4(0.0), hi = vec4(0.0), lo2 = vec4(0.0), hi2 = vec4(0.0), wg, cg4, cg4_1;
w = texture(ravu_lite_lut3, vec2(0.038461538461538464, coord_y));
res += gather0.w * w + luma24 * w.wzyx;
w = texture(ravu_lite_lut3, vec2(0.11538461538461539, coord_y));
res += gather0.x * w + gather22.y * w.wzyx;
w = texture(ravu_lite_lut3, vec2(0.19230769230769232, coord_y));
wg = max(vec4(0.0), w);
res += gather2.w * w + gather22.x * w.wzyx;
cg4 = vec4(0.1 + gather2.w, 1.1 - gather2.w, 0.1 + gather22.x, 1.1 - gather22.x);
cg4_1 = cg4;
cg4 *= cg4;cg4 *= cg4;cg4 *= cg4;cg4 *= cg4;cg4 *= cg4;
hi += cg4.x * wg + cg4.z * wg.wzyx;
lo += cg4.y * wg + cg4.w * wg.wzyx;
cg4 *= cg4_1;
hi2 += cg4.x * wg + cg4.z * wg.wzyx;
lo2 += cg4.y * wg + cg4.w * wg.wzyx;
w = texture(ravu_lite_lut3, vec2(0.2692307692307692, coord_y));
res += gather2.x * w + gather20.y * w.wzyx;
w = texture(ravu_lite_lut3, vec2(0.34615384615384615, coord_y));
res += gather4.x * w + gather20.x * w.wzyx;
w = texture(ravu_lite_lut3, vec2(0.4230769230769231, coord_y));
res += gather0.z * w + gather14.y * w.wzyx;
w = texture(ravu_lite_lut3, vec2(0.5, coord_y));
wg = max(vec4(0.0), w);
res += gather0.y * w + gather12.y * w.wzyx;
cg4 = vec4(0.1 + gather0.y, 1.1 - gather0.y, 0.1 + gather12.y, 1.1 - gather12.y);
cg4_1 = cg4;
cg4 *= cg4;cg4 *= cg4;cg4 *= cg4;cg4 *= cg4;cg4 *= cg4;
hi += cg4.x * wg + cg4.z * wg.wzyx;
lo += cg4.y * wg + cg4.w * wg.wzyx;
cg4 *= cg4_1;
hi2 += cg4.x * wg + cg4.z * wg.wzyx;
lo2 += cg4.y * wg + cg4.w * wg.wzyx;
w = texture(ravu_lite_lut3, vec2(0.5769230769230769, coord_y));
wg = max(vec4(0.0), w);
res += gather2.z * w + gather12.z * w.wzyx;
cg4 = vec4(0.1 + gather2.z, 1.1 - gather2.z, 0.1 + gather12.z, 1.1 - gather12.z);
cg4_1 = cg4;
cg4 *= cg4;cg4 *= cg4;cg4 *= cg4;cg4 *= cg4;cg4 *= cg4;
hi += cg4.x * wg + cg4.z * wg.wzyx;
lo += cg4.y * wg + cg4.w * wg.wzyx;
cg4 *= cg4_1;
hi2 += cg4.x * wg + cg4.z * wg.wzyx;
lo2 += cg4.y * wg + cg4.w * wg.wzyx;
w = texture(ravu_lite_lut3, vec2(0.6538461538461539, coord_y));
wg = max(vec4(0.0), w);
res += gather2.y * w + gather10.y * w.wzyx;
cg4 = vec4(0.1 + gather2.y, 1.1 - gather2.y, 0.1 + gather10.y, 1.1 - gather10.y);
cg4_1 = cg4;
cg4 *= cg4;cg4 *= cg4;cg4 *= cg4;cg4 *= cg4;cg4 *= cg4;
hi += cg4.x * wg + cg4.z * wg.wzyx;
lo += cg4.y * wg + cg4.w * wg.wzyx;
cg4 *= cg4_1;
hi2 += cg4.x * wg + cg4.z * wg.wzyx;
lo2 += cg4.y * wg + cg4.w * wg.wzyx;
w = texture(ravu_lite_lut3, vec2(0.7307692307692307, coord_y));
res += gather4.y * w + gather10.z * w.wzyx;
w = texture(ravu_lite_lut3, vec2(0.8076923076923077, coord_y));
wg = max(vec4(0.0), w);
res += gather10.w * w + gather14.x * w.wzyx;
cg4 = vec4(0.1 + gather10.w, 1.1 - gather10.w, 0.1 + gather14.x, 1.1 - gather14.x);
cg4_1 = cg4;
cg4 *= cg4;cg4 *= cg4;cg4 *= cg4;cg4 *= cg4;cg4 *= cg4;
hi += cg4.x * wg + cg4.z * wg.wzyx;
lo += cg4.y * wg + cg4.w * wg.wzyx;
cg4 *= cg4_1;
hi2 += cg4.x * wg + cg4.z * wg.wzyx;
lo2 += cg4.y * wg + cg4.w * wg.wzyx;
w = texture(ravu_lite_lut3, vec2(0.8846153846153846, coord_y));
wg = max(vec4(0.0), w);
res += gather10.x * w + gather12.x * w.wzyx;
cg4 = vec4(0.1 + gather10.x, 1.1 - gather10.x, 0.1 + gather12.x, 1.1 - gather12.x);
cg4_1 = cg4;
cg4 *= cg4;cg4 *= cg4;cg4 *= cg4;cg4 *= cg4;cg4 *= cg4;
hi += cg4.x * wg + cg4.z * wg.wzyx;
lo += cg4.y * wg + cg4.w * wg.wzyx;
cg4 *= cg4_1;
hi2 += cg4.x * wg + cg4.z * wg.wzyx;
lo2 += cg4.y * wg + cg4.w * wg.wzyx;
w = texture(ravu_lite_lut3, vec2(0.9615384615384616, coord_y));
wg = max(vec4(0.0), w);
res += gather12.w * w;
vec2 cg2 = vec2(0.1 + gather12.w, 1.1 - gather12.w);
vec2 cg2_1 = cg2;
cg2 *= cg2;cg2 *= cg2;cg2 *= cg2;cg2 *= cg2;cg2 *= cg2;
hi += cg2.x * wg;
lo += cg2.y * wg;
cg2 *= cg2_1;
hi2 += cg2.x * wg;
lo2 += cg2.y * wg;
lo = 1.1 - lo2 / lo;
hi = hi2 / hi - 0.1;
res = mix(res, clamp(res, lo, hi), 0.800000);
return res;
}
//!DESC RAVU-Lite-AR (step2, r3)
//!HOOK LUMA
//!BIND HOOKED
//!BIND ravu_lite_int
//!WIDTH 2 HOOKED.w *
//!HEIGHT 2 HOOKED.h *
//!WHEN HOOKED.w OUTPUT.w / 0.833333 < HOOKED.h OUTPUT.h / 0.833333 < *
//!COMPONENTS 1
vec4 hook() {
    vec2 dir = fract(HOOKED_pos * HOOKED_size) - 0.5;
    int idx = int(dir.x > 0.0) * 2 + int(dir.y > 0.0);
    return vec4(ravu_lite_int_texOff(-dir)[idx], 0.0, 0.0, 0.0);
}
//!TEXTURE ravu_lite_lut3
//!SIZE 13 288
//!FORMAT rgba16f
//!FILTER NEAREST
[encoded data, 119808 characters]
