diff --git a/cubic/shaders/spline16-x.slang b/cubic/shaders/spline16-x.slang new file mode 100644 index 0000000..8b28c72 --- /dev/null +++ b/cubic/shaders/spline16-x.slang @@ -0,0 +1,125 @@ +#version 450 + +/* + Spline16 - PassX - by Hyllian 2022 + + Adapted from bicubic source shaders below. + + Spline36 math sources: https://www.panotools.org/dersch/interpolator/interpolator.html +*/ + + + +/* + Copyright (C) 2010 Team XBMC + http://www.xbmc.org + Copyright (C) 2011 Stefanos A. + http://www.opentk.com + +This Program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, 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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with XBMC; see the file COPYING. If not, write to +the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +http://www.gnu.org/copyleft/gpl.html +*/ + + +layout(push_constant) uniform Push +{ + vec4 SourceSize; + vec4 OriginalSize; + vec4 OutputSize; + uint FrameCount; +} params; + +layout(std140, set = 0, binding = 0) uniform UBO +{ + mat4 MVP; +} global; + +#pragma stage vertex +layout(location = 0) in vec4 Position; +layout(location = 1) in vec2 TexCoord; +layout(location = 0) out vec2 vTexCoord; + +void main() +{ + gl_Position = global.MVP * Position; + vTexCoord = TexCoord + vec2(0.0001, 0.0001);; +} + +#pragma stage fragment +layout(location = 0) in vec2 vTexCoord; +layout(location = 0) out vec4 FragColor; +layout(set = 0, binding = 2) uniform sampler2D Source; + + +float weight(float x) +{ + x = abs(x); + + if (x < 1.0) + { + return + ( + ((x - 9.0 / 5.0) * x - 1.0 / 5.0 ) * x + 1.0 + ); + } + else if ((x >= 1.0) && (x < 2.0)) + { + return + ( + (( -1.0 / 3.0 * (x - 1) + 4.0 / 5.0 ) * (x - 1) - 7.0 / 15.0 ) * (x - 1) + ); + } + else + { + return 0.0; + } +} + +vec4 weight4(float x) +{ + return vec4( + weight(x - 2.0), + weight(x - 1.0), + weight(x), + weight(x + 1.0) + ); +} + + + +void main() +{ + vec2 ps = params.SourceSize.zw; + vec2 pos = vTexCoord.xy + ps * vec2(0.5, 0.0); + vec2 fp = fract(pos / ps); + + vec2 xystart = (-1.5 - fp) * ps + pos; + + float ypos = xystart.y + ps.y * 2.0; + + vec3 C0 = texture(Source, vec2(xystart.x , ypos)).rgb; + vec3 C1 = texture(Source, vec2(xystart.x + ps.x , ypos)).rgb; + vec3 C2 = texture(Source, vec2(xystart.x + ps.x * 2.0, ypos)).rgb; + vec3 C3 = texture(Source, vec2(xystart.x + ps.x * 3.0, ypos)).rgb; + + vec4 w = weight4(1.0 - fp.x); + + float sum = dot( w, vec4(1)); + w /= sum; + + vec3 color = mat4x3( C0, C1, C2, C3 ) * w; + + FragColor = vec4(color, 1.0); +} diff --git a/cubic/shaders/spline16-y.slang b/cubic/shaders/spline16-y.slang new file mode 100644 index 0000000..ab18e8c --- /dev/null +++ b/cubic/shaders/spline16-y.slang @@ -0,0 +1,125 @@ +#version 450 + +/* + Spline16 - PassY - by Hyllian 2022 + + Adapted from bicubic source shaders below. + + Spline36 math sources: https://www.panotools.org/dersch/interpolator/interpolator.html +*/ + + + +/* + Copyright (C) 2010 Team XBMC + http://www.xbmc.org + Copyright (C) 2011 Stefanos A. + http://www.opentk.com + +This Program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, 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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with XBMC; see the file COPYING. If not, write to +the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +http://www.gnu.org/copyleft/gpl.html +*/ + + +layout(push_constant) uniform Push +{ + vec4 SourceSize; + vec4 OriginalSize; + vec4 OutputSize; + uint FrameCount; +} params; + +layout(std140, set = 0, binding = 0) uniform UBO +{ + mat4 MVP; +} global; + +#pragma stage vertex +layout(location = 0) in vec4 Position; +layout(location = 1) in vec2 TexCoord; +layout(location = 0) out vec2 vTexCoord; + +void main() +{ + gl_Position = global.MVP * Position; + vTexCoord = TexCoord + vec2(0.0001, 0.0001);; +} + +#pragma stage fragment +layout(location = 0) in vec2 vTexCoord; +layout(location = 0) out vec4 FragColor; +layout(set = 0, binding = 2) uniform sampler2D Source; + + +float weight(float x) +{ + x = abs(x); + + if (x < 1.0) + { + return + ( + ((x - 9.0 / 5.0) * x - 1.0 / 5.0 ) * x + 1.0 + ); + } + else if ((x >= 1.0) && (x < 2.0)) + { + return + ( + (( -1.0 / 3.0 * (x - 1) + 4.0 / 5.0 ) * (x - 1) - 7.0 / 15.0 ) * (x - 1) + ); + } + else + { + return 0.0; + } +} + +vec4 weight4(float x) +{ + return vec4( + weight(x - 2.0), + weight(x - 1.0), + weight(x), + weight(x + 1.0) + ); +} + + + +void main() +{ + vec2 ps = params.SourceSize.zw; + vec2 pos = vTexCoord.xy + ps * vec2(0.0, 0.5); + vec2 fp = fract(pos / ps); + + vec2 xystart = (-1.5 - fp) * ps + pos; + + float xpos = xystart.x + ps.x * 2.0; + + vec3 C0 = texture(Source, vec2(xpos, xystart.y )).rgb; + vec3 C1 = texture(Source, vec2(xpos, xystart.y + ps.y )).rgb; + vec3 C2 = texture(Source, vec2(xpos, xystart.y + ps.y * 2.0)).rgb; + vec3 C3 = texture(Source, vec2(xpos, xystart.y + ps.y * 3.0)).rgb; + + vec4 w = weight4(1.0 - fp.y); + + float sum = dot( w, vec4(1)); + w /= sum; + + vec3 color = mat4x3( C0, C1, C2, C3 ) * w; + + FragColor = vec4(color, 1.0); +} diff --git a/cubic/shaders/spline36-x.slang b/cubic/shaders/spline36-x.slang new file mode 100644 index 0000000..3ebc665 --- /dev/null +++ b/cubic/shaders/spline36-x.slang @@ -0,0 +1,135 @@ +#version 450 + +/* + Spline36 - PassX - by Hyllian 2022 + + Adapted from bicubic source shaders below. + + Spline36 math sources: https://www.panotools.org/dersch/interpolator/interpolator.html +*/ + + + +/* + Copyright (C) 2010 Team XBMC + http://www.xbmc.org + Copyright (C) 2011 Stefanos A. + http://www.opentk.com + +This Program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, 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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with XBMC; see the file COPYING. If not, write to +the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +http://www.gnu.org/copyleft/gpl.html +*/ + + +layout(push_constant) uniform Push +{ + vec4 SourceSize; + vec4 OriginalSize; + vec4 OutputSize; + uint FrameCount; +} params; + +layout(std140, set = 0, binding = 0) uniform UBO +{ + mat4 MVP; +} global; + +#pragma stage vertex +layout(location = 0) in vec4 Position; +layout(location = 1) in vec2 TexCoord; +layout(location = 0) out vec2 vTexCoord; + +void main() +{ + gl_Position = global.MVP * Position; + vTexCoord = TexCoord + vec2(0.0001, 0.0001);; +} + +#pragma stage fragment +layout(location = 0) in vec2 vTexCoord; +layout(location = 0) out vec4 FragColor; +layout(set = 0, binding = 2) uniform sampler2D Source; + + +float weight(float x) +{ + x = abs(x); + + if (x < 1.0) + { + return + ( + ( ( 13.0/11.0 * x - 453.0/ 209.0 ) * x - 3.0/ 209.0 ) * x + 1.0 + ); + } + else if ((x >= 1.0) && (x < 2.0)) + { + return + ( + ( ( - 6.0/11.0 * (x-1) + 270.0/ 209.0 ) * (x-1) - 156.0/ 209.0 ) *(x-1) + ); + } + else if ((x >= 2.0) && (x < 3.0)) + { + return + ( + ( ( 1.0/11.0 * (x-2) - 45.0/ 209.0 ) * (x-2) + 26.0/ 209.0 ) *(x-2) + ); + } + else + { + return 0.0; + } +} + +vec3 weight3(float x) +{ + return vec3( + weight(x - 1.0), + weight(x), + weight(x + 1.0) + ); +} + + + +void main() +{ + vec2 ps = params.SourceSize.zw; + vec2 pos = vTexCoord.xy + ps * vec2(0.5, 0.0); + vec2 fp = fract(pos / ps); + + vec2 xystart = (-2.5 - fp) * ps + pos; + + float ypos = xystart.y + ps.y * 3.0; + + vec3 C0 = texture(Source, vec2(xystart.x , ypos)).rgb; + vec3 C1 = texture(Source, vec2(xystart.x + ps.x , ypos)).rgb; + vec3 C2 = texture(Source, vec2(xystart.x + ps.x * 2.0, ypos)).rgb; + vec3 C3 = texture(Source, vec2(xystart.x + ps.x * 3.0, ypos)).rgb; + vec3 C4 = texture(Source, vec2(xystart.x + ps.x * 4.0, ypos)).rgb; + vec3 C5 = texture(Source, vec2(xystart.x + ps.x * 5.0, ypos)).rgb; + + vec3 w1 = weight3(-1.0 - fp.x); + vec3 w2 = weight3( 2.0 - fp.x); + + float sum = dot( w1, vec3(1)) + dot( w2, vec3(1)); + w1 /= sum; + w2 /= sum; + + vec3 color = mat3( C0, C1, C2 ) * w1 + mat3( C3, C4, C5) * w2; + + FragColor = vec4(color, 1.0); +} diff --git a/cubic/shaders/spline36-y.slang b/cubic/shaders/spline36-y.slang new file mode 100644 index 0000000..4790b17 --- /dev/null +++ b/cubic/shaders/spline36-y.slang @@ -0,0 +1,135 @@ +#version 450 + +/* + Spline36 - PassY - by Hyllian 2022 + + Adapted from bicubic source shaders below. + + Spline36 math sources: https://www.panotools.org/dersch/interpolator/interpolator.html +*/ + + + +/* + Copyright (C) 2010 Team XBMC + http://www.xbmc.org + Copyright (C) 2011 Stefanos A. + http://www.opentk.com + +This Program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, 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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with XBMC; see the file COPYING. If not, write to +the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +http://www.gnu.org/copyleft/gpl.html +*/ + + +layout(push_constant) uniform Push +{ + vec4 SourceSize; + vec4 OriginalSize; + vec4 OutputSize; + uint FrameCount; +} params; + +layout(std140, set = 0, binding = 0) uniform UBO +{ + mat4 MVP; +} global; + +#pragma stage vertex +layout(location = 0) in vec4 Position; +layout(location = 1) in vec2 TexCoord; +layout(location = 0) out vec2 vTexCoord; + +void main() +{ + gl_Position = global.MVP * Position; + vTexCoord = TexCoord + vec2(0.0001, 0.0001);; +} + +#pragma stage fragment +layout(location = 0) in vec2 vTexCoord; +layout(location = 0) out vec4 FragColor; +layout(set = 0, binding = 2) uniform sampler2D Source; + + +float weight(float x) +{ + x = abs(x); + + if (x < 1.0) + { + return + ( + ( ( 13.0/11.0 * x - 453.0/ 209.0 ) * x - 3.0/ 209.0 ) * x + 1.0 + ); + } + else if ((x >= 1.0) && (x < 2.0)) + { + return + ( + ( ( - 6.0/11.0 * (x-1) + 270.0/ 209.0 ) * (x-1) - 156.0/ 209.0 ) *(x-1) + ); + } + else if ((x >= 2.0) && (x < 3.0)) + { + return + ( + ( ( 1.0/11.0 * (x-2) - 45.0/ 209.0 ) * (x-2) + 26.0/ 209.0 ) *(x-2) + ); + } + else + { + return 0.0; + } +} + +vec3 weight3(float x) +{ + return vec3( + weight(x - 1.0), + weight(x), + weight(x + 1.0) + ); +} + + + +void main() +{ + vec2 ps = params.SourceSize.zw; + vec2 pos = vTexCoord.xy + ps * vec2(0.0, 0.5); + vec2 fp = fract(pos / ps); + + vec2 xystart = (-2.5 - fp) * ps + pos; + + float xpos = xystart.x + ps.x * 3.0; + + vec3 C0 = texture(Source, vec2(xpos, xystart.y )).rgb; + vec3 C1 = texture(Source, vec2(xpos, xystart.y + ps.y )).rgb; + vec3 C2 = texture(Source, vec2(xpos, xystart.y + ps.y * 2.0)).rgb; + vec3 C3 = texture(Source, vec2(xpos, xystart.y + ps.y * 3.0)).rgb; + vec3 C4 = texture(Source, vec2(xpos, xystart.y + ps.y * 4.0)).rgb; + vec3 C5 = texture(Source, vec2(xpos, xystart.y + ps.y * 5.0)).rgb; + + vec3 w1 = weight3(-1.0 - fp.y); + vec3 w2 = weight3( 2.0 - fp.y); + + float sum = dot( w1, vec3(1)) + dot( w2, vec3(1)); + w1 /= sum; + w2 /= sum; + + vec3 color = mat3( C0, C1, C2 ) * w1 + mat3( C3, C4, C5) * w2; + + FragColor = vec4(color, 1.0); +} diff --git a/cubic/spline16-fast.slangp b/cubic/spline16-fast.slangp new file mode 100644 index 0000000..4589ffd --- /dev/null +++ b/cubic/spline16-fast.slangp @@ -0,0 +1,12 @@ +shaders = 2 + +shader0 = shaders/spline16-x.slang +filter_linear0 = false +scale_type_x0 = viewport +scale_type_y0 = source +scale0 = 1.0 +wrap_mode0 = "clamp_to_edge" + +shader1 = shaders/spline16-y.slang +filter_linear1 = false +wrap_mode1 = "clamp_to_edge" diff --git a/cubic/spline36-fast.slangp b/cubic/spline36-fast.slangp new file mode 100644 index 0000000..852dd4d --- /dev/null +++ b/cubic/spline36-fast.slangp @@ -0,0 +1,12 @@ +shaders = 2 + +shader0 = shaders/spline36-x.slang +filter_linear0 = false +scale_type_x0 = viewport +scale_type_y0 = source +scale0 = 1.0 +wrap_mode0 = "clamp_to_edge" + +shader1 = shaders/spline36-y.slang +filter_linear1 = false +wrap_mode1 = "clamp_to_edge" diff --git a/windowed/lanczos3-fast.slangp b/windowed/lanczos3-fast.slangp new file mode 100644 index 0000000..a8d5275 --- /dev/null +++ b/windowed/lanczos3-fast.slangp @@ -0,0 +1,13 @@ +shaders = 2 + +shader0 = shaders/lanczos3-x.slang +filter_linear0 = false +scale_type_x0 = viewport +scale_type_y0 = source +scale0 = 1.0 +wrap_mode0 = "clamp_to_edge" + +shader1 = shaders/lanczos3-y.slang +filter_linear1 = false +wrap_mode1 = "clamp_to_edge" + diff --git a/windowed/shaders/lanczos3-x.slang b/windowed/shaders/lanczos3-x.slang new file mode 100644 index 0000000..05c248d --- /dev/null +++ b/windowed/shaders/lanczos3-x.slang @@ -0,0 +1,106 @@ +#version 450 + +/* + Lanczos3 - passX + + Multipass code by Hyllian 2022. + +*/ + + +/* + Copyright (C) 2010 Team XBMC + http://www.xbmc.org + Copyright (C) 2011 Stefanos A. + http://www.opentk.com + +This Program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, 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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with XBMC; see the file COPYING. If not, write to +the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +http://www.gnu.org/copyleft/gpl.html +*/ + + +layout(push_constant) uniform Push +{ + vec4 SourceSize; + vec4 OriginalSize; + vec4 OutputSize; + uint FrameCount; +} params; + +#define FIX(c) (max(abs(c), 1e-5)) + +const float PI = 3.1415926535897932384626433832795; +const float radius = 3.0; + +layout(std140, set = 0, binding = 0) uniform UBO +{ + mat4 MVP; +} global; + +#pragma stage vertex +layout(location = 0) in vec4 Position; +layout(location = 1) in vec2 TexCoord; +layout(location = 0) out vec2 vTexCoord; + +void main() +{ + gl_Position = global.MVP * Position; + vTexCoord = TexCoord; +} + +#pragma stage fragment +layout(location = 0) in vec2 vTexCoord; +layout(location = 0) out vec4 FragColor; +layout(set = 0, binding = 2) uniform sampler2D Source; + + +vec3 weight3(float x) +{ + // Looks like "sample" is a reserved word in slang. + vec3 Sample = FIX(2.0 * PI * vec3(x - 1.5, x - 0.5, x + 0.5)); + + // Lanczos3. Note: we normalize outside this function, so no point in multiplying by radius. + return sin(Sample) * sin(Sample / radius) / (Sample * Sample); +} + + +void main() +{ + vec2 ps = params.SourceSize.zw; + vec2 pos = vTexCoord.xy + ps * vec2(0.5, 0.0); + vec2 fp = fract(pos / ps); + + vec2 xystart = (-2.5 - fp) * ps + pos; + + float ypos = xystart.y + ps.y * 3.0; + + vec3 C0 = texture(Source, vec2(xystart.x , ypos)).rgb; + vec3 C1 = texture(Source, vec2(xystart.x + ps.x , ypos)).rgb; + vec3 C2 = texture(Source, vec2(xystart.x + ps.x * 2.0, ypos)).rgb; + vec3 C3 = texture(Source, vec2(xystart.x + ps.x * 3.0, ypos)).rgb; + vec3 C4 = texture(Source, vec2(xystart.x + ps.x * 4.0, ypos)).rgb; + vec3 C5 = texture(Source, vec2(xystart.x + ps.x * 5.0, ypos)).rgb; + + vec3 w1 = weight3(0.5 - fp.x * 0.5); + vec3 w2 = weight3(1.0 - fp.x * 0.5); + + float sum = dot( w1, vec3(1)) + dot( w2, vec3(1)); + w1 /= sum; + w2 /= sum; + + vec3 color = mat3( C0, C2, C4 ) * w1 + mat3( C1, C3, C5) * w2; + + FragColor = vec4(color, 1.0); +} diff --git a/windowed/shaders/lanczos3-y.slang b/windowed/shaders/lanczos3-y.slang new file mode 100644 index 0000000..c5fb65e --- /dev/null +++ b/windowed/shaders/lanczos3-y.slang @@ -0,0 +1,106 @@ +#version 450 + +/* + Lanczos3 - passY + + Multipass code by Hyllian 2022. + +*/ + + +/* + Copyright (C) 2010 Team XBMC + http://www.xbmc.org + Copyright (C) 2011 Stefanos A. + http://www.opentk.com + +This Program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, 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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with XBMC; see the file COPYING. If not, write to +the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +http://www.gnu.org/copyleft/gpl.html +*/ + + +layout(push_constant) uniform Push +{ + vec4 SourceSize; + vec4 OriginalSize; + vec4 OutputSize; + uint FrameCount; +} params; + +#define FIX(c) (max(abs(c), 1e-5)) + +const float PI = 3.1415926535897932384626433832795; +const float radius = 3.0; + +layout(std140, set = 0, binding = 0) uniform UBO +{ + mat4 MVP; +} global; + +#pragma stage vertex +layout(location = 0) in vec4 Position; +layout(location = 1) in vec2 TexCoord; +layout(location = 0) out vec2 vTexCoord; + +void main() +{ + gl_Position = global.MVP * Position; + vTexCoord = TexCoord; +} + +#pragma stage fragment +layout(location = 0) in vec2 vTexCoord; +layout(location = 0) out vec4 FragColor; +layout(set = 0, binding = 2) uniform sampler2D Source; + + +vec3 weight3(float x) +{ + // Looks like "sample" is a reserved word in slang. + vec3 Sample = FIX(2.0 * PI * vec3(x - 1.5, x - 0.5, x + 0.5)); + + // Lanczos3. Note: we normalize outside this function, so no point in multiplying by radius. + return sin(Sample) * sin(Sample / radius) / (Sample * Sample); +} + + +void main() +{ + vec2 ps = params.SourceSize.zw; + vec2 pos = vTexCoord.xy + ps * vec2(0.0, 0.5); + vec2 fp = fract(pos / ps); + + vec2 xystart = (-2.5 - fp) * ps + pos; + + float xpos = xystart.x + ps.x * 3.0; + + vec3 C0 = texture(Source, vec2(xpos, xystart.y )).rgb; + vec3 C1 = texture(Source, vec2(xpos, xystart.y + ps.y )).rgb; + vec3 C2 = texture(Source, vec2(xpos, xystart.y + ps.y * 2.0)).rgb; + vec3 C3 = texture(Source, vec2(xpos, xystart.y + ps.y * 3.0)).rgb; + vec3 C4 = texture(Source, vec2(xpos, xystart.y + ps.y * 4.0)).rgb; + vec3 C5 = texture(Source, vec2(xpos, xystart.y + ps.y * 5.0)).rgb; + + vec3 w1 = weight3(0.5 - fp.y * 0.5); + vec3 w2 = weight3(1.0 - fp.y * 0.5); + + float sum = dot( w1, vec3(1)) + dot( w2, vec3(1)); + w1 /= sum; + w2 /= sum; + + vec3 color = mat3( C0, C2, C4 ) * w1 + mat3( C1, C3, C5) * w2; + + FragColor = vec4(color, 1.0); +}