// 
// 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, r2)
//!HOOK LUMA
//!BIND HOOKED
//!BIND ravu_lite_lut2
//!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(-1, -1), 0);
vec2 gather2 = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(-1, 1), 0).wz;
vec2 gather6 = HOOKED_mul * textureGatherOffset(HOOKED_raw, HOOKED_pos, ivec2(1, -1), 0).wx;
float luma8 = HOOKED_texOff(vec2(1.0, 1.0)).x;
vec3 abd = vec3(0.0);
float gx, gy;
gx = (gather0.z-gather0.w);
gy = (gather0.x-gather0.w);
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.1018680644198163;
gx = (gather0.y-gather0.x);
gy = (gather2.x-gather0.w)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.11543163961422666;
gx = (gather2.y-gather2.x);
gy = (gather2.x-gather0.x);
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.1018680644198163;
gx = (gather6.x-gather0.w)/2.0;
gy = (gather0.y-gather0.z);
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.11543163961422666;
gx = (gather6.y-gather0.x)/2.0;
gy = (gather2.y-gather0.z)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.13080118386382833;
gx = (luma8-gather2.x)/2.0;
gy = (gather2.y-gather0.y);
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.11543163961422666;
gx = (gather6.x-gather0.z);
gy = (gather6.y-gather6.x);
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.1018680644198163;
gx = (gather6.y-gather0.y);
gy = (luma8-gather6.x)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.11543163961422666;
gx = (luma8-gather2.y);
gy = (luma8-gather6.y);
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_lut2, vec2(0.1, coord_y));
wg = max(vec4(0.0), w);
res += gather0.w * w + luma8 * w.wzyx;
cg4 = vec4(0.1 + gather0.w, 1.1 - gather0.w, 0.1 + luma8, 1.1 - luma8);
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_lut2, vec2(0.3, coord_y));
wg = max(vec4(0.0), w);
res += gather0.x * w + gather6.y * w.wzyx;
cg4 = vec4(0.1 + gather0.x, 1.1 - gather0.x, 0.1 + gather6.y, 1.1 - gather6.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_lut2, vec2(0.5, coord_y));
wg = max(vec4(0.0), w);
res += gather2.x * w + gather6.x * w.wzyx;
cg4 = vec4(0.1 + gather2.x, 1.1 - gather2.x, 0.1 + gather6.x, 1.1 - gather6.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_lut2, vec2(0.7, coord_y));
wg = max(vec4(0.0), w);
res += gather0.z * w + gather2.y * w.wzyx;
cg4 = vec4(0.1 + gather0.z, 1.1 - gather0.z, 0.1 + gather2.y, 1.1 - gather2.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_lut2, vec2(0.9, coord_y));
wg = max(vec4(0.0), w);
res += gather0.y * w;
vec2 cg2 = vec2(0.1 + gather0.y, 1.1 - gather0.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, r2)
//!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_lut2
//!SIZE 5 288
//!FORMAT rgba16f
//!FILTER NEAREST
[encoded data, 46080 characters]
