Remove old upscalers, rename parameters

This commit is contained in:
fp64 2023-04-18 20:36:28 -04:00
parent 9044c0b54c
commit 1b534a4272
6 changed files with 36 additions and 164 deletions

View File

@ -99,28 +99,14 @@ Vertex=upscale_bicubic.vsh
OutputResolution=True
RequiresIntSupport=True
Upscaling=True
SettingName1=B
SettingDefaultValue1=0.0
SettingName1=Sharpness
SettingDefaultValue1=1.0
SettingMaxValue1=2.0
SettingMinValue1=-1.0
SettingName2=C
SettingDefaultValue2=0.5
SettingMinValue1=-2.0
SettingName2=Anisotropy
SettingDefaultValue2=0.0
SettingMaxValue2=2.0
SettingMinValue2=-1.0
[CatmullRom]
Name=Bicubic (Catmull-Rom) Upscaler
Fragment=upscale_catmull_rom.fsh
Vertex=upscale_catmull_rom.vsh
OutputResolution=True
RequiresIntSupport=True
Upscaling=True
[MitchellNetravali]
Name=Bicubic (Mitchell-Netravali) Upscaler
Fragment=upscale_mitchell_netravali.fsh
Vertex=upscale_mitchell_netravali.vsh
OutputResolution=True
RequiresIntSupport=True
Upscaling=True
SettingMinValue2=-2.0
[UpscaleSpline36]
Name=Spline36 Upscaler
Fragment=upscale_spline36.fsh

View File

@ -1,4 +1,6 @@
// Bicubic upscaling shader.
// Implements Mitchell-Netravali class filters (aka BC-splines), see:
// https://en.wikipedia.org/wiki/Mitchell%E2%80%93Netravali_filters .
#ifdef GL_ES
precision mediump float;
@ -12,8 +14,17 @@ uniform vec2 u_texelDelta;
uniform vec2 u_pixelDelta;
uniform vec4 u_setting;
// u_setting.x - B
// u_setting.y - C
// Shader parameters (somewhat poorly named):
// u_setting.x - Sharpness
// u_setting.y - Anisotropy
// from which filter coefficients are computed as
// B = 1 - Sharpness + 0.5*Anisotropy
// C = 0.5 * Sharpness + Anisotropy
// Note: some popular filters are
// B-spline - B=1, C=0 <=> Sharpness=0, Anisotropy=0
// 'The' Mitchell-Netravali - B=C=1/3 <=> Sharpness=2/3, Anisotropy=0
// Catmull-Rom - B=0, C=1/2 <=> Sharpness=1, Anisotropy=0
const vec2 HALF_PIXEL = vec2(0.5, 0.5);
@ -25,7 +36,7 @@ vec4 getWeights(mat4 W, float t) {
return W * vec4(1.0, t, t*t, t*t*t);
}
vec3 interpolateHorizontally(ivec2 inputPosFloor, int dy, vec4 w) {
vec3 filterX(ivec2 inputPosFloor, int dy, vec4 w) {
return
w.x * rgb(inputPosFloor.x - 1, inputPosFloor.y + dy) +
w.y * rgb(inputPosFloor.x , inputPosFloor.y + dy) +
@ -33,28 +44,33 @@ vec3 interpolateHorizontally(ivec2 inputPosFloor, int dy, vec4 w) {
w.w * rgb(inputPosFloor.x + 2, inputPosFloor.y + dy);
}
vec4 process(vec2 outputPos, float B, float C) {
vec4 filterBC(vec2 outputPos, float B, float C) {
vec2 inputPos = outputPos / u_texelDelta - HALF_PIXEL;
ivec2 inputPosFloor = ivec2(inputPos);
float x = inputPos.x - float(inputPosFloor.x);
float y = inputPos.y - float(inputPosFloor.y);
const float r6 = 0.166666666, r3 = 0.333333333; // Precomputed 1/6 and 1/3.
// Matrix for computing weights.
// NOTE: column-major.
mat4 W = mat4(
B/6.0 , 1.0-B/3.0 , B/6.0 , 0.0 ,
-C-0.5*B , 0.0 , C+0.5*B , 0.0 ,
2.0*C+0.5*B, C+2.0*B-3.0 , -2.0*C-2.5*B+3.0, -C ,
-C-B/6.0 , -C-1.5*B+2.0, C+1.5*B-2.0 , C+B/6.0);
B*r6 , 1.0-B*r3 , B*r6 , 0.0 ,
-C-0.5*B , 0.0 , C+0.5*B , 0.0 ,
2.0*C+0.5*B, C+2.0*B-3.0 , -2.0*C-2.5*B+3.0, -C ,
-C-B*r6 , -C-1.5*B+2.0, C+1.5*B-2.0 , C+B*r6);
vec4 Wx = getWeights(W, x);
vec4 Wy = getWeights(W, y);
vec3 ret =
Wy.x * interpolateHorizontally(inputPosFloor, -1, Wx) +
Wy.y * interpolateHorizontally(inputPosFloor, 0, Wx) +
Wy.z * interpolateHorizontally(inputPosFloor, +1, Wx) +
Wy.w * interpolateHorizontally(inputPosFloor, +2, Wx);
Wy.x * filterX(inputPosFloor, -1, Wx) +
Wy.y * filterX(inputPosFloor, 0, Wx) +
Wy.z * filterX(inputPosFloor, +1, Wx) +
Wy.w * filterX(inputPosFloor, +2, Wx);
return vec4(ret, 1.0);
}
void main() {
gl_FragColor.rgba = process(v_position, u_setting.x, u_setting.y);
gl_FragColor.rgba = filterBC(
v_position,
dot(u_setting.xy, vec2(-1.0, 0.5)) + 1.0,
dot(u_setting.xy, vec2(0.5, +1.0)));
}

View File

@ -1,54 +0,0 @@
// Bicubic (Catmull-Rom) upscaling shader.
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
uniform sampler2D sampler0;
varying vec2 v_position;
uniform vec2 u_texelDelta;
uniform vec2 u_pixelDelta;
const vec2 HALF_PIXEL = vec2(0.5, 0.5);
vec3 rgb(int inputX, int inputY)
{
return texture2D(sampler0, (vec2(inputX, inputY) + HALF_PIXEL) * u_texelDelta).xyz;
}
// Catmull-Rom coefficients, multiplied by 2.
float A(float x) {return x*((2.0-x)*x-1.0);}
float B(float x) {return x*x*(3.0*x-5.0)+2.0;}
float C(float x) {return x*((4.0-3.0*x)*x+1.0);}
float D(float x) {return x*x*(x-1.0);}
vec3 interpolateHorizontally(vec2 inputPos, ivec2 inputPosFloor, int dy) {
vec3 ret = vec3(0.0);
float x = inputPos.x - float(inputPosFloor.x);
ret += A(x) * rgb(inputPosFloor.x - 1, inputPosFloor.y + dy);
ret += B(x) * rgb(inputPosFloor.x , inputPosFloor.y + dy);
ret += C(x) * rgb(inputPosFloor.x + 1, inputPosFloor.y + dy);
ret += D(x) * rgb(inputPosFloor.x + 2, inputPosFloor.y + dy);
return ret;
}
vec4 process(vec2 outputPos) {
vec2 inputPos = outputPos / u_texelDelta - HALF_PIXEL;
ivec2 inputPosFloor = ivec2(inputPos);
vec3 ret = vec3(0.0);
float y = inputPos.y - float(inputPosFloor.y);
ret += A(y) * interpolateHorizontally(inputPos, inputPosFloor, -1);
ret += B(y) * interpolateHorizontally(inputPos, inputPosFloor, 0);
ret += C(y) * interpolateHorizontally(inputPos, inputPosFloor, +1);
ret += D(y) * interpolateHorizontally(inputPos, inputPosFloor, +2);
return vec4(0.25 * ret, 1.0);
}
void main()
{
gl_FragColor.rgba = process(v_position);
}

View File

@ -1,11 +0,0 @@
attribute vec4 a_position;
attribute vec2 a_texcoord0;
varying vec2 v_position;
void main()
{
gl_Position = a_position;
v_position = a_texcoord0;
}

View File

@ -1,54 +0,0 @@
// Bicubic (MitchellNetravali, B=1/3, C=1/3) upscaling shader.
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
uniform sampler2D sampler0;
varying vec2 v_position;
uniform vec2 u_texelDelta;
uniform vec2 u_pixelDelta;
const vec2 HALF_PIXEL = vec2(0.5, 0.5);
vec3 rgb(int inputX, int inputY)
{
return texture2D(sampler0, (vec2(inputX, inputY) + HALF_PIXEL) * u_texelDelta).xyz;
}
// MitchellNetravali coefficients, multiplied by 18.
float A(float x) {return ((-7.0*x+15.0)*x-9.0)*x+1.0;}
float B(float x) {return (21.0*x-36.0)*x*x+16.0;}
float C(float x) {return ((-21.0*x+27.0)*x+9.0)*x+1.0;}
float D(float x) {return (7.0*x-6.0)*x*x;}
vec3 interpolateHorizontally(vec2 inputPos, ivec2 inputPosFloor, int dy) {
vec3 ret = vec3(0.0);
float x = inputPos.x - float(inputPosFloor.x);
ret += A(x) * rgb(inputPosFloor.x - 1, inputPosFloor.y + dy);
ret += B(x) * rgb(inputPosFloor.x , inputPosFloor.y + dy);
ret += C(x) * rgb(inputPosFloor.x + 1, inputPosFloor.y + dy);
ret += D(x) * rgb(inputPosFloor.x + 2, inputPosFloor.y + dy);
return ret;
}
vec4 process(vec2 outputPos) {
vec2 inputPos = outputPos / u_texelDelta - HALF_PIXEL;
ivec2 inputPosFloor = ivec2(inputPos);
vec3 ret = vec3(0.0);
float y = inputPos.y - float(inputPosFloor.y);
ret += A(y) * interpolateHorizontally(inputPos, inputPosFloor, -1);
ret += B(y) * interpolateHorizontally(inputPos, inputPosFloor, 0);
ret += C(y) * interpolateHorizontally(inputPos, inputPosFloor, +1);
ret += D(y) * interpolateHorizontally(inputPos, inputPosFloor, +2);
return vec4(ret / 324.0, 1.0);
}
void main()
{
gl_FragColor.rgba = process(v_position);
}

View File

@ -1,11 +0,0 @@
attribute vec4 a_position;
attribute vec2 a_texcoord0;
varying vec2 v_position;
void main()
{
gl_Position = a_position;
v_position = a_texcoord0;
}