// 
// 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, r4)
//!HOOK LUMA
//!BIND HOOKED
//!BIND ravu_lite_lut4
//!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(-3, -3), 0);
vec4 gather2 = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(-3, -1), 0);
vec4 gather4 = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(-3, 1), 0);
vec2 gather6 = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(-3, 3), 0).wz;
vec4 gather14 = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(-1, -3), 0);
vec4 gather16 = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(-1, -1), 0);
vec4 gather18 = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(-1, 1), 0);
vec2 gather20 = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(-1, 3), 0).wz;
vec4 gather28 = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(1, -3), 0);
vec4 gather30 = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(1, -1), 0);
vec4 gather32 = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(1, 1), 0);
vec2 gather34 = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(1, 3), 0).wz;
vec2 gather42 = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(3, -3), 0).wx;
vec2 gather44 = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(3, -1), 0).wx;
vec2 gather46 = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(3, 1), 0).wx;
float luma48 = HOOKED_texOff(vec2(3.0, 3.0)).x;
vec3 abd = vec3(0.0);
float gx, gy;
gx = (gather14.x-gather0.x)/2.0;
gy = (gather2.z-gather0.z)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.02324683987829437;
gx = (gather16.w-gather2.w)/2.0;
gy = (gather2.y-gather0.y)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.033823952439922346;
gx = (gather16.x-gather2.x)/2.0;
gy = (gather4.z-gather2.z)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.038327559383903906;
gx = (gather18.w-gather4.w)/2.0;
gy = (gather4.y-gather2.y)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.033823952439922346;
gx = (gather18.x-gather4.x)/2.0;
gy = (gather6.y-gather4.z)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.02324683987829437;
gx = (gather14.y-gather0.y)/2.0;
gy = (gather16.w-gather14.w)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.033823952439922346;
gx = (gather16.z-gather2.z)/2.0;
gy = (gather16.x-gather14.x)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.04921356040854137;
gx = (gather16.y-gather2.y)/2.0;
gy = (gather18.w-gather16.w)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.055766269846849466;
gx = (gather18.z-gather4.z)/2.0;
gy = (gather18.x-gather16.x)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.04921356040854137;
gx = (gather18.y-gather4.y)/2.0;
gy = (gather20.x-gather18.w)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.033823952439922346;
gx = (gather28.x-gather14.x)/2.0;
gy = (gather16.z-gather14.z)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.038327559383903906;
gx = (gather30.w-gather16.w)/2.0;
gy = (gather16.y-gather14.y)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.055766269846849466;
gx = (gather30.x-gather16.x)/2.0;
gy = (gather18.z-gather16.z)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.06319146241026467;
gx = (gather32.w-gather18.w)/2.0;
gy = (gather18.y-gather16.y)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.055766269846849466;
gx = (gather32.x-gather18.x)/2.0;
gy = (gather20.y-gather18.z)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.038327559383903906;
gx = (gather28.y-gather14.y)/2.0;
gy = (gather30.w-gather28.w)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.033823952439922346;
gx = (gather30.z-gather16.z)/2.0;
gy = (gather30.x-gather28.x)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.04921356040854137;
gx = (gather30.y-gather16.y)/2.0;
gy = (gather32.w-gather30.w)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.055766269846849466;
gx = (gather32.z-gather18.z)/2.0;
gy = (gather32.x-gather30.x)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.04921356040854137;
gx = (gather32.y-gather18.y)/2.0;
gy = (gather34.x-gather32.w)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.033823952439922346;
gx = (gather42.y-gather28.x)/2.0;
gy = (gather30.z-gather28.z)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.02324683987829437;
gx = (gather44.x-gather30.w)/2.0;
gy = (gather30.y-gather28.y)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.033823952439922346;
gx = (gather44.y-gather30.x)/2.0;
gy = (gather32.z-gather30.z)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.038327559383903906;
gx = (gather46.x-gather32.w)/2.0;
gy = (gather32.y-gather30.y)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.033823952439922346;
gx = (gather46.y-gather32.x)/2.0;
gy = (gather34.y-gather32.z)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.02324683987829437;
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_lut4, vec2(0.02, coord_y));
res += gather0.w * w + luma48 * w.wzyx;
w = texture(ravu_lite_lut4, vec2(0.06, coord_y));
res += gather0.x * w + gather46.y * w.wzyx;
w = texture(ravu_lite_lut4, vec2(0.1, coord_y));
res += gather2.w * w + gather46.x * w.wzyx;
w = texture(ravu_lite_lut4, vec2(0.14, coord_y));
res += gather2.x * w + gather44.y * w.wzyx;
w = texture(ravu_lite_lut4, vec2(0.18, coord_y));
res += gather4.w * w + gather44.x * w.wzyx;
w = texture(ravu_lite_lut4, vec2(0.22, coord_y));
res += gather4.x * w + gather42.y * w.wzyx;
w = texture(ravu_lite_lut4, vec2(0.26, coord_y));
res += gather6.x * w + gather42.x * w.wzyx;
w = texture(ravu_lite_lut4, vec2(0.3, coord_y));
res += gather0.z * w + gather34.y * w.wzyx;
w = texture(ravu_lite_lut4, vec2(0.34, coord_y));
res += gather0.y * w + gather32.y * w.wzyx;
w = texture(ravu_lite_lut4, vec2(0.38, coord_y));
res += gather2.z * w + gather32.z * w.wzyx;
w = texture(ravu_lite_lut4, vec2(0.42, coord_y));
wg = max(vec4(0.0), w);
res += gather2.y * w + gather30.y * w.wzyx;
cg4 = vec4(0.1 + gather2.y, 1.1 - gather2.y, 0.1 + gather30.y, 1.1 - gather30.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_lut4, vec2(0.46, coord_y));
res += gather4.z * w + gather30.z * w.wzyx;
w = texture(ravu_lite_lut4, vec2(0.5, coord_y));
res += gather4.y * w + gather28.y * w.wzyx;
w = texture(ravu_lite_lut4, vec2(0.54, coord_y));
res += gather6.y * w + gather28.z * w.wzyx;
w = texture(ravu_lite_lut4, vec2(0.58, coord_y));
res += gather14.w * w + gather34.x * w.wzyx;
w = texture(ravu_lite_lut4, vec2(0.62, coord_y));
res += gather14.x * w + gather32.x * w.wzyx;
w = texture(ravu_lite_lut4, vec2(0.66, coord_y));
wg = max(vec4(0.0), w);
res += gather16.w * w + gather32.w * w.wzyx;
cg4 = vec4(0.1 + gather16.w, 1.1 - gather16.w, 0.1 + gather32.w, 1.1 - gather32.w);
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_lut4, vec2(0.7, coord_y));
wg = max(vec4(0.0), w);
res += gather16.x * w + gather30.x * w.wzyx;
cg4 = vec4(0.1 + gather16.x, 1.1 - gather16.x, 0.1 + gather30.x, 1.1 - gather30.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_lut4, vec2(0.74, coord_y));
wg = max(vec4(0.0), w);
res += gather18.w * w + gather30.w * w.wzyx;
cg4 = vec4(0.1 + gather18.w, 1.1 - gather18.w, 0.1 + gather30.w, 1.1 - gather30.w);
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_lut4, vec2(0.78, coord_y));
res += gather18.x * w + gather28.x * w.wzyx;
w = texture(ravu_lite_lut4, vec2(0.82, coord_y));
res += gather20.x * w + gather28.w * w.wzyx;
w = texture(ravu_lite_lut4, vec2(0.86, coord_y));
res += gather14.z * w + gather20.y * w.wzyx;
w = texture(ravu_lite_lut4, vec2(0.9, coord_y));
wg = max(vec4(0.0), w);
res += gather14.y * w + gather18.y * w.wzyx;
cg4 = vec4(0.1 + gather14.y, 1.1 - gather14.y, 0.1 + gather18.y, 1.1 - gather18.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_lut4, vec2(0.94, coord_y));
wg = max(vec4(0.0), w);
res += gather16.z * w + gather18.z * w.wzyx;
cg4 = vec4(0.1 + gather16.z, 1.1 - gather16.z, 0.1 + gather18.z, 1.1 - gather18.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_lut4, vec2(0.98, coord_y));
wg = max(vec4(0.0), w);
res += gather16.y * w;
vec2 cg2 = vec2(0.1 + gather16.y, 1.1 - gather16.y);
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, r4)
//!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_lut4
//!SIZE 25 288
//!FORMAT rgba16f
//!FILTER NEAREST
[encoded data, 230400 characters]
