Upload files to ".config/mpv/scripts/shaders"

main
berkeley 2024-06-24 01:28:28 +00:00
parent d533fd13c4
commit 2983930f51
4 changed files with 1459 additions and 0 deletions

View File

@ -0,0 +1,220 @@
// Revised 12/08/23
// https://gist.github.com/igv/36508af3ffc84410fe39761d6969be10
// https://raw.githubusercontent.com/deus0ww/mpv-conf/master/shaders/igv/SSimDownscaler.glsl
//
// SSimDownscaler by Shiandow
//
// This library 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.0 of the License, or (at your option) any later version.
//
// This library 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 library.
//!HOOK POSTKERNEL
//!BIND PREKERNEL
//!BIND HOOKED
//!SAVE L2
//!WIDTH NATIVE_CROPPED.w
//!WHEN NATIVE_CROPPED.h POSTKERNEL.h >
//!COMPONENTS 3
//!DESC SSimDownscaler L2 1 [robidoux]
#define axis 1
#define offset vec2(0,0)
#define MN(B,C,x) (x < 1.0 ? ((2.-1.5*B-(C))*x + (-3.+2.*B+C))*x*x + (1.-(B)/3.) : (((-(B)/6.-(C))*x + (B+5.*C))*x + (-2.*B-8.*C))*x+((4./3.)*B+4.*C))
#define Kernel(x) MN(0.3782157550939987, 0.3108921224530007, abs(x))
#define taps 2.0
vec4 hook() {
vec2 base = PREKERNEL_pt * (PREKERNEL_pos * input_size + tex_offset);
float low = ceil((PREKERNEL_pos - taps*POSTKERNEL_pt) * input_size - offset + tex_offset - 0.5)[axis];
float high = floor((PREKERNEL_pos + taps*POSTKERNEL_pt) * input_size - offset + tex_offset - 0.5)[axis];
float W = 0.0;
vec4 avg = vec4(0);
vec2 pos = base;
for (float k = low; k <= high; k++) {
pos[axis] = PREKERNEL_pt[axis] * (k - offset[axis] + 0.5);
float rel = (pos[axis] - base[axis])*POSTKERNEL_size[axis];
float w = Kernel(rel);
vec4 tex = textureLod(PREKERNEL_raw, pos, 0.0) * PREKERNEL_mul;
avg += w * tex * tex;
W += w;
}
avg /= W;
return avg;
}
//!HOOK POSTKERNEL
//!BIND L2
//!BIND HOOKED
//!SAVE L2
//!WHEN NATIVE_CROPPED.w POSTKERNEL.w >
//!COMPONENTS 3
//!DESC SSimDownscaler L2 2 [robidoux]
#define axis 0
#define offset vec2(0,0)
#define MN(B,C,x) (x < 1.0 ? ((2.-1.5*B-(C))*x + (-3.+2.*B+C))*x*x + (1.-(B)/3.) : (((-(B)/6.-(C))*x + (B+5.*C))*x + (-2.*B-8.*C))*x+((4./3.)*B+4.*C))
#define Kernel(x) MN(0.3782157550939987, 0.3108921224530007, abs(x))
#define taps 2.0
vec4 hook() {
float low = ceil((L2_pos - taps*POSTKERNEL_pt) * L2_size - offset - 0.5)[axis];
float high = floor((L2_pos + taps*POSTKERNEL_pt) * L2_size - offset - 0.5)[axis];
float W = 0.0;
vec4 avg = vec4(0);
vec2 pos = L2_pos;
for (float k = low; k <= high; k++) {
pos[axis] = L2_pt[axis] * (k - offset[axis] + 0.5);
float rel = (pos[axis] - L2_pos[axis])*POSTKERNEL_size[axis];
float w = Kernel(rel);
avg += w * textureLod(L2_raw, pos, 0.0) * L2_mul;
W += w;
}
avg /= W;
return avg;
}
//!HOOK POSTKERNEL
//!BIND HOOKED
//!BIND L2
//!SAVE MR
//!WHEN NATIVE_CROPPED.h POSTKERNEL.h >
//!COMPONENTS 4
//!DESC SSimDownscaler mean & R
#define oversharp 0.0
#define sigma_nsq 10. / (255.*255.)
#define locality 2.0
#define offset vec2(0,0)
#define Kernel(x) pow(1.0 / locality, abs(x))
#define taps 3.0
#define Luma(rgb) ( dot(rgb, vec3(0.212655, 0.715158, 0.072187)) )
mat3x3 ScaleH(vec2 pos) {
float low = ceil(-0.5*taps - offset)[0];
float high = floor(0.5*taps - offset)[0];
float W = 0.0;
mat3x3 avg = mat3x3(0);
for (float k = low; k <= high; k++) {
pos[0] = HOOKED_pos[0] + HOOKED_pt[0] * k;
float rel = k + offset[0];
float w = Kernel(rel);
vec3 L = POSTKERNEL_tex(pos).rgb;
avg += w * mat3x3(L, L*L, L2_tex(pos).rgb);
W += w;
}
avg /= W;
return avg;
}
vec4 hook() {
vec2 pos = HOOKED_pos;
float low = ceil(-0.5*taps - offset)[1];
float high = floor(0.5*taps - offset)[1];
float W = 0.0;
mat3x3 avg = mat3x3(0);
for (float k = low; k <= high; k++) {
pos[1] = HOOKED_pos[1] + HOOKED_pt[1] * k;
float rel = k + offset[1];
float w = Kernel(rel);
avg += w * ScaleH(pos);
W += w;
}
avg /= W;
float Sl = Luma(max(avg[1] - avg[0] * avg[0], 0.));
float Sh = Luma(max(avg[2] - avg[0] * avg[0], 0.));
return vec4(avg[0], mix(sqrt((Sh + sigma_nsq) / (Sl + sigma_nsq)) * (1. + oversharp), clamp(Sh / Sl, 0., 1.), int(Sl > Sh)));
}
//!HOOK POSTKERNEL
//!BIND HOOKED
//!BIND MR
//!WHEN NATIVE_CROPPED.h POSTKERNEL.h >
//!DESC SSimDownscaler Final
#define locality 2.0
#define offset vec2(0,0)
#define Kernel(x) pow(1.0 / locality, abs(x))
#define taps 3.0
#define Gamma(x) ( pow(x, vec3(1.0/2.0)) )
#define GammaInv(x) ( pow(clamp(x, 0.0, 1.0), vec3(2.0)) )
mat3x3 ScaleH(vec2 pos) {
float low = ceil(-0.5*taps - offset)[0];
float high = floor(0.5*taps - offset)[0];
float W = 0.0;
mat3x3 avg = mat3x3(0);
for (float k = low; k <= high; k++) {
pos[0] = HOOKED_pos[0] + HOOKED_pt[0] * k;
float rel = k + offset[0];
float w = Kernel(rel);
vec4 MR = MR_tex(pos);
avg += w * mat3x3(MR.a*MR.rgb, MR.rgb, MR.aaa);
W += w;
}
avg /= W;
return avg;
}
vec4 hook() {
vec2 pos = HOOKED_pos;
float low = ceil(-0.5*taps - offset)[1];
float high = floor(0.5*taps - offset)[1];
float W = 0.0;
mat3x3 avg = mat3x3(0);
for (float k = low; k <= high; k++) {
pos[1] = HOOKED_pos[1] + HOOKED_pt[1] * k;
float rel = k + offset[1];
float w = Kernel(rel);
avg += w * ScaleH(pos);
W += w;
}
avg /= W;
vec4 L = POSTKERNEL_texOff(0);
return vec4(avg[1] + avg[2] * L.rgb - avg[0], L.a);
}

View File

@ -0,0 +1,207 @@
// Revised 12/08/23
// https://gist.github.com/igv/2364ffa6e81540f29cb7ab4c9bc05b6b
// https://raw.githubusercontent.com/deus0ww/mpv-conf/master/shaders/igv/SSimSuperRes.glsl
//
// SSimSuperRes by Shiandow
//
// This library 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.0 of the License, or (at your option) any later version.
//
// This library 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 library.
//!HOOK POSTKERNEL
//!BIND HOOKED
//!SAVE LOWRES
//!HEIGHT NATIVE_CROPPED.h
//!WHEN NATIVE_CROPPED.h OUTPUT.h <
//!COMPONENTS 4
//!DESC SSSR Downscaling 1 [robidoux]
#define axis 1
#define offset vec2(0,0)
#define MN(B,C,x) (x < 1.0 ? ((2.-1.5*B-(C))*x + (-3.+2.*B+C))*x*x + (1.-(B)/3.) : (((-(B)/6.-(C))*x + (B+5.*C))*x + (-2.*B-8.*C))*x+((4./3.)*B+4.*C))
#define Kernel(x) MN(0.3782157550939987, 0.3108921224530007, abs(x))
#define taps 2.0
#define Luma(rgb) dot(rgb*rgb, vec3(0.212655, 0.715158, 0.072187))
vec4 hook() {
float low = ceil((HOOKED_pos - taps/input_size) * HOOKED_size - offset - 0.5)[axis];
float high = floor((HOOKED_pos + taps/input_size) * HOOKED_size - offset - 0.5)[axis];
float W = 0.0;
vec4 avg = vec4(0);
vec2 pos = HOOKED_pos;
vec4 tex;
for (float k = low; k <= high; k++) {
pos[axis] = HOOKED_pt[axis] * (k - offset[axis] + 0.5);
float rel = (pos[axis] - HOOKED_pos[axis])*input_size[axis];
float w = Kernel(rel);
tex.rgb = textureLod(HOOKED_raw, pos, 0.0).rgb * HOOKED_mul;
tex.a = Luma(tex.rgb);
avg += w * tex;
W += w;
}
avg /= W;
return vec4(avg.rgb, max(abs(avg.a - Luma(avg.rgb)), 5e-7));
}
//!HOOK POSTKERNEL
//!BIND LOWRES
//!SAVE LOWRES
//!WIDTH NATIVE_CROPPED.w
//!HEIGHT NATIVE_CROPPED.h
//!WHEN NATIVE_CROPPED.w OUTPUT.w <
//!COMPONENTS 4
//!DESC SSSR Downscaling 2 [robidoux]
#define axis 0
#define offset vec2(0,0)
#define MN(B,C,x) (x < 1.0 ? ((2.-1.5*B-(C))*x + (-3.+2.*B+C))*x*x + (1.-(B)/3.) : (((-(B)/6.-(C))*x + (B+5.*C))*x + (-2.*B-8.*C))*x+((4./3.)*B+4.*C))
#define Kernel(x) MN(0.3782157550939987, 0.3108921224530007, abs(x))
#define taps 2.0
#define Luma(rgb) dot(rgb*rgb, vec3(0.212655, 0.715158, 0.072187))
vec4 hook() {
float low = ceil((LOWRES_pos - taps/input_size) * LOWRES_size - offset - 0.5)[axis];
float high = floor((LOWRES_pos + taps/input_size) * LOWRES_size - offset - 0.5)[axis];
float W = 0.0;
vec4 avg = vec4(0);
vec2 pos = LOWRES_pos;
vec4 tex;
for (float k = low; k <= high; k++) {
pos[axis] = LOWRES_pt[axis] * (k - offset[axis] + 0.5);
float rel = (pos[axis] - LOWRES_pos[axis])*input_size[axis];
float w = Kernel(rel);
tex.rgb = textureLod(LOWRES_raw, pos, 0.0).rgb * LOWRES_mul;
tex.a = Luma(tex.rgb);
avg += w * tex;
W += w;
}
avg /= W;
return vec4(avg.rgb, max(abs(avg.a - Luma(avg.rgb)), 5e-7) + LOWRES_texOff(0).a);
}
//!HOOK POSTKERNEL
//!BIND PREKERNEL
//!BIND LOWRES
//!SAVE var
//!WIDTH NATIVE_CROPPED.w
//!HEIGHT NATIVE_CROPPED.h
//!WHEN NATIVE_CROPPED.h OUTPUT.h <
//!COMPONENTS 2
//!DESC SSSR var
#define spread 1.0 / 4.0
#define GetL(x,y) PREKERNEL_tex(PREKERNEL_pt * (PREKERNEL_pos * input_size + tex_offset + vec2(x,y))).rgb
#define GetH(x,y) LOWRES_texOff(vec2(x,y)).rgb
#define Luma(rgb) dot(rgb*rgb, vec3(0.212655, 0.715158, 0.072187))
#define diff(x,y) vec2(Luma((GetL(x,y) - meanL)), Luma((GetH(x,y) - meanH)))
vec4 hook() {
vec3 meanL = GetL(0,0);
vec3 meanH = GetH(0,0);
for (int X=-1; X<=1; X+=2) {
meanL += GetL(X,0) * spread;
meanH += GetH(X,0) * spread;
}
for (int Y=-1; Y<=1; Y+=2) {
meanL += GetL(0,Y) * spread;
meanH += GetH(0,Y) * spread;
}
meanL /= (1.0 + 4.0*spread);
meanH /= (1.0 + 4.0*spread);
vec2 var = diff(0,0);
for (int X=-1; X<=1; X+=2)
var += diff(X,0) * spread;
for (int Y=-1; Y<=1; Y+=2)
var += diff(0,Y) * spread;
return vec4(max(var / (1.0 + 4.0*spread), vec2(1e-6)), 0, 0);
}
//!HOOK POSTKERNEL
//!BIND HOOKED
//!BIND PREKERNEL
//!BIND LOWRES
//!BIND var
//!WHEN NATIVE_CROPPED.h OUTPUT.h <
//!DESC SSSR Final
#define oversharp 0.5
// -- Window Size --
#define taps 3.0
#define even (taps - 2.0 * floor(taps / 2.0) == 0.0)
#define minX int(1.0-ceil(taps/2.0))
#define maxX int(floor(taps/2.0))
#define Kernel(x) cos(acos(-1.0)*(x)/taps) // Hann kernel
// -- Input processing --
#define var(x,y) var_tex(var_pt * (pos + vec2(x,y) + 0.5)).rg
#define GetL(x,y) PREKERNEL_tex(PREKERNEL_pt * (pos + tex_offset + vec2(x,y) + 0.5)).rgb
#define GetH(x,y) LOWRES_tex(LOWRES_pt * (pos + vec2(x,y) + 0.5))
#define Luma(rgb) dot(rgb*rgb, vec3(0.212655, 0.715158, 0.072187))
vec4 hook() {
vec4 c0 = HOOKED_texOff(0);
vec2 pos = HOOKED_pos * LOWRES_size - vec2(0.5);
vec2 offset = pos - (even ? floor(pos) : round(pos));
pos -= offset;
vec2 mVar = vec2(0.0);
for (int X=-1; X<=1; X++)
for (int Y=-1; Y<=1; Y++) {
vec2 w = clamp(1.5 - abs(vec2(X,Y)), 0.0, 1.0);
mVar += w.r * w.g * vec2(GetH(X,Y).a, 1.0);
}
mVar.r /= mVar.g;
// Calculate faithfulness force
float weightSum = 0.0;
vec3 diff = vec3(0);
for (int X = minX; X <= maxX; X++)
for (int Y = minX; Y <= maxX; Y++)
{
float R = (-1.0 - oversharp) * sqrt(var(X,Y).r / (var(X,Y).g + mVar.r));
vec2 krnl = Kernel(vec2(X,Y) - offset);
float weight = krnl.r * krnl.g / (Luma((c0.rgb - GetH(X,Y).rgb)) + GetH(X,Y).a);
diff += weight * (GetL(X,Y) + GetH(X,Y).rgb * R + (-1.0 - R) * (c0.rgb));
weightSum += weight;
}
diff /= weightSum;
c0.rgb = ((c0.rgb) + diff);
return c0;
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long