// 
// 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-Zoom-AR (luma, r3)
//!HOOK LUMA
//!BIND HOOKED
//!BIND ravu_zoom_lut3
//!BIND ravu_zoom_lut3_ar
//!WIDTH OUTPUT.w
//!HEIGHT OUTPUT.h
//!OFFSET ALIGN
//!WHEN HOOKED.w OUTPUT.w < HOOKED.h OUTPUT.h < *
#define LUTPOS(x, lut_size) mix(0.5 / (lut_size), 1.0 - 0.5 / (lut_size), (x))
vec4 hook() {
vec2 pos = HOOKED_pos * HOOKED_size;
vec2 subpix = fract(pos - 0.5);
pos -= subpix;
subpix = LUTPOS(subpix, vec2(9.0));
vec2 subpix_inv = 1.0 - subpix;
vec2 subpix_ar = subpix / vec2(2.0, 288.0);
vec2 subpix_inv_ar = subpix_inv / vec2(2.0, 288.0);
subpix /= vec2(5.0, 288.0);
subpix_inv /= vec2(5.0, 288.0);
vec4 gather0 = HOOKED_mul * textureGatherOffset(HOOKED_raw, pos * HOOKED_pt, ivec2(-2, -2), 0);
vec4 gather2 = HOOKED_mul * textureGatherOffset(HOOKED_raw, pos * HOOKED_pt, ivec2(-2, 0), 0);
vec4 gather4 = HOOKED_mul * textureGatherOffset(HOOKED_raw, pos * HOOKED_pt, ivec2(-2, 2), 0);
vec4 gather12 = HOOKED_mul * textureGatherOffset(HOOKED_raw, pos * HOOKED_pt, ivec2(0, -2), 0);
vec4 gather14 = HOOKED_mul * textureGatherOffset(HOOKED_raw, pos * HOOKED_pt, ivec2(0, 0), 0);
vec4 gather16 = HOOKED_mul * textureGatherOffset(HOOKED_raw, pos * HOOKED_pt, ivec2(0, 2), 0);
vec4 gather24 = HOOKED_mul * textureGatherOffset(HOOKED_raw, pos * HOOKED_pt, ivec2(2, -2), 0);
vec4 gather26 = HOOKED_mul * textureGatherOffset(HOOKED_raw, pos * HOOKED_pt, ivec2(2, 0), 0);
vec4 gather28 = HOOKED_mul * textureGatherOffset(HOOKED_raw, pos * HOOKED_pt, ivec2(2, 2), 0);
vec3 abd = vec3(0.0);
float gx, gy;
gx = (gather12.x-gather0.x)/2.0;
gy = (gather2.z-gather0.z)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.04792235409415088;
gx = (gather14.w-gather2.w)/2.0;
gy = (-gather4.z+8.0*gather2.y-8.0*gather0.y+gather0.z)/12.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.06153352068439959;
gx = (gather14.x-gather2.x)/2.0;
gy = (-gather4.y+8.0*gather4.z-8.0*gather2.z+gather0.y)/12.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.06153352068439959;
gx = (gather16.w-gather4.w)/2.0;
gy = (gather4.y-gather2.y)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.04792235409415088;
gx = (-gather24.x+8.0*gather12.y-8.0*gather0.y+gather0.x)/12.0;
gy = (gather14.w-gather12.w)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.06153352068439959;
gx = (-gather26.w+8.0*gather14.z-8.0*gather2.z+gather2.w)/12.0;
gy = (-gather16.w+8.0*gather14.x-8.0*gather12.x+gather12.w)/12.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.07901060453704994;
gx = (-gather26.x+8.0*gather14.y-8.0*gather2.y+gather2.x)/12.0;
gy = (-gather16.x+8.0*gather16.w-8.0*gather14.w+gather12.x)/12.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.07901060453704994;
gx = (-gather28.w+8.0*gather16.z-8.0*gather4.z+gather4.w)/12.0;
gy = (gather16.x-gather14.x)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.06153352068439959;
gx = (-gather24.y+8.0*gather24.x-8.0*gather12.x+gather0.y)/12.0;
gy = (gather14.z-gather12.z)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.06153352068439959;
gx = (-gather26.z+8.0*gather26.w-8.0*gather14.w+gather2.z)/12.0;
gy = (-gather16.z+8.0*gather14.y-8.0*gather12.y+gather12.z)/12.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.07901060453704994;
gx = (-gather26.y+8.0*gather26.x-8.0*gather14.x+gather2.y)/12.0;
gy = (-gather16.y+8.0*gather16.z-8.0*gather14.z+gather12.y)/12.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.07901060453704994;
gx = (-gather28.z+8.0*gather28.w-8.0*gather16.w+gather4.z)/12.0;
gy = (gather16.y-gather14.y)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.06153352068439959;
gx = (gather24.y-gather12.y)/2.0;
gy = (gather26.w-gather24.w)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.04792235409415088;
gx = (gather26.z-gather14.z)/2.0;
gy = (-gather28.w+8.0*gather26.x-8.0*gather24.x+gather24.w)/12.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.06153352068439959;
gx = (gather26.y-gather14.y)/2.0;
gy = (-gather28.x+8.0*gather28.w-8.0*gather26.w+gather24.x)/12.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.06153352068439959;
gx = (gather28.z-gather16.z)/2.0;
gy = (gather28.x-gather26.x)/2.0;
abd += vec3(gx * gx, gx * gy, gy * gy) * 0.04792235409415088;
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) / 288.0;
float res = 0.0;
vec4 w;
vec4 cg, cg1;
float lo = 0.0, hi = 0.0;
float lo2 = 0.0, hi2 = 0.0;
w = texture(ravu_zoom_lut3, vec2(0.0, coord_y) + subpix);
res += gather0.w * w[0];
res += gather0.x * w[1];
res += gather2.w * w[2];
res += gather2.x * w[3];
w = texture(ravu_zoom_lut3, vec2(0.2, coord_y) + subpix);
res += gather4.w * w[0];
res += gather4.x * w[1];
res += gather0.z * w[2];
res += gather0.y * w[3];
w = texture(ravu_zoom_lut3, vec2(0.4, coord_y) + subpix);
res += gather2.z * w[0];
res += gather2.y * w[1];
res += gather4.z * w[2];
res += gather4.y * w[3];
w = texture(ravu_zoom_lut3, vec2(0.6, coord_y) + subpix);
res += gather12.w * w[0];
res += gather12.x * w[1];
res += gather14.w * w[2];
res += gather14.x * w[3];
w = texture(ravu_zoom_lut3, vec2(0.8, coord_y) + subpix);
res += gather16.w * w[0];
res += gather16.x * w[1];
w = texture(ravu_zoom_lut3, vec2(0.0, coord_y) + subpix_inv);
res += gather28.y * w[0];
res += gather28.z * w[1];
res += gather26.y * w[2];
res += gather26.z * w[3];
w = texture(ravu_zoom_lut3, vec2(0.2, coord_y) + subpix_inv);
res += gather24.y * w[0];
res += gather24.z * w[1];
res += gather28.x * w[2];
res += gather28.w * w[3];
w = texture(ravu_zoom_lut3, vec2(0.4, coord_y) + subpix_inv);
res += gather26.x * w[0];
res += gather26.w * w[1];
res += gather24.x * w[2];
res += gather24.w * w[3];
w = texture(ravu_zoom_lut3, vec2(0.6, coord_y) + subpix_inv);
res += gather16.y * w[0];
res += gather16.z * w[1];
res += gather14.y * w[2];
res += gather14.z * w[3];
w = texture(ravu_zoom_lut3, vec2(0.8, coord_y) + subpix_inv);
res += gather12.y * w[0];
res += gather12.z * w[1];
w = texture(ravu_zoom_lut3_ar, vec2(0.0, coord_y) + subpix_ar);
cg = vec4(0.1 + gather0.y, 1.1 - gather0.y, 0.1 + gather2.z, 1.1 - gather2.z);
cg1 = cg;
cg *= cg;cg *= cg;cg *= cg;cg *= cg;cg *= cg;
hi += cg[0] * w[0] + cg[2] * w[1];
lo += cg[1] * w[0] + cg[3] * w[1];
cg *= cg1;
hi2 += cg[0] * w[0] + cg[2] * w[1];
lo2 += cg[1] * w[0] + cg[3] * w[1];
cg = vec4(0.1 + gather2.y, 1.1 - gather2.y, 0.1 + gather4.z, 1.1 - gather4.z);
cg1 = cg;
cg *= cg;cg *= cg;cg *= cg;cg *= cg;cg *= cg;
hi += cg[0] * w[2] + cg[2] * w[3];
lo += cg[1] * w[2] + cg[3] * w[3];
cg *= cg1;
hi2 += cg[0] * w[2] + cg[2] * w[3];
lo2 += cg[1] * w[2] + cg[3] * w[3];
w = texture(ravu_zoom_lut3_ar, vec2(0.5, coord_y) + subpix_ar);
cg = vec4(0.1 + gather12.x, 1.1 - gather12.x, 0.1 + gather14.w, 1.1 - gather14.w);
cg1 = cg;
cg *= cg;cg *= cg;cg *= cg;cg *= cg;cg *= cg;
hi += cg[0] * w[0] + cg[2] * w[1];
lo += cg[1] * w[0] + cg[3] * w[1];
cg *= cg1;
hi2 += cg[0] * w[0] + cg[2] * w[1];
lo2 += cg[1] * w[0] + cg[3] * w[1];
cg = vec4(0.1 + gather14.x, 1.1 - gather14.x, 0.1 + gather16.w, 1.1 - gather16.w);
cg1 = cg;
cg *= cg;cg *= cg;cg *= cg;cg *= cg;cg *= cg;
hi += cg[0] * w[2] + cg[2] * w[3];
lo += cg[1] * w[2] + cg[3] * w[3];
cg *= cg1;
hi2 += cg[0] * w[2] + cg[2] * w[3];
lo2 += cg[1] * w[2] + cg[3] * w[3];
w = texture(ravu_zoom_lut3_ar, vec2(0.0, coord_y) + subpix_inv_ar);
cg = vec4(0.1 + gather28.w, 1.1 - gather28.w, 0.1 + gather26.x, 1.1 - gather26.x);
cg1 = cg;
cg *= cg;cg *= cg;cg *= cg;cg *= cg;cg *= cg;
hi += cg[0] * w[0] + cg[2] * w[1];
lo += cg[1] * w[0] + cg[3] * w[1];
cg *= cg1;
hi2 += cg[0] * w[0] + cg[2] * w[1];
lo2 += cg[1] * w[0] + cg[3] * w[1];
cg = vec4(0.1 + gather26.w, 1.1 - gather26.w, 0.1 + gather24.x, 1.1 - gather24.x);
cg1 = cg;
cg *= cg;cg *= cg;cg *= cg;cg *= cg;cg *= cg;
hi += cg[0] * w[2] + cg[2] * w[3];
lo += cg[1] * w[2] + cg[3] * w[3];
cg *= cg1;
hi2 += cg[0] * w[2] + cg[2] * w[3];
lo2 += cg[1] * w[2] + cg[3] * w[3];
w = texture(ravu_zoom_lut3_ar, vec2(0.5, coord_y) + subpix_inv_ar);
cg = vec4(0.1 + gather16.z, 1.1 - gather16.z, 0.1 + gather14.y, 1.1 - gather14.y);
cg1 = cg;
cg *= cg;cg *= cg;cg *= cg;cg *= cg;cg *= cg;
hi += cg[0] * w[0] + cg[2] * w[1];
lo += cg[1] * w[0] + cg[3] * w[1];
cg *= cg1;
hi2 += cg[0] * w[0] + cg[2] * w[1];
lo2 += cg[1] * w[0] + cg[3] * w[1];
cg = vec4(0.1 + gather14.z, 1.1 - gather14.z, 0.1 + gather12.y, 1.1 - gather12.y);
cg1 = cg;
cg *= cg;cg *= cg;cg *= cg;cg *= cg;cg *= cg;
hi += cg[0] * w[2] + cg[2] * w[3];
lo += cg[1] * w[2] + cg[3] * w[3];
cg *= cg1;
hi2 += cg[0] * w[2] + cg[2] * w[3];
lo2 += cg[1] * w[2] + cg[3] * w[3];
hi = hi2 / hi - 0.1;
lo = 1.1 - lo2 / lo;
res = mix(res, clamp(res, lo, hi), 0.800000);
return vec4(res, 0.0, 0.0, 0.0);
}
//!TEXTURE ravu_zoom_lut3
//!SIZE 45 2592
//!FORMAT rgba16f
//!FILTER LINEAR
[encoded data, 3732480 characters]
//!TEXTURE ravu_zoom_lut3_ar
//!SIZE 18 2592
//!FORMAT rgba16f
//!FILTER LINEAR
[encoded data, 1492992 characters]
