// 
// 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() {
float luma0 = HOOKED_texOff(vec2(-2.0, -2.0)).x;
float luma1 = HOOKED_texOff(vec2(-2.0, -1.0)).x;
float luma2 = HOOKED_texOff(vec2(-2.0, 0.0)).x;
float luma3 = HOOKED_texOff(vec2(-2.0, 1.0)).x;
float luma4 = HOOKED_texOff(vec2(-2.0, 2.0)).x;
float luma5 = HOOKED_texOff(vec2(-1.0, -2.0)).x;
float luma6 = HOOKED_texOff(vec2(-1.0, -1.0)).x;
float luma7 = HOOKED_texOff(vec2(-1.0, 0.0)).x;
float luma8 = HOOKED_texOff(vec2(-1.0, 1.0)).x;
float luma9 = HOOKED_texOff(vec2(-1.0, 2.0)).x;
float luma10 = HOOKED_texOff(vec2(0.0, -2.0)).x;
float luma11 = HOOKED_texOff(vec2(0.0, -1.0)).x;
float luma12 = HOOKED_texOff(vec2(0.0, 0.0)).x;
float luma13 = HOOKED_texOff(vec2(0.0, 1.0)).x;
float luma14 = HOOKED_texOff(vec2(0.0, 2.0)).x;
float luma15 = HOOKED_texOff(vec2(1.0, -2.0)).x;
float luma16 = HOOKED_texOff(vec2(1.0, -1.0)).x;
float luma17 = HOOKED_texOff(vec2(1.0, 0.0)).x;
float luma18 = HOOKED_texOff(vec2(1.0, 1.0)).x;
float luma19 = HOOKED_texOff(vec2(1.0, 2.0)).x;
float luma20 = HOOKED_texOff(vec2(2.0, -2.0)).x;
float luma21 = HOOKED_texOff(vec2(2.0, -1.0)).x;
float luma22 = HOOKED_texOff(vec2(2.0, 0.0)).x;
float luma23 = HOOKED_texOff(vec2(2.0, 1.0)).x;
float luma24 = HOOKED_texOff(vec2(2.0, 2.0)).x;
vec3 abd = vec3(0.0);
float gx, gy;
gx = (luma11-luma1)/2.0;
gy = (luma7-luma5)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.1018680644198163;
gx = (luma12-luma2)/2.0;
gy = (luma8-luma6)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.11543163961422666;
gx = (luma13-luma3)/2.0;
gy = (luma9-luma7)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.1018680644198163;
gx = (luma16-luma6)/2.0;
gy = (luma12-luma10)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.11543163961422666;
gx = (luma17-luma7)/2.0;
gy = (luma13-luma11)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.13080118386382833;
gx = (luma18-luma8)/2.0;
gy = (luma14-luma12)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.11543163961422666;
gx = (luma21-luma11)/2.0;
gy = (luma17-luma15)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.1018680644198163;
gx = (luma22-luma12)/2.0;
gy = (luma18-luma16)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.11543163961422666;
gx = (luma23-luma13)/2.0;
gy = (luma19-luma17)/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 += luma0 * w + luma24 * w.wzyx;
w = texture(ravu_lite_lut3, vec2(0.11538461538461539, coord_y));
res += luma1 * w + luma23 * w.wzyx;
w = texture(ravu_lite_lut3, vec2(0.19230769230769232, coord_y));
wg = max(vec4(0.0), w);
res += luma2 * w + luma22 * w.wzyx;
cg4 = vec4(0.1 + luma2, 1.1 - luma2, 0.1 + luma22, 1.1 - luma22);
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 += luma3 * w + luma21 * w.wzyx;
w = texture(ravu_lite_lut3, vec2(0.34615384615384615, coord_y));
res += luma4 * w + luma20 * w.wzyx;
w = texture(ravu_lite_lut3, vec2(0.4230769230769231, coord_y));
res += luma5 * w + luma19 * w.wzyx;
w = texture(ravu_lite_lut3, vec2(0.5, coord_y));
wg = max(vec4(0.0), w);
res += luma6 * w + luma18 * w.wzyx;
cg4 = vec4(0.1 + luma6, 1.1 - luma6, 0.1 + luma18, 1.1 - luma18);
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 += luma7 * w + luma17 * w.wzyx;
cg4 = vec4(0.1 + luma7, 1.1 - luma7, 0.1 + luma17, 1.1 - luma17);
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 += luma8 * w + luma16 * w.wzyx;
cg4 = vec4(0.1 + luma8, 1.1 - luma8, 0.1 + luma16, 1.1 - luma16);
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 += luma9 * w + luma15 * w.wzyx;
w = texture(ravu_lite_lut3, vec2(0.8076923076923077, coord_y));
wg = max(vec4(0.0), w);
res += luma10 * w + luma14 * w.wzyx;
cg4 = vec4(0.1 + luma10, 1.1 - luma10, 0.1 + luma14, 1.1 - luma14);
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 += luma11 * w + luma13 * w.wzyx;
cg4 = vec4(0.1 + luma11, 1.1 - luma11, 0.1 + luma13, 1.1 - luma13);
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 += luma12 * w;
vec2 cg2 = vec2(0.1 + luma12, 1.1 - luma12);
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]
