Merge pull request #155 from hunterk/master

move/add stereoscopic-3D shaders to match glsl repo
This commit is contained in:
hizzlekizzle 2020-12-16 12:54:59 -06:00 committed by GitHub
commit d26ad30362
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 2405 additions and 239 deletions

View file

@ -0,0 +1,8 @@
shaders = 1
shader0 = gaussian_blur_filtering/gaussian-sharp.slang
filter_linear0 = false
scale_type_x0 = viewport
scale_x0 = 1.0
scale_type_y0 = viewport
scale_y0 = 1.0

8
blurs/gaussian_blur.slangp Executable file
View file

@ -0,0 +1,8 @@
shaders = 1
shader0 = gaussian_blur_filtering/gaussian.slang
filter_linear0 = false
scale_type_x0 = viewport
scale_x0 = 1.0
scale_type_y0 = viewport
scale_y0 = 1.0

View file

@ -0,0 +1,15 @@
shaders = 2
shader0 = gaussian_blur_filtering/gaussian_horizontal-sharp.slang
filter_linear0 = false
scale_type_x0 = viewport
scale_x0 = 1.0
scale_type_y0 = source
scale_y0 = 1.0
shader1 = gaussian_blur_filtering/gaussian_vertical-sharp.slang
filter_linear1 = false
scale_type_x1 = viewport
scale_x1 = 1.0
scale_type_y1 = viewport
scale_y1 = 1.0

View file

@ -0,0 +1,15 @@
shaders = 2
shader0 = gaussian_blur_filtering/gaussian_horizontal.slang
filter_linear0 = false
scale_type_x0 = viewport
scale_x0 = 1.0
scale_type_y0 = source
scale_y0 = 1.0
shader1 = gaussian_blur_filtering/gaussian_vertical.slang
filter_linear1 = false
scale_type_x1 = viewport
scale_x1 = 1.0
scale_type_y1 = viewport
scale_y1 = 1.0

View file

@ -0,0 +1,157 @@
#version 450
/*
Gaussian blur 'sharp'- dynamic range, resizable
Copyright (C) 2020 guest(r) - guest.r@gmail.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
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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Anti-Ringing inspired by Hyllian
*/
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float SIZEH;
float SIGMA_H;
float HSHARP0;
float HAR;
float SHAR;
} params;
#pragma parameter SIZEH "Gaussian Blur Radius" 6.0 0.0 25.0 1.0
#define SIZEH params.SIZEH
#pragma parameter SIGMA_H "Gaussian Blur Sigma" 1.50 0.1 12.0 0.05
#define SIGMA_H params.SIGMA_H
#pragma parameter HSHARP0 "Sharpness Filter 'Range'" 0.8 0.8 20.0 0.2
#define HSHARP0 params.HSHARP0
#pragma parameter SHAR "Sharpness Definition" 0.5 0.0 2.0 0.05
#define SHAR params.SHAR
#pragma parameter HAR "Anti-Ringing" 0.5 0.0 1.0 0.10
#define HAR params.HAR
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;
#define COMPAT_TEXTURE(c,d) texture(c,d)
#define SourceSize params.SourceSize
float invsqrsigma_h = 1.0/(2.0*SIGMA_H*SIGMA_H);
float gaussian_h(float x)
{
return exp(-x*x*invsqrsigma_h);
}
void main()
{
vec2 f = fract(SourceSize.xy * vTexCoord.xy);
f = 0.5 - f;
vec2 tex = floor(SourceSize.xy * vTexCoord)*SourceSize.zw + 0.5*SourceSize.zw;
vec2 dx = vec2(SourceSize.z, 0.0);
vec2 dy = vec2(0.0, SourceSize.w);
vec3 colorx = vec3(0.0);
vec3 colory = vec3(0.0);
float wx, wy;
float wsumx;
float wsumy = 0.0;
vec3 pixel;
float x;
float y = -SIZEH;
vec3 xcmax = COMPAT_TEXTURE(Source, tex).rgb;
vec3 xcmin = xcmax;
vec3 ycmax = xcmax;
vec3 ycmin = xcmax;
float sharp = (HSHARP0 > 0.85) ? gaussian_h(HSHARP0) : 0.0;
float FPR = HSHARP0;
float wnorm = 1.0; // /(1.0-sharp);
float fpx = 0.0;
do
{
wsumx = 0.0;
colorx = 0.0.xxx;
x = -SIZEH;
do
{
pixel = COMPAT_TEXTURE(Source, tex + x*dx + y*dy).rgb;
wx = (gaussian_h(x+f.x) - sharp)*wnorm;
if (HSHARP0 > 0.85)
{
if (abs(x+f.x) > FPR) { if (x < 0.0) fpx = -(x+f.x+FPR)/FPR; else fpx = (x+f.x-FPR)/FPR; fpx = min(fpx, 1.0); }
if (abs(x) <= 2.0*FPR) { xcmax = max(xcmax, pixel); xcmin = min(xcmin, pixel); }
if (wx < 0.0) wx = clamp(wx, mix(-0.18, 0.0, pow(fpx, SHAR)), 0.0);
}
colorx = colorx + wx * pixel;
wsumx = wsumx+ wx;
x = x + 1.0;
} while (x <= SIZEH);
colorx = colorx / wsumx;
if (HSHARP0 > 0.85) colorx = mix(clamp(colorx, 0.0, 1.0), clamp(colorx, xcmin, xcmax), HAR);
wy = (gaussian_h(y+f.y) - sharp)*wnorm;
if (HSHARP0 > 0.85)
{
if (abs(y+f.y) > FPR) { if (y < 0.0) fpx = -(y+f.y+FPR)/FPR; else fpx = (y+f.y-FPR)/FPR; fpx = min(fpx, 1.0); }
if (abs(y) <= 2.0*FPR) { ycmax = max(ycmax, colorx); ycmin = min(ycmin, colorx); }
if (wy < 0.0) wy = clamp(wy, mix(-0.18, 0.0, pow(fpx, SHAR)), 0.0);
}
colory = colory + wy * colorx;
wsumy = wsumy + wy;
y = y + 1.0;
} while (y <= SIZEH);
colory= colory/wsumy;
if (HSHARP0 > 0.85) colory = mix(clamp(colory, 0.0, 1.0), clamp(colory, ycmin, ycmax), HAR);
FragColor = vec4(colory, 1.0);
}

View file

@ -0,0 +1,129 @@
#version 450
/*
Gaussian blur - dynamic range, resizable
Copyright (C) 2020 guest(r) - guest.r@gmail.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
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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float SIZEH;
float SIGMA_H;
float SIZEV;
float SIGMA_V;
} params;
#pragma parameter SIZEH "Horizontal Blur Radius" 6.0 0.0 25.0 1.0
#define SIZEH params.SIZEH
#pragma parameter SIGMA_H "Horizontal Blur Sigma" 1.50 0.1 12.0 0.05
#define SIGMA_H params.SIGMA_H
#pragma parameter SIZEV "Vertical Blur Radius" 6.0 0.0 25.0 1.0
#define SIZEV params.SIZEV
#pragma parameter SIGMA_V "Vertical Blur Sigma" 1.50 0.1 12.0 0.05
#define SIGMA_V params.SIGMA_V
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;
#define COMPAT_TEXTURE(c,d) texture(c,d)
#define SourceSize params.SourceSize
float invsqrsigma_h = 1.0/(2.0*SIGMA_H*SIGMA_H);
float invsqrsigma_v = 1.0/(2.0*SIGMA_V*SIGMA_V);
float gaussian_h(float x)
{
return exp(-x*x*invsqrsigma_h);
}
float gaussian_v(float x)
{
return exp(-x*x*invsqrsigma_v);
}
void main()
{
vec2 f = fract(SourceSize.xy * vTexCoord.xy);
f = 0.5 - f;
vec2 tex = floor(SourceSize.xy * vTexCoord)*SourceSize.zw + 0.5*SourceSize.zw;
vec2 dx = vec2(SourceSize.z, 0.0);
vec2 dy = vec2(0.0, SourceSize.w);
vec3 colorx = vec3(0.0);
vec3 colory = vec3(0.0);
float wx, wy;
float wsumx;
float wsumy = 0.0;
vec3 pixel;
float x;
float y = -SIZEV;
do
{
wsumx = 0.0;
colorx = 0.0.xxx;
x = -SIZEH;
do
{
pixel = COMPAT_TEXTURE(Source, tex + x*dx + y*dy).rgb;
wx = gaussian_h(x+f.x);
colorx = colorx + wx * pixel;
wsumx = wsumx+ wx;
x = x + 1.0;
} while (x <= SIZEH);
colorx = colorx / wsumx;
wy = gaussian_v(y+f.y);
colory = colory + wy * colorx;
wsumy = wsumy + wy;
y = y + 1.0;
} while (y <= SIZEV);
colory= colory/wsumy;
FragColor = vec4(colory, 1.0);
}

View file

@ -0,0 +1,129 @@
#version 450
/*
Gaussian blur 'sharp' - horizontal pass, dynamic range, resizable
Copyright (C) 2020 guest(r) - guest.r@gmail.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
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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Anti-Ringing inspired by Hyllian
*/
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float SIZEH;
float SIGMA_H;
float HSHARP0;
float HAR;
float HSHAR;
} params;
#pragma parameter SIZEH "Horizontal Blur Radius" 5.0 0.0 40.0 1.0
#define SIZEH params.SIZEH
#pragma parameter SIGMA_H "Horizontal Blur Sigma" 0.70 0.1 15.0 0.05
#define SIGMA_H params.SIGMA_H
#pragma parameter HSHARP0 "Horizontal Sharpness Filter 'Range'" 0.8 0.8 20.0 0.2
#define HSHARP0 params.HSHARP0
#pragma parameter HSHAR "Sharpness Definition - Horizontal" 0.5 0.0 2.0 0.05
#define HSHAR params.HSHAR
#pragma parameter HAR "Horizontal Anti-Ringing" 0.5 0.0 1.0 0.1
#define HAR params.HAR
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;
#define COMPAT_TEXTURE(c,d) texture(c,d)
#define SourceSize params.SourceSize
float invsqrsigma = 1.0/(2.0*SIGMA_H*SIGMA_H);
float gaussian(float x)
{
return exp(-x*x*invsqrsigma);
}
void main()
{
float f = fract(SourceSize.x * vTexCoord.x);
f = 0.5 - f;
vec2 tex = floor(SourceSize.xy * vTexCoord)*SourceSize.zw + 0.5*SourceSize.zw;
vec3 color = vec3(0.0);
vec2 dx = vec2(SourceSize.z, 0.0);
float w;
float wsum = 0.0;
vec3 pixel;
float n = -SIZEH;
vec3 cmax = COMPAT_TEXTURE(Source, tex).rgb;
vec3 cmin = cmax;
float sharp = (HSHARP0 > 0.85) ? gaussian(HSHARP0) : 0.0;
float FPR = HSHARP0;
float wnorm = 1.0/(1.0-sharp);
float fpx = 0.0;
do
{
w = (gaussian(n+f) - sharp)*wnorm;
if (HSHARP0 > 0.85)
{
if (abs(n+f) > FPR) { if (n < 0.0) fpx = -(n+f+FPR)/FPR; else fpx = (n+f-FPR)/FPR; fpx = min(fpx, 1.0);}
if (abs(n) <= 2.0*FPR) { cmax = max(cmax, pixel); cmin = min(cmin, pixel); }
if (w < 0.0) w = clamp(w, mix(-0.18, 0.0, pow(fpx,HSHAR)), 0.0);
}
pixel = COMPAT_TEXTURE(Source, tex + n*dx).rgb;
color = color + w * pixel;
wsum = wsum + w;
n = n + 1.0;
} while (n <= SIZEH);
color = color / wsum;
if (HSHARP0 > 0.85) color = mix(clamp(color, 0.0, 1.0), clamp(color, cmin, cmax), HAR);
FragColor = vec4(color, 1.0);
}

View file

@ -0,0 +1,98 @@
#version 450
/*
Gaussian blur - horizontal pass, dynamic range, resizable
Copyright (C) 2020 guest(r) - guest.r@gmail.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
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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float SIZEH;
float SIGMA_H;
} params;
#pragma parameter SIZEH "Horizontal Blur Radius" 5.0 0.0 40.0 1.0
#define SIZEH params.SIZEH
#pragma parameter SIGMA_H "Horizontal Blur Sigma" 1.0 0.1 15.0 0.05
#define SIGMA_H params.SIGMA_H
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;
#define COMPAT_TEXTURE(c,d) texture(c,d)
#define SourceSize params.SourceSize
float invsqrsigma = 1.0/(2.0*SIGMA_H*SIGMA_H);
float gaussian(float x)
{
return exp(-x*x*invsqrsigma);
}
void main()
{
float f = fract(SourceSize.x * vTexCoord.x);
f = 0.5 - f;
vec2 tex = floor(SourceSize.xy * vTexCoord)*SourceSize.zw + 0.5*SourceSize.zw;
vec3 color = vec3(0.0);
vec2 dx = vec2(SourceSize.z, 0.0);
float w;
float wsum = 0.0;
vec3 pixel;
float n = -SIZEH;
do
{
pixel = COMPAT_TEXTURE(Source, tex + n*dx).rgb;
w = gaussian(n+f);
color = color + w * pixel;
wsum = wsum + w;
n = n + 1.0;
} while (n <= SIZEH);
color = color / wsum;
FragColor = vec4(color, 1.0);
}

View file

@ -0,0 +1,129 @@
#version 450
/*
Gaussian blur 'sharp' - vertical pass, dynamic range, resizable
Copyright (C) 2020 guest(r) - guest.r@gmail.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
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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Anti-Ringing inspired by Hyllian
*/
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float SIZEV;
float SIGMA_V;
float VSHARP0;
float VAR;
float VSHAR;
} params;
#pragma parameter bogus-line "-------------------------------------------------" 0.0 0.0 0.0 0.0
#pragma parameter SIZEV "Vertical Blur Radius" 5.0 0.0 40.0 1.0
#define SIZEV params.SIZEV
#pragma parameter SIGMA_V "Vertical Blur Sigma" 0.70 0.1 15.0 0.05
#define SIGMA_V params.SIGMA_V
#pragma parameter VSHARP0 "Vertical Sharpness Filter 'Range'" 0.8 0.8 20.0 0.2
#define VSHARP0 params.VSHARP0
#pragma parameter VSHAR "Sharpness Definition - Vertical" 0.5 0.0 2.0 0.05
#define VSHAR params.VSHAR
#pragma parameter VAR "Vertical Anti-Ringing" 0.5 0.0 1.0 0.1
#define VAR params.VAR
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;
#define COMPAT_TEXTURE(c,d) texture(c,d)
#define SourceSize params.SourceSize
float invsqrsigma = 1.0/(2.0*SIGMA_V*SIGMA_V);
float gaussian(float x)
{
return exp(-x*x*invsqrsigma);
}
void main()
{
float f = fract(SourceSize.y * vTexCoord.y);
f = 0.5 - f;
vec2 tex = floor(SourceSize.xy * vTexCoord)*SourceSize.zw + 0.5*SourceSize.zw;
vec3 color = vec3(0.0);
vec2 dy = vec2(0.0, SourceSize.w);
float w;
float wsum = 0.0;
vec3 pixel;
float n = -SIZEV;
vec3 cmax = COMPAT_TEXTURE(Source, tex).rgb;
vec3 cmin = cmax;
float sharp = (VSHARP0 > 0.85) ? gaussian(VSHARP0) : 0.0;
float FPR = VSHARP0;
float wnorm = 1.0/(1.0-sharp);
float fpx = 0.0;
do
{
w = (gaussian(n+f) - sharp)*wnorm;
if (VSHARP0 > 0.85)
{
if (abs(n+f) > FPR) { if (n < 0.0) fpx = -(n+f+FPR)/FPR; else fpx = (n+f-FPR)/FPR; fpx = min(fpx, 1.0); }
if (abs(n) <= 2.0*FPR) { cmax = max(cmax, pixel); cmin = min(cmin, pixel); }
if (w < 0.0) w = clamp(w, mix(-0.18, 0.0, pow(fpx,VSHAR)), 0.0);
}
pixel = COMPAT_TEXTURE(Source, tex + n*dy).rgb;
color = color + w * pixel;
wsum = wsum + w;
n = n + 1.0;
} while (n <= SIZEV);
color = color / wsum;
if (VSHARP0 > 0.85) color = mix(clamp(color, 0.0, 1.0), clamp(color, cmin, cmax), VAR);
FragColor = vec4(color, 1.0);
}

View file

@ -0,0 +1,98 @@
#version 450
/*
Gaussian blur - vertical pass, dynamic range, resizable
Copyright (C) 2020 guest(r) - guest.r@gmail.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
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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float SIZEV;
float SIGMA_V;
} params;
#pragma parameter SIZEV "Vertical Blur Radius" 5.0 0.0 40.0 1.0
#define SIZEV params.SIZEV
#pragma parameter SIGMA_V "Vertical Blur Sigma" 1.0 0.1 15.0 0.05
#define SIGMA_V params.SIGMA_V
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;
#define COMPAT_TEXTURE(c,d) texture(c,d)
#define SourceSize params.SourceSize
float invsqrsigma = 1.0/(2.0*SIGMA_V*SIGMA_V);
float gaussian(float x)
{
return exp(-x*x*invsqrsigma);
}
void main()
{
float f = fract(SourceSize.y * vTexCoord.y);
f = 0.5 - f;
vec2 tex = floor(SourceSize.xy * vTexCoord)*SourceSize.zw + 0.5*SourceSize.zw;
vec3 color = vec3(0.0);
vec2 dy = vec2(0.0, SourceSize.w);
float w;
float wsum = 0.0;
vec3 pixel;
float n = -SIZEV;
do
{
pixel = COMPAT_TEXTURE(Source, tex + n*dy).rgb;
w = gaussian(n+f);
color = color + w * pixel;
wsum = wsum + w;
n = n + 1.0;
} while (n <= SIZEV);
color = color / wsum;
FragColor = vec4(color, 1.0);
}

View file

@ -54,12 +54,14 @@ layout(push_constant) uniform Push
float use_frame;
float curvature;
float wiggle_toggle;
float scanroll;
} params;
#pragma parameter use_frame "Use Frame Image" 0.0 0.0 1.0 1.0
#define use_frame params.use_frame
#pragma parameter curvature "Curvature" 2.0 0.0001 4.0 0.25
#pragma parameter wiggle_toggle "Interference" 0.0 0.0 1.0 1.0
#pragma parameter scanroll "Rolling Scanlines" 1.0 0.0 1.0 1.0
#define gl_FragCoord (vTexCoord.xy * params.OutputSize.xy)
#define backbuffer accum1
@ -176,6 +178,8 @@ void main()
vig = 1.3*pow(vig,0.5);
col *= vig;
time *= params.scanroll;
/* Scanlines */
float scans = clamp( 0.35+0.18*sin(6.0*time-curved_uv.y*resolution.y*1.5), 0.0, 1.0);
float s = pow(scans,0.9);
@ -206,7 +210,7 @@ void main()
/* Frame */
vec2 fscale = vec2( 0.026, -0.018);//vec2( -0.018, -0.013 );
uv = vec2(uv.x, 1.-uv.y);
vec4 f=texture(frametexture,uv*((1.0)+2.0*fscale)-fscale-vec2(-0.0, 0.005));
vec4 f=texture(frametexture,vTexCoord.xy);//*((1.0)+2.0*fscale)-fscale-vec2(-0.0, 0.005));
f.xyz = mix( f.xyz, vec3(0.5,0.5,0.5), 0.5 );
float fvig = clamp( -0.00+512.0*uv.x*uv.y*(1.0-uv.x)*(1.0-uv.y), 0.2, 0.8 );
col = mix( col, mix( max( col, 0.0), pow( abs( f.xyz ), vec3( 1.4 ) ) * fvig, f.w * f.w), vec3( use_frame ) );

4
cubic/b-spline-fast.slangp Executable file
View file

@ -0,0 +1,4 @@
shaders = 1
shader0 = shaders/b-spline-fast.slang
filter_linear0 = true

4
cubic/catmull-rom-fast.slangp Executable file
View file

@ -0,0 +1,4 @@
shaders = 1
shader0 = shaders/catmull-rom-fast.slang
filter_linear0 = true

View file

@ -0,0 +1,87 @@
#version 450
/*
Bicubic B-Spline 4-taps (Fast) - ported by Hyllian - 2020
The following code is licensed under the MIT license: https://gist.github.com/TheRealMJP/bc503b0b87b643d3505d41eab8b332ae
Samples a texture with B-Spline filtering, using only 4 texture fetches instead of 16.
See http://vec3.ca/bicubic-filtering-in-fewer-taps/ for more details
ATENTION: This code only work using LINEAR filter sampling set on Retroarch!
*/
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;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
void main()
{
// We're going to sample a a 4x4 grid of texels surrounding the target UV coordinate. We'll do this by rounding
// down the sample location to get the exact center of our "starting" texel. The starting texel will be at
// location [1, 1] in the grid, where [0, 0] is the top left corner.
vec2 samplePos = vTexCoord * params.SourceSize.xy;
vec2 tc = floor(samplePos - 0.5) + 0.5;
// Compute the fractional offset from our starting texel to our original sample location, which we'll
// feed into the B-Spline function to get our filter weights.
vec2 f = samplePos - tc;
vec2 f2 = f * f;
vec2 f3 = f2 * f;
// Compute the B-Spline weights using the fractional offset that we calculated earlier.
// These equations are pre-expanded based on our knowledge of where the texels will be located,
// which lets us avoid having to evaluate a piece-wise function.
vec2 w0 = f2 - 0.5 * (f3 + f);
vec2 w1 = 1.5 * f3 - 2.5 * f2 + 1.0;
vec2 w2 = -1.5 * f3 + 2. * f2 + 0.5 * f;
// vec2 w3 = 0.5 * (f3 - f2);
vec2 w3 = 1.0 - w0 - w1 - w2; // The sum of weights must be one.
// Work out weighting factors and sampling offsets that will let us use bilinear filtering to
// simultaneously evaluate the 2 samples each from the 4x4 grid.
vec2 s0 = w0 + w1;
vec2 s1 = w2 + w3;
vec2 f0 = w1 / s0;
vec2 f1 = w3 / s1;
// Compute the final UV coordinates we'll use for sampling the texture
vec2 t0 = tc - 1. + f0;
vec2 t1 = tc + 1. + f1;
t0 *= params.SourceSize.zw;
t1 *= params.SourceSize.zw;
vec4 c0 = texture(Source, vec2(t0.x, t0.y));
vec4 c1 = texture(Source, vec2(t1.x, t0.y));
vec4 c2 = texture(Source, vec2(t0.x, t1.y));
vec4 c3 = texture(Source, vec2(t1.x, t1.y));
FragColor = (c0 * s0.x + c1 * s1.x) * s0.y + (c2 * s0.x + c3 * s1.x) * s1.y;
}

View file

@ -0,0 +1,103 @@
#version 450
/*
Bicubic Catmull-Rom 9 taps (Fast) - ported by Hyllian - 2020
The following code is licensed under the MIT license: https://gist.github.com/TheRealMJP/bc503b0b87b643d3505d41eab8b332ae
Ported from code: https://gist.github.com/TheRealMJP/c83b8c0f46b63f3a88a5986f4fa982b1
Samples a texture with Catmull-Rom filtering, using 9 texture fetches instead of 16.
See http://vec3.ca/bicubic-filtering-in-fewer-taps/ for more details
ATENTION: This code only work using LINEAR filter sampling set on Retroarch!
*/
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
} params;
#define mul(c,d) (d*c)
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;
void main()
{
// We're going to sample a a 4x4 grid of texels surrounding the target UV coordinate. We'll do this by rounding
// down the sample location to get the exact center of our "starting" texel. The starting texel will be at
// location [1, 1] in the grid, where [0, 0] is the top left corner.
vec2 samplePos = vTexCoord * params.SourceSize.xy;
vec2 texPos1 = floor(samplePos - 0.5) + 0.5;
// Compute the fractional offset from our starting texel to our original sample location, which we'll
// feed into the Catmull-Rom spline function to get our filter weights.
vec2 f = samplePos - texPos1;
// Compute the Catmull-Rom weights using the fractional offset that we calculated earlier.
// These equations are pre-expanded based on our knowledge of where the texels will be located,
// which lets us avoid having to evaluate a piece-wise function.
vec2 w0 = f * (-0.5 + f * (1.0 - 0.5 * f));
vec2 w1 = 1.0 + f * f * (-2.5 + 1.5 * f);
vec2 w2 = f * (0.5 + f * (2.0 - 1.5 * f));
vec2 w3 = f * f * (-0.5 + 0.5 * f);
// vec2 w3 = 1.0 - w0 - w1 - w2;
// Work out weighting factors and sampling offsets that will let us use bilinear filtering to
// simultaneously evaluate the middle 2 samples from the 4x4 grid.
vec2 w12 = w1 + w2;
vec2 offset12 = w2 / (w1 + w2);
// Compute the final UV coordinates we'll use for sampling the texture
vec2 texPos0 = texPos1 - 1.;
vec2 texPos3 = texPos1 + 2.;
vec2 texPos12 = texPos1 + offset12;
texPos0 *= params.SourceSize.zw;
texPos3 *= params.SourceSize.zw;
texPos12 *= params.SourceSize.zw;
vec4 c00 = texture(Source, vec2(texPos0.x, texPos0.y));
vec4 c10 = texture(Source, vec2(texPos12.x, texPos0.y));
vec4 c20 = texture(Source, vec2(texPos3.x, texPos0.y));
vec4 c01 = texture(Source, vec2(texPos0.x, texPos12.y));
vec4 c11 = texture(Source, vec2(texPos12.x, texPos12.y));
vec4 c21 = texture(Source, vec2(texPos3.x, texPos12.y));
vec4 c02 = texture(Source, vec2(texPos0.x, texPos3.y));
vec4 c12 = texture(Source, vec2(texPos12.x, texPos3.y));
vec4 c22 = texture(Source, vec2(texPos3.x, texPos3.y));
vec3 wx = vec3(w0.x, w12.x, w3.x);
vec3 wy = vec3(w0.y, w12.y, w3.y);
vec4 c1 = mul(wx, mat3x4(c00, c10, c20));
vec4 c2 = mul(wx, mat3x4(c01, c11, c21));
vec4 c3 = mul(wx, mat3x4(c02, c12, c22));
FragColor = mul(wy, mat3x4(c1, c2, c3));
}

View file

@ -0,0 +1,6 @@
shaders = 1
shader0 = shaders/sgenpt-mix.slang
filter_linear0 = false
scale_type0 = source
scale0 = 1.0

View file

@ -0,0 +1,104 @@
#version 450
/*
SGENPT-MIX - Sega Genesis Pseudo Transparency Mixer Shader - v4
2011-2020 Hyllian - sergiogdb@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float SGPT_SHARPNESS;
float SGPT_BLEND_OPTION;
} params;
#pragma parameter SGPT_SHARPNESS "SGENPT-MIX Sharpness" 1.0 0.0 1.0 0.1
#pragma parameter SGPT_BLEND_OPTION "OFF | Transparency | Checkerboard" 1.0 0.0 2.0 1.0
#define SGPT_SHARPNESS params.SGPT_SHARPNESS
#define SGPT_BLEND_OPTION params.SGPT_BLEND_OPTION
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;
void main()
{
vec2 dx = vec2(1.0, 0.0)*params.SourceSize.zw;
vec2 dy = vec2(0.0, 1.0)*params.SourceSize.zw;
// Reading the texels.
vec3 C = texture(Source, vTexCoord ).xyz;
vec3 L = texture(Source, vTexCoord -dx).xyz;
vec3 R = texture(Source, vTexCoord +dx).xyz;
vec3 U = texture(Source, vTexCoord -dy).xyz;
vec3 D = texture(Source, vTexCoord +dy).xyz;
vec3 color = C;
if (SGPT_BLEND_OPTION > 0.0)
{
// Get min/max samples
vec3 min_sample = min(C, max(L, R));
vec3 max_sample = max(C, min(L, R));
color = 0.5*C + 0.25*(L + R);
if (SGPT_BLEND_OPTION > 1.0)
{
// Get min/max samples
min_sample = max(min_sample, min(C, max(U, D)));
max_sample = min(max_sample, max(C, min(U, D)));
color = 0.5*C + 0.125*(L + R + U + D);
}
// Sharpness control
vec3 aux = color;
color = clamp(color, min_sample, max_sample);
color = mix(aux, color, SGPT_SHARPNESS);
}
FragColor = vec4(color, 1.0);
}

View file

@ -52,7 +52,7 @@ void main()
float tick = registers.FrameCount;
// assume anything with a vertical resolution greater than 400 lines is interlaced
if (registers.SourceSize.y > 400.0)
if (registers.OriginalSize.y > 400.0)
{y = registers.SourceSize.y * vTexCoord.y + (tick * registers.enable_480i) + registers.top_field_first;}
else
{y = 2.000001 * registers.SourceSize.y * vTexCoord.y + registers.top_field_first;}

View file

@ -1,224 +1,186 @@
# IMPORTANT:
# Shader passes need to know details about the image in the mask_texture LUT
# files, so set the following constants in user-cgp-constants.h accordingly:
# 1.) mask_triads_per_tile = (number of horizontal triads in mask texture LUT's)
# 2.) mask_texture_small_size = (texture size of mask*texture_small LUT's)
# 3.) mask_texture_large_size = (texture size of mask*texture_large LUT's)
# 4.) mask_grille_avg_color = (avg. brightness of mask_grille_texture* LUT's, in [0, 1])
# 5.) mask_slot_avg_color = (avg. brightness of mask_slot_texture* LUT's, in [0, 1])
# 6.) mask_shadow_avg_color = (avg. brightness of mask_shadow_texture* LUT's, in [0, 1])
# Shader passes also need to know certain scales set in this .slangp, but their
# compilation model doesn't currently allow the .slangp file to tell them. Make
# sure to set the following constants in user-cgp-constants.h accordingly too:
# 1.) bloom_approx_scale_x = scale_x2
# 2.) mask_resize_viewport_scale = float2(scale_x6, scale_y5)
# Finally, shader passes need to know the value of geom_max_aspect_ratio used to
# calculate scale_y6 (among other values):
# 1.) geom_max_aspect_ratio = (geom_max_aspect_ratio used to calculate scale_y5)
shaders = "13"
# Set an identifier, filename, and sampling traits for the phosphor mask texture.
# Load an aperture grille, slot mask, and an EDP shadow mask, and load a small
# non-mipmapped version and a large mipmapped version.
# TODO: Test masks in other directories.
textures = "mask_grille_texture_small;mask_grille_texture_large;mask_slot_texture_small;mask_slot_texture_large;mask_shadow_texture_small;mask_shadow_texture_large;SamplerLUT1;SamplerLUT2"
mask_grille_texture_small = "../crt/shaders/crt-royale/TileableLinearApertureGrille15Wide8And5d5SpacingResizeTo64.png"
mask_grille_texture_large = "../crt/shaders/crt-royale/TileableLinearApertureGrille15Wide8And5d5Spacing.png"
mask_slot_texture_small = "../crt/shaders/crt-royale/TileableLinearSlotMaskTall15Wide9And4d5Horizontal9d14VerticalSpacingResizeTo64.png"
mask_slot_texture_large = "../crt/shaders/crt-royale/TileableLinearSlotMaskTall15Wide9And4d5Horizontal9d14VerticalSpacing.png"
mask_shadow_texture_small = "../crt/shaders/crt-royale/TileableLinearShadowMaskEDPResizeTo64.png"
mask_shadow_texture_large = "../crt/shaders/crt-royale/TileableLinearShadowMaskEDP.png"
mask_grille_texture_small_wrap_mode = "repeat"
mask_grille_texture_large_wrap_mode = "repeat"
mask_slot_texture_small_wrap_mode = "repeat"
mask_slot_texture_large_wrap_mode = "repeat"
mask_shadow_texture_small_wrap_mode = "repeat"
mask_shadow_texture_large_wrap_mode = "repeat"
mask_grille_texture_small_linear = "true"
mask_grille_texture_large_linear = "true"
mask_slot_texture_small_linear = "true"
mask_slot_texture_large_linear = "true"
mask_shadow_texture_small_linear = "true"
mask_shadow_texture_large_linear = "true"
mask_grille_texture_small_mipmap = "false" # Mipmapping causes artifacts with manually resized masks without tex2Dlod
mask_grille_texture_large_mipmap = "true" # Essential for hardware-resized masks
mask_slot_texture_small_mipmap = "false" # Mipmapping causes artifacts with manually resized masks without tex2Dlod
mask_slot_texture_large_mipmap = "true" # Essential for hardware-resized masks
mask_shadow_texture_small_mipmap = "false" # Mipmapping causes artifacts with manually resized masks without tex2Dlod
mask_shadow_texture_large_mipmap = "true" # Essential for hardware-resized masks
SamplerLUT1 = "../reshade/shaders/LUT/Kurozumi_64_D65_Rec601.png"
SamplerLUT1_linear = true
SamplerLUT2 = "../reshade/shaders/LUT/Kurozumi_64_D93_Rec601.png"
SamplerLUT2_linear = true
# Pass0: LUT to correct screen colors.
# Digital Displays different color coordinates for primaries than CRTs (Rec709 vs Rec601).
shader0 = "../reshade/shaders/LUT/multiLUT.slang"
# Pass1: Linearize the input based on CRT gamma and bob interlaced fields.
# (Bobbing ensures we can immediately blur without getting artifacts.)
shader1 = "../crt/shaders/crt-royale/src/crt-royale-first-pass-linearize-crt-gamma-bob-fields.slang"
alias1 = "ORIG_LINEARIZED"
shader0 = "shaders_slang/misc/grade.slang"
wrap_mode0 = "clamp_to_border"
mipmap_input0 = "false"
alias0 = ""
float_framebuffer0 = "false"
srgb_framebuffer0 = "false"
shader1 = "shaders_slang/crt/shaders/crt-royale/src/crt-royale-first-pass-linearize-crt-gamma-bob-fields.slang"
filter_linear1 = "false"
scale_type1 = "source"
scale1 = "1.0"
wrap_mode1 = "clamp_to_border"
mipmap_input1 = "false"
alias1 = "ORIG_LINEARIZED"
float_framebuffer1 = "false"
srgb_framebuffer1 = "true"
# Pass2: Resample interlaced (and misconverged) scanlines vertically.
# Separating vertical/horizontal scanline sampling is faster: It lets us
# consider more scanlines while calculating weights for fewer pixels, and
# it reduces our samples from vertical*horizontal to vertical+horizontal.
# This has to come right after ORIG_LINEARIZED, because there's no
# "original_source" scale_type we can use later.
shader2 = "../crt/shaders/crt-royale/src/crt-royale-scanlines-vertical-interlacing.slang"
alias2 = "VERTICAL_SCANLINES"
scale_type_x1 = "source"
scale_x1 = "1.000000"
scale_type_y1 = "source"
scale_y1 = "1.000000"
shader2 = "shaders_slang/crt/shaders/crt-royale/src/crt-royale-scanlines-vertical-interlacing.slang"
filter_linear2 = "true"
scale_type_x2 = "source"
scale_x2 = "1.0"
scale_type_y2 = "viewport"
scale_y2 = "1.0"
#float_framebuffer2 = "true"
wrap_mode2 = "clamp_to_border"
mipmap_input2 = "false"
alias2 = "VERTICAL_SCANLINES"
float_framebuffer2 = "false"
srgb_framebuffer2 = "true"
# Pass3: Do a small resize blur of ORIG_LINEARIZED at an absolute size, and
# account for convergence offsets. We want to blur a predictable portion of the
# screen to match the phosphor bloom, and absolute scale works best for
# reliable results with a fixed-size bloom. Picking a scale is tricky:
# a.) 400x300 is a good compromise for the "fake-bloom" version: It's low enough
# to blur high-res/interlaced sources but high enough that resampling
# doesn't smear low-res sources too much.
# b.) 320x240 works well for the "real bloom" version: It's 1-1.5% faster, and
# the only noticeable visual difference is a larger halation spread (which
# may be a good thing for people who like to crank it up).
# Note the 4:4 aspect ratio assumes the input has cropped geom_overscan (so it's
# *intended* for an ~4:4 aspect ratio).
shader3 = "../crt/shaders/crt-royale/src/crt-royale-bloom-approx.slang"
alias3 = "BLOOM_APPROX"
scale_type_x2 = "source"
scale_x2 = "1.000000"
scale_type_y2 = "viewport"
scale_y2 = "1.000000"
shader3 = "shaders_slang/crt/shaders/crt-royale/src/crt-royale-bloom-approx.slang"
filter_linear3 = "true"
scale_type3 = "absolute"
scale_x3 = "320"
scale_y3 = "240"
wrap_mode3 = "clamp_to_border"
mipmap_input3 = "false"
alias3 = "BLOOM_APPROX"
float_framebuffer3 = "false"
srgb_framebuffer3 = "true"
# Pass4: Vertically blur the input for halation and refractive diffusion.
# Base this on BLOOM_APPROX: This blur should be small and fast, and blurring
# a constant portion of the screen is probably physically correct if the
# viewport resolution is proportional to the simulated CRT size.
shader4 = "../blurs/blur5fast-vertical.slang"
scale_type_x3 = "absolute"
scale_x3 = "320"
scale_type_y3 = "absolute"
scale_y3 = "240"
shader4 = "shaders_slang/blurs/blur5fast-vertical.slang"
filter_linear4 = "true"
scale_type4 = "source"
scale4 = "1.0"
wrap_mode4 = "clamp_to_border"
mipmap_input4 = "false"
alias4 = ""
float_framebuffer4 = "false"
srgb_framebuffer4 = "true"
# Pass5: Horizontally blur the input for halation and refractive diffusion.
# Note: Using a one-pass 9x10 blur is about 1% slower.
shader5 = "../blurs/blur5fast-horizontal.slang"
alias5 = "HALATION_BLUR"
scale_type_x4 = "source"
scale_x4 = "1.000000"
scale_type_y4 = "source"
scale_y4 = "1.000000"
shader5 = "shaders_slang/blurs/blur5fast-horizontal.slang"
filter_linear5 = "true"
scale_type5 = "source"
scale5 = "1.0"
wrap_mode5 = "clamp_to_border"
mipmap_input5 = "false"
alias5 = "HALATION_BLUR"
float_framebuffer5 = "false"
srgb_framebuffer5 = "true"
# Pass6: Lanczos-resize the phosphor mask vertically. Set the absolute
# scale_x5 == mask_texture_small_size.x (see IMPORTANT above). Larger scales
# will blur, and smaller scales could get nasty. The vertical size must be
# based on the viewport size and calculated carefully to avoid artifacts later.
# First calculate the minimum number of mask tiles we need to draw.
# Since curvature is computed after the scanline masking pass:
# num_resized_mask_tiles = 2.0;
# If curvature were computed in the scanline masking pass (it's not):
# max_mask_texel_border = ~3.0 * (1/3.0 + 4.0*sqrt(2.0) + 0.6 + 1.0);
# max_mask_tile_border = max_mask_texel_border/
# (min_resized_phosphor_triad_size * mask_triads_per_tile);
# num_resized_mask_tiles = max(2.0, 1.0 + max_mask_tile_border * 2.0);
# At typical values (triad_size >= 2.0, mask_triads_per_tile == 8):
# num_resized_mask_tiles = ~3.8
# Triad sizes are given in horizontal terms, so we need geom_max_aspect_ratio
# to relate them to vertical resolution. The widest we expect is:
# geom_max_aspect_ratio = 4.0/3.0 # Note: Shader passes need to know this!
# The fewer triads we tile across the screen, the larger each triad will be as a
# fraction of the viewport size, and the larger scale_y6 must be to draw a full
# num_resized_mask_tiles. Therefore, we must decide the smallest number of
# triads we'll guarantee can be displayed on screen. We'll set this according
# to 3-pixel triads at 768p resolution (the lowest anyone's likely to use):
# min_allowed_viewport_triads = 768.0*geom_max_aspect_ratio / 3.0 = 341.333333
# Now calculate the viewport scale that ensures we can draw resized_mask_tiles:
# min_scale_x = resized_mask_tiles * mask_triads_per_tile /
# min_allowed_viewport_triads
# scale_y6 = geom_max_aspect_ratio * min_scale_x
# # Some code might depend on equal scales:
# scale_x7 = scale_y5
# Given our default geom_max_aspect_ratio and min_allowed_viewport_triads:
# scale_y6 = 4.0/3.0 * 2.0/(341.33334 / 8.0) = 0.0625
# IMPORTANT: The scales MUST be calculated in this way. If you wish to change
# geom_max_aspect_ratio, update that constant in user-cgp-constants.h!
shader6 = "../crt/shaders/crt-royale/src/crt-royale-mask-resize-vertical.slang"
scale_type_x5 = "source"
scale_x5 = "1.000000"
scale_type_y5 = "source"
scale_y5 = "1.000000"
shader6 = "shaders_slang/crt/shaders/crt-royale/src/crt-royale-mask-resize-vertical.slang"
filter_linear6 = "true"
wrap_mode6 = "clamp_to_border"
mipmap_input6 = "false"
alias6 = ""
float_framebuffer6 = "false"
srgb_framebuffer6 = "false"
scale_type_x6 = "absolute"
scale_x6 = "64"
scale_type_y6 = "viewport"
scale_y6 = "0.0625" # Safe for >= 341.334 horizontal triads at viewport size
#srgb_framebuffer6 = "false" # mask_texture is already assumed linear
# Pass7: Lanczos-resize the phosphor mask horizontally. scale_x7 = scale_y5.
# TODO: Check again if the shaders actually require equal scales.
shader7 = "../crt/shaders/crt-royale/src/crt-royale-mask-resize-horizontal.slang"
alias7 = "MASK_RESIZE"
scale_y6 = "0.062500"
shader7 = "shaders_slang/crt/shaders/crt-royale/src/crt-royale-mask-resize-horizontal.slang"
filter_linear7 = "false"
wrap_mode7 = "clamp_to_border"
mipmap_input7 = "false"
alias7 = "MASK_RESIZE"
float_framebuffer7 = "false"
srgb_framebuffer7 = "false"
scale_type_x7 = "viewport"
scale_x7 = "0.0625"
scale_x7 = "0.062500"
scale_type_y7 = "source"
scale_y7 = "1.0"
#srgb_framebuffer7 = "false" # mask_texture is already assumed linear
# Pass8: Resample (misconverged) scanlines horizontally, apply halation, and
# apply the phosphor mask.
shader8 = "../crt/shaders/crt-royale/src/crt-royale-scanlines-horizontal-apply-mask.slang"
scale_y7 = "1.000000"
shader8 = "shaders_slang/crt/shaders/crt-royale/src/crt-royale-scanlines-horizontal-apply-mask.slang"
filter_linear8 = "true"
wrap_mode8 = "clamp_to_border"
mipmap_input8 = "false"
alias8 = "MASKED_SCANLINES"
filter_linear8 = "true" # This could just as easily be nearest neighbor.
scale_type8 = "viewport"
scale8 = "1.0"
#float_framebuffer8 = "true"
float_framebuffer8 = "false"
srgb_framebuffer8 = "true"
# Pass 9: Compute a brightpass. This will require reading the final mask.
shader9 = "../crt/shaders/crt-royale/src/crt-royale-brightpass.slang"
scale_type_x8 = "viewport"
scale_x8 = "1.000000"
scale_type_y8 = "viewport"
scale_y8 = "1.000000"
shader9 = "shaders_slang/crt/shaders/crt-royale/src/crt-royale-brightpass.slang"
filter_linear9 = "true"
wrap_mode9 = "clamp_to_border"
mipmap_input9 = "false"
alias9 = "BRIGHTPASS"
filter_linear9 = "true" # This could just as easily be nearest neighbor.
scale_type9 = "viewport"
scale9 = "1.0"
float_framebuffer9 = "false"
srgb_framebuffer9 = "true"
# Pass 10: Blur the brightpass vertically
shader10 = "../crt/shaders/crt-royale/src/crt-royale-bloom-vertical.slang"
filter_linear10 = "true" # This could just as easily be nearest neighbor.
scale_type10 = "source"
scale10 = "1.0"
scale_type_x9 = "viewport"
scale_x9 = "1.000000"
scale_type_y9 = "viewport"
scale_y9 = "1.000000"
shader10 = "shaders_slang/crt/shaders/crt-royale/src/crt-royale-bloom-vertical.slang"
filter_linear10 = "true"
wrap_mode10 = "clamp_to_border"
mipmap_input10 = "false"
alias10 = ""
float_framebuffer10 = "false"
srgb_framebuffer10 = "true"
# Pass 11: Blur the brightpass horizontally and combine it with the dimpass:
shader11 = "../crt/shaders/crt-royale/src/crt-royale-bloom-horizontal-reconstitute.slang"
scale_type_x10 = "source"
scale_x10 = "1.000000"
scale_type_y10 = "source"
scale_y10 = "1.000000"
shader11 = "shaders_slang/crt/shaders/crt-royale/src/crt-royale-bloom-horizontal-reconstitute.slang"
filter_linear11 = "true"
scale_type11 = "source"
scale11 = "1.0"
wrap_mode11 = "clamp_to_border"
mipmap_input11 = "false"
alias11 = ""
float_framebuffer11 = "false"
srgb_framebuffer11 = "true"
# Pass 12: Compute curvature/AA:
shader12 = "../crt/shaders/crt-royale/src/crt-royale-geometry-aa-last-pass.slang"
scale_type_x11 = "source"
scale_x11 = "1.000000"
scale_type_y11 = "source"
scale_y11 = "1.000000"
shader12 = "shaders_slang/crt/shaders/crt-royale/src/crt-royale-geometry-aa-last-pass.slang"
filter_linear12 = "true"
scale_type12 = "viewport"
wrap_mode12 = "clamp_to_border"
mipmap_input12 = "true"
texture_wrap_mode12 = "clamp_to_edge"
parameters = "crt_gamma;lcd_gamma;levels_contrast;halation_weight;diffusion_weight;bloom_underestimate_levels;bloom_excess;beam_min_sigma;beam_max_sigma;beam_spot_power;beam_min_shape;beam_max_shape;beam_shape_power;beam_horiz_filter;beam_horiz_sigma;beam_horiz_linear_rgb_weight;convergence_offset_x_r;convergence_offset_x_g;convergence_offset_x_b;convergence_offset_y_r;convergence_offset_y_g;convergence_offset_y_b;mask_type;mask_sample_mode_desired;mask_specify_num_triads;mask_triad_size_desired;mask_num_triads_desired;aa_subpixel_r_offset_x_runtime;aa_subpixel_r_offset_y_runtime;aa_cubic_c;aa_gauss_sigma;geom_mode_runtime;geom_radius;geom_view_dist;geom_tilt_angle_x;geom_tilt_angle_y;geom_aspect_ratio_x;geom_aspect_ratio_y;geom_overscan_x;geom_overscan_y;border_size;border_darkness;border_compress;interlace_bff;interlace_1080i"
alias12 = ""
float_framebuffer12 = "false"
srgb_framebuffer12 = "false"
scale_type_x12 = "viewport"
scale_x12 = "1.000000"
scale_type_y12 = "viewport"
scale_y12 = "1.000000"
parameters = "g_gamma_in;g_signal_type;g_gamma_type;g_crtgamut;g_space_out;g_hue_degrees;g_I_SHIFT;g_Q_SHIFT;g_I_MUL;g_Q_MUL;g_lum_fix;g_vignette;g_vstr;g_vpower;g_lum;g_cntrst;g_mid;wp_temperature;g_sat;g_vibr;g_satr;g_satg;g_satb;g_lift;blr;blg;blb;wlr;wlg;wlb;rg;rb;gr;gb;br;bg;LUT_Size1;LUT1_toggle;LUT_Size2;LUT2_toggle;crt_gamma;lcd_gamma;levels_contrast;halation_weight;diffusion_weight;bloom_underestimate_levels;bloom_excess;beam_min_sigma;beam_max_sigma;beam_spot_power;beam_min_shape;beam_max_shape;beam_shape_power;beam_horiz_filter;beam_horiz_sigma;beam_horiz_linear_rgb_weight;convergence_offset_x_r;convergence_offset_x_g;convergence_offset_x_b;convergence_offset_y_r;convergence_offset_y_g;convergence_offset_y_b;mask_type;mask_sample_mode_desired;mask_specify_num_triads;mask_triad_size_desired;mask_num_triads_desired;aa_subpixel_r_offset_x_runtime;aa_subpixel_r_offset_y_runtime;aa_cubic_c;aa_gauss_sigma;geom_mode_runtime;geom_radius;geom_view_dist;geom_tilt_angle_x;geom_tilt_angle_y;geom_aspect_ratio_x;geom_aspect_ratio_y;geom_overscan_x;geom_overscan_y;border_size;border_darkness;border_compress;interlace_detect_toggle;interlace_bff;interlace_1080i"
g_gamma_in = "2.400000"
g_signal_type = "0.000000"
g_gamma_type = "1.000000"
g_crtgamut = "1.000000"
g_space_out = "-1.000000"
g_hue_degrees = "0.000000"
g_I_SHIFT = "0.000000"
g_Q_SHIFT = "0.000000"
g_I_MUL = "1.000000"
g_Q_MUL = "1.000000"
g_lum_fix = "0.000000"
g_vignette = "0.000000"
g_vstr = "40.000000"
g_vpower = "0.200000"
g_lum = "0.000000"
g_cntrst = "0.000000"
g_mid = "0.500000"
wp_temperature = "6504.000000"
g_sat = "0.000000"
g_vibr = "0.000000"
g_satr = "0.000000"
g_satg = "0.000000"
g_satb = "0.000000"
g_lift = "0.000000"
blr = "0.000000"
blg = "0.000000"
blb = "0.000000"
wlr = "1.000000"
wlg = "1.000000"
wlb = "1.000000"
rg = "0.000000"
rb = "0.000000"
gr = "0.000000"
gb = "0.000000"
br = "0.000000"
bg = "0.000000"
crt_gamma = "2.400000"
lcd_gamma = "2.400000"
levels_contrast = "0.670000"
halation_weight = "0.003700"
diffusion_weight = "0.001100"
bloom_underestimate_levels = "0.650000"
bloom_excess = "0.020000"
bloom_underestimate_levels = "0.680000"
bloom_excess = "0.000000"
beam_min_sigma = "0.020000"
beam_max_sigma = "0.160000"
beam_spot_power = "0.380000"
@ -255,5 +217,31 @@ geom_overscan_y = "1.000000"
border_size = "0.005000"
border_darkness = "0.000000"
border_compress = "2.500000"
interlace_detect_toggle = "1.000000"
interlace_bff = "0.000000"
interlace_1080i = "0.000000"
textures = "mask_grille_texture_small;mask_grille_texture_large;mask_slot_texture_small;mask_slot_texture_large;mask_shadow_texture_small;mask_shadow_texture_large"
mask_grille_texture_small = "shaders_slang/crt/shaders/crt-royale/TileableLinearApertureGrille15Wide8And5d5SpacingResizeTo64.png"
mask_grille_texture_small_linear = "true"
mask_grille_texture_small_wrap_mode = "repeat"
mask_grille_texture_small_mipmap = "false"
mask_grille_texture_large = "shaders_slang/crt/shaders/crt-royale/TileableLinearApertureGrille15Wide8And5d5Spacing.png"
mask_grille_texture_large_linear = "true"
mask_grille_texture_large_wrap_mode = "repeat"
mask_grille_texture_large_mipmap = "true"
mask_slot_texture_small = "shaders_slang/crt/shaders/crt-royale/TileableLinearSlotMaskTall15Wide9And4d5Horizontal9d14VerticalSpacingResizeTo64.png"
mask_slot_texture_small_linear = "true"
mask_slot_texture_small_wrap_mode = "repeat"
mask_slot_texture_small_mipmap = "false"
mask_slot_texture_large = "shaders_slang/crt/shaders/crt-royale/TileableLinearSlotMaskTall15Wide9And4d5Horizontal9d14VerticalSpacing.png"
mask_slot_texture_large_linear = "true"
mask_slot_texture_large_wrap_mode = "repeat"
mask_slot_texture_large_mipmap = "true"
mask_shadow_texture_small = "shaders_slang/crt/shaders/crt-royale/TileableLinearShadowMaskEDPResizeTo64.png"
mask_shadow_texture_small_linear = "true"
mask_shadow_texture_small_wrap_mode = "repeat"
mask_shadow_texture_small_mipmap = "false"
mask_shadow_texture_large = "shaders_slang/crt/shaders/crt-royale/TileableLinearShadowMaskEDP.png"
mask_shadow_texture_large_linear = "true"
mask_shadow_texture_large_wrap_mode = "repeat"
mask_shadow_texture_large_mipmap = "true"

49
sharpen/Anime4k.slangp Executable file
View file

@ -0,0 +1,49 @@
shaders = 4
shader0 = "shaders/anime4k/anime4k-compute-lum.slang"
filter_linear0 = "false"
wrap_mode0 = "clamp_to_border"
mipmap_input0 = "false"
alias0 = ""
float_framebuffer0 = "false"
srgb_framebuffer0 = "false"
scale_type_x0 = "source"
scale_x0 = "1.000000"
scale_type_y0 = "source"
scale_y0 = "1.000000"
shader1 = "shaders/anime4k/anime4k-push.slang"
filter_linear1 = "false"
wrap_mode1 = "clamp_to_border"
mipmap_input1 = "false"
alias1 = ""
float_framebuffer1 = "false"
srgb_framebuffer1 = "false"
scale_type_x1 = "source"
scale_x1 = "1.000000"
scale_type_y1 = "source"
scale_y1 = "1.000000"
shader2 = "shaders/anime4k/anime4k-compute-gradient.slang"
filter_linear2 = "false"
wrap_mode2 = "clamp_to_border"
mipmap_input2 = "false"
alias2 = ""
float_framebuffer2 = "false"
srgb_framebuffer2 = "false"
scale_type_x2 = "source"
scale_x2 = "1.000000"
scale_type_y2 = "source"
scale_y2 = "1.000000"
shader3 = "shaders/anime4k/anime4k-pushgrad-weak.slang"
filter_linear3 = "false"
wrap_mode3 = "clamp_to_border"
mipmap_input3 = "false"
alias3 = ""
float_framebuffer3 = "false"
srgb_framebuffer3 = "false"
scale_type_x3 = "source"
scale_x3 = "1.000000"
scale_type_y3 = "source"
scale_y3 = "1.000000"

View file

@ -0,0 +1,90 @@
#version 450
// MIT License
// Copyright (c) 2019 bloc97
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
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 * 1.0001;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
void main()
{
float dx = params.SourceSize.z;
float dy = params.SourceSize.w;
vec4 c0 = texture(Source, vTexCoord);
//[tl t tr]
//[ l r]
//[bl b br]
float t = texture(Source, vTexCoord + vec2( 0, -dy)).a;
float tl = texture(Source, vTexCoord + vec2(-dx, -dy)).a;
float tr = texture(Source, vTexCoord + vec2( dx, -dy)).a;
float l = texture(Source, vTexCoord + vec2(-dx, 0)).a;
float r = texture(Source, vTexCoord + vec2( dx, 0)).a;
float b = texture(Source, vTexCoord + vec2( 0, dy)).a;
float bl = texture(Source, vTexCoord + vec2(-dx, dy)).a;
float br = texture(Source, vTexCoord + vec2( dx, dy)).a;
//Horizontal Gradient
//[-1 0 1]
//[-2 0 2]
//[-1 0 1]
float xgrad = (-tl + tr - l - l + r + r - bl + br);
//Vertical Gradient
//[-1 -2 -1]
//[ 0 0 0]
//[ 1 2 1]
float ygrad = (-tl - t - t - tr + bl + b + b + br);
//Computes the luminance's gradient and saves it in the unused alpha channel
FragColor = vec4(c0.r, c0.g, c0.b, 1 - clamp(sqrt(xgrad * xgrad + ygrad * ygrad), 0, 1));
}

View file

@ -0,0 +1,45 @@
#version 450
/*
Anime4k - Luma shader - ported by Hyllian - 2020
*/
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;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
void main()
{
vec4 c0 = texture(Source, vTexCoord);
//Quick luminance approximation
float lum = (c0.r + c0[0].r + c0.g + c0.g + c0.g + c0.b) / 6;
//Computes the luminance and saves it in the unused alpha channel
FragColor = vec4(c0.r, c0.g, c0.b, lum);
}

View file

@ -0,0 +1,153 @@
#version 450
// MIT License
// Copyright (c) 2019 bloc97
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float STRENGTH_PUSH, STRENGTH_GRAD;
} params;
#pragma parameter STRENGTH_PUSH "Luminance strength" 0.3 0.0 1.0 0.1
#define STRENGTH_PUSH params.STRENGTH_PUSH
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;
float min3(vec4 a, vec4 b, vec4 c) {
return min(min(a.a, b.a), c.a);
}
float max3(vec4 a, vec4 b, vec4 c) {
return max(max(a.a, b.a), c.a);
}
vec4 getLargest(vec4 cc, vec4 lightestColor, vec4 a, vec4 b, vec4 c) {
vec4 newColor = cc * (1 - STRENGTH_PUSH) + ((a + b + c) / 3) * STRENGTH_PUSH;
// vec4 newColor = lerp(cc, ((a + b + c) / 3), STRENGTH_PUSH);
if (newColor.a > lightestColor.a) {
return newColor;
}
return lightestColor;
}
void main()
{
float dx = params.SourceSize.z;
float dy = params.SourceSize.w;
vec4 cc = texture(Source, vTexCoord); //Current Color
vec4 t = texture(Source, vTexCoord + vec2( 0, -dy));
vec4 tl = texture(Source, vTexCoord + vec2(-dx, -dy));
vec4 tr = texture(Source, vTexCoord + vec2( dx, -dy));
vec4 l = texture(Source, vTexCoord + vec2(-dx, 0));
vec4 r = texture(Source, vTexCoord + vec2( dx, 0));
vec4 b = texture(Source, vTexCoord + vec2( 0, dy));
vec4 bl = texture(Source, vTexCoord + vec2(-dx, dy));
vec4 br = texture(Source, vTexCoord + vec2( dx, dy));
vec4 lightestColor = cc;
//Kernel 0 and 4
float maxDark = max3(br, b, bl);
float minLight = min3(tl, t, tr);
if (minLight > cc.a && minLight > maxDark) {
lightestColor = getLargest(cc, lightestColor, tl, t, tr);
} else {
maxDark = max3(tl, t, tr);
minLight = min3(br, b, bl);
if (minLight > cc.a && minLight > maxDark) {
lightestColor = getLargest(cc, lightestColor, br, b, bl);
}
}
//Kernel 1 and 5
maxDark = max3(cc, l, b);
minLight = min3(r, t, tr);
if (minLight > maxDark) {
lightestColor = getLargest(cc, lightestColor, r, t, tr);
} else {
maxDark = max3(cc, r, t);
minLight = min3(bl, l, b);
if (minLight > maxDark) {
lightestColor = getLargest(cc, lightestColor, bl, l, b);
}
}
//Kernel 2 and 6
maxDark = max3(l, tl, bl);
minLight = min3(r, br, tr);
if (minLight > cc.a && minLight > maxDark) {
lightestColor = getLargest(cc, lightestColor, r, br, tr);
} else {
maxDark = max3(r, br, tr);
minLight = min3(l, tl, bl);
if (minLight > cc.a && minLight > maxDark) {
lightestColor = getLargest(cc, lightestColor, l, tl, bl);
}
}
//Kernel 3 and 7
maxDark = max3(cc, l, t);
minLight = min3(r, br, b);
if (minLight > maxDark) {
lightestColor = getLargest(cc, lightestColor, r, br, b);
} else {
maxDark = max3(cc, r, b);
minLight = min3(t, l, tl);
if (minLight > maxDark) {
lightestColor = getLargest(cc, lightestColor, t, l, tl);
}
}
FragColor = lightestColor;
}

View file

@ -0,0 +1,157 @@
#version 450
// MIT License
// Copyright (c) 2019 bloc97
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float STRENGTH_PUSH, STRENGTH_GRAD;
} params;
#pragma parameter STRENGTH_GRAD "Gradient strength" 0.3 0.0 1.0 0.1
#define STRENGTH_GRAD params.STRENGTH_GRAD
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;
//#define strength 0.7
float min3(vec4 a, vec4 b, vec4 c) {
return min(min(a.a, b.a), c.a);
}
float max3(vec4 a, vec4 b, vec4 c) {
return max(max(a.a, b.a), c.a);
}
vec4 getAverage(vec4 cc, vec4 a, vec4 b, vec4 c) {
return cc * (1 - STRENGTH_GRAD) + ((a + b + c) / 3) * STRENGTH_GRAD;
}
void main()
{
float dx = params.SourceSize.z;
float dy = params.SourceSize.w;
vec4 cc = texture(Source, vTexCoord); //Current Color
vec4 t = texture(Source, vTexCoord + vec2( 0, -dy));
vec4 tl = texture(Source, vTexCoord + vec2(-dx, -dy));
vec4 tr = texture(Source, vTexCoord + vec2( dx, -dy));
vec4 l = texture(Source, vTexCoord + vec2(-dx, 0));
vec4 r = texture(Source, vTexCoord + vec2( dx, 0));
vec4 b = texture(Source, vTexCoord + vec2( 0, dy));
vec4 bl = texture(Source, vTexCoord + vec2(-dx, dy));
vec4 br = texture(Source, vTexCoord + vec2( dx, dy));
vec4 lightestColor = cc;
//Kernel 0 and 4
float maxDark = max3(br, b, bl);
float minLight = min3(tl, t, tr);
if (minLight > cc.a && minLight > maxDark) {
FragColor = getAverage(cc, tl, t, tr);
return;
} else {
maxDark = max3(tl, t, tr);
minLight = min3(br, b, bl);
if (minLight > cc.a && minLight > maxDark) {
FragColor = getAverage(cc, br, b, bl);
return;
}
}
//Kernel 1 and 5
maxDark = max3(cc, l, b);
minLight = min3(r, t, tr);
if (minLight > maxDark) {
FragColor = getAverage(cc, r, t, tr);
return;
} else {
maxDark = max3(cc, r, t);
minLight = min3(bl, l, b);
if (minLight > maxDark) {
FragColor = getAverage(cc, bl, l, b);
return;
}
}
//Kernel 2 and 6
maxDark = max3(l, tl, bl);
minLight = min3(r, br, tr);
if (minLight > cc.a && minLight > maxDark) {
FragColor = getAverage(cc, r, br, tr);
return;
} else {
maxDark = max3(r, br, tr);
minLight = min3(l, tl, bl);
if (minLight > cc.a && minLight > maxDark) {
FragColor = getAverage(cc, l, tl, bl);
return;
}
}
//Kernel 3 and 7
maxDark = max3(cc, l, t);
minLight = min3(r, br, b);
if (minLight > maxDark) {
FragColor = getAverage(cc, r, br, b);
return;
} else {
maxDark = max3(cc, r, b);
minLight = min3(t, l, tl);
if (minLight > maxDark) {
FragColor = getAverage(cc, t, l, tl);
return;
}
}
FragColor = cc;
}

View file

@ -0,0 +1,3 @@
shaders = 1
shader0 = shaders/anaglyph-to-side-by-side.slang

View file

@ -0,0 +1,60 @@
#version 450
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float flip_eye_toggle;
float green;
float blue;
} params;
#pragma parameter flip_eye_toggle "Flip Left/Right" 0.0 0.0 1.0 1.0
bool flip_eye = bool(params.flip_eye_toggle);
#pragma parameter green "Green" 1.0 0.0 1.0 1.0
#pragma parameter blue "Blue" 1.0 0.0 1.0 1.0
const vec3 rec_709_luma = vec3(0.212, 0.701, 0.087);
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;
layout(location = 1) out float oscillator;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
oscillator = float(mod(params.FrameCount, 2.));
oscillator = (flip_eye) ? oscillator : 1. - oscillator;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in float oscillator;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
layout(set = 0, binding = 3) uniform sampler2D OriginalHistory1;
void main()
{
// convert current and previous frames to luma to preserve details
vec3 curr = texture(Source, vTexCoord).rgb;
float curr_lum = dot(curr, rec_709_luma);
vec3 last = texture(OriginalHistory1, vTexCoord).rgb;
float last_lum = dot(last, rec_709_luma);
// image for left/right eyes alternate on each frame
float one_eye = last_lum * oscillator + (curr_lum * (1. - oscillator));
float other_eye = curr_lum * oscillator + (last_lum * (1. - oscillator));
// one eye gets the red channel, the other eye goes to green and/or blue, depending on glasses
vec3 combined = vec3(one_eye, other_eye * params.green, other_eye * params.blue);
FragColor = vec4(combined, 1.0);
}

View file

@ -0,0 +1,76 @@
#version 450
// Shutter 3D to side-by-side
// by hunterk
// license: public domain
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float ZOOM, vert_pos, horz_pos, separation, flicker, height_mod, swap_eye;
} params;
#pragma parameter ZOOM "Zoom" 1.0 0.0 2.0 0.01
#define ZOOM params.ZOOM
#pragma parameter vert_pos "Vertical Modifier" 0.0 -2.0 2.0 0.01
#define vert_pos params.vert_pos
#pragma parameter horz_pos "Horizontal Modifier" 0.0 -2.0 2.0 0.01
#define horz_pos params.horz_pos
#pragma parameter separation "Eye Separation" 0.0 -2.0 2.0 0.01
#define separation params.separation
#pragma parameter flicker "Hold Last Frame (reduce flicker)" 1.0 0.0 1.0 0.25
#define flicker params.flicker
#pragma parameter height_mod "Image Height" 1.0 0.0 2.0 0.01
#define height_mod params.height_mod
#pragma parameter swap_eye "Swap Eye Sequence" 0.0 0.0 1.0 1.0
#define swap_eye params.swap_eye
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 left_coord;
layout(location = 1) out vec2 right_coord;
layout(location = 2) out float timer;
void main()
{
gl_Position = global.MVP * Position;
vec2 temp_coord = TexCoord.xy - 0.5;
temp_coord *= ZOOM;
temp_coord *= vec2(2.,1. / height_mod);
temp_coord += vec2(horz_pos, vert_pos);
temp_coord += 0.5;
left_coord = temp_coord.xy - vec2(0.5 + separation,0.);
right_coord = temp_coord.xy + vec2(0.5 + separation,0.);
timer = abs(swap_eye - mod(float(params.FrameCount), 2.));
}
#pragma stage fragment
layout(location = 0) in vec2 left_coord;
layout(location = 1) in vec2 right_coord;
layout(location = 2) in float timer;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
layout(set = 0, binding = 2) uniform sampler2D OriginalHistory1;
#define PrevTexture OriginalHistory1
void main()
{
vec4 left_screen = texture(Source, left_coord);
vec4 left_hold = texture(PrevTexture, left_coord);
vec4 right_screen = texture(Source, right_coord);
vec4 right_hold = texture(PrevTexture, right_coord);
left_screen = left_screen * timer + (1. - timer) * left_hold * flicker;
right_screen = right_screen * (1. - timer) + right_hold * timer * flicker;
FragColor = left_screen + right_screen;
}

View file

@ -0,0 +1,71 @@
#version 450
// simple shader to view content on side-by-side 3D displays
// by hunterk
// license: public domain
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float eye_sep, y_loc, BOTH, ana_zoom, WIDTH, HEIGHT, warpX, warpY, pulfrich;
} params;
#pragma parameter eye_sep "Eye Separation" 0.30 -1.0 5.0 0.05
#define eye_sep params.eye_sep
#pragma parameter y_loc "Vertical Placement" 0.25 -1.0 1.0 0.01
#define y_loc params.y_loc
#pragma parameter BOTH "Horizontal Placement" 0.51 -2.0 2.0 0.005
#define BOTH params.BOTH
#pragma parameter ana_zoom "Zoom" 0.75 -2.0 2.0 0.05
#define ana_zoom params.ana_zoom
#pragma parameter WIDTH "Side-by-Side Image Width" 3.05 1.0 7.0 0.05
#define WIDTH params.WIDTH
#pragma parameter HEIGHT "Side-by-Side Image Height" 2.0 1.0 5.0 0.1
#define HEIGHT params.HEIGHT
#pragma parameter warpX "Lens Warp Correction X" 0.1 0.0 0.5 0.05
#define warpX params.warpX
#pragma parameter warpY "Lens Warp Correction Y" 0.1 0.0 0.5 0.05
#define warpY params.warpY
#pragma parameter pulfrich "Pulfrich Effect" 0.0 0.0 0.5 0.25
#define pulfrich params.pulfrich
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.xy - 0.5) * ana_zoom + 0.5) * vec2(WIDTH, HEIGHT) - vec2(BOTH, 0.0);
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
//distortion
vec2 Warp(vec2 pos){
pos.xy = pos.xy * 2.0-1.0;
pos.xy *= vec2(1.0+(pos.y*pos.y)*warpX,1.0+(pos.x*pos.x)*warpY);
return pos*0.5+0.5;}
void main()
{
vec2 warpCoord1 = Warp(vTexCoord.xy - vec2(eye_sep, y_loc));
vec2 warpCoord2 = Warp(vTexCoord.xy + vec2(eye_sep, -y_loc));
vec4 frame1 = texture(Source, warpCoord1);
vec4 frame2 = texture(Source, warpCoord2) * (1.0 - pulfrich);
vec4 final = vec4(frame1 + frame2);
FragColor = final;
}

View file

@ -0,0 +1,3 @@
shaders = 1
shader0 = shaders/shutter-to-anaglyph.slang

View file

@ -0,0 +1,3 @@
shaders = 1
shader0 = shaders/shutter-to-side-by-side.slang

View file

@ -0,0 +1,3 @@
shaders = 1
shaders0 = shaders/side-by-side-simple.slang

45
xbr/shaders/super-xbr/super-xbr-pass0.slang Normal file → Executable file
View file

@ -32,7 +32,7 @@ layout(push_constant) uniform Push
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float XBR_EDGE_STR;
float XBR_EDGE_STR_P0;
float XBR_WEIGHT;
float XBR_ANTI_RINGING;
float MODE;
@ -40,16 +40,14 @@ layout(push_constant) uniform Push
float XBR_TEXTURE_SHP;
} params;
#pragma parameter XBR_EDGE_STR "Xbr - Edge Strength p0" 0.6 0.0 5.0 0.2
#pragma parameter XBR_WEIGHT "Xbr - Filter Weight" 1.0 0.00 1.50 0.01
#pragma parameter XBR_ANTI_RINGING "Xbr - Anti-Ringing Level" 1.0 0.0 1.0 1.0
#pragma parameter MODE "Mode - Normal, Details, Adaptive" 0.0 0.0 2.0 1.0
#pragma parameter XBR_EDGE_STR_P0 "Xbr - Edge Strength p0" 5.0 0.0 5.0 0.5
#pragma parameter XBR_WEIGHT "Xbr - Filter Weight" 1.0 0.00 1.50 0.01
#pragma parameter XBR_EDGE_SHP "Adaptive Dynamic Edge Sharp" 0.4 0.0 3.0 0.1
#pragma parameter XBR_TEXTURE_SHP "Adaptive Static Edge Sharp" 1.0 0.0 2.0 0.1
#define XBR_EDGE_STR params.XBR_EDGE_STR
#define XBR_EDGE_STR_P0 params.XBR_EDGE_STR_P0
#define XBR_WEIGHT params.XBR_WEIGHT
#define XBR_ANTI_RINGING params.XBR_ANTI_RINGING
#define MODE params.MODE
#define XBR_EDGE_SHP params.XBR_EDGE_SHP
#define XBR_TEXTURE_SHP params.XBR_TEXTURE_SHP
@ -144,32 +142,7 @@ void main()
{
// settings //
float wp1, wp2, wp3, wp4, wp5, wp6, weight1, weight2;
if (MODE == 1.0)
{
wp1 = 1.0;
wp2 = 0.0;
wp3 = 0.0;
wp4 = 1.0;
wp5 = -1.0;
wp6 = 0.0;
weight1 = (XBR_WEIGHT*1.29633/10.0);
weight2 = (XBR_WEIGHT*1.75068/10.0/2.0);
}
else if (MODE == 2.0)
{
wp1 = 1.0;
wp2 = 0.0;
wp3 = 0.0;
wp4 = 2.0;
wp5 = -1.0;
wp6 = 0.0;
weight1 = (1.29633/10.0);
weight2 = (1.75068/10.0/2.0);
}
else
{
wp1 = 2.0;
wp2 = 1.0;
wp3 = -1.0;
@ -179,7 +152,7 @@ void main()
weight1 = (XBR_WEIGHT*1.29633/10.0);
weight2 = (XBR_WEIGHT*1.75068/10.0/2.0);
}
// end settings //
vec3 P0 = texture(Source, t1.xy).xyz;
@ -222,7 +195,7 @@ void main()
/* Calc edgeness in horizontal/vertical directions. */
float hv_edge = (hv_wd(wp1, wp2, wp3, wp4, wp5, wp6, f, i, e, h, c, i5, b, h5) - hv_wd(wp1, wp2, wp3, wp4, wp5, wp6, e, f, h, i, d, f4, g, i4));
float limits = XBR_EDGE_STR + 0.000001;
float limits = XBR_EDGE_STR_P0 + 0.000001;
float edge_strength = smoothstep(0.0, limits, abs(d_edge));
vec4 w1, w2;
@ -238,7 +211,7 @@ void main()
w1 = vec4(-wgt1, wgt1+ 0.5, wgt1+ 0.5, -wgt1);
w2 = vec4(-wgt2, wgt2+0.25, wgt2+0.25, -wgt2);
c3 = mul(w2, mat4x3(P0+2.0*(D+G)+P2, B+2.0*(E+H)+H5, C+2.0*(F+I)+I5, P1+2.0*(F4+I4)+P3))/3.0;
c4 = mul(w2, mat4x3(P0+2.0*(C+B)+P1, D+2.0*(F+E)+F4, G+2.0*(I+H)+I4, P2+2.0*(I5+H5)+P3))/3.0;
c4 = mul(w2, mat4x3(P0+2.0*(C+B)+P1, D+2.0*(F+E)+F4, G+2.0*(I+H)+I4, P2+2.0*(I5+H5)+P3))/3.0;
}
else
{
@ -257,8 +230,8 @@ void main()
vec3 color = mix(mix(c1, c2, step(0.0, d_edge)), mix(c3, c4, step(0.0, hv_edge)), 1. - edge_strength);
/* Anti-ringing code. */
vec3 min_sample = min4( E, F, H, I ) + (1.-XBR_ANTI_RINGING)*mix((P2-H)*(F-P1), (P0-E)*(I-P3), step(0.0, d_edge));
vec3 max_sample = max4( E, F, H, I ) - (1.-XBR_ANTI_RINGING)*mix((P2-H)*(F-P1), (P0-E)*(I-P3), step(0.0, d_edge));
vec3 min_sample = min4( E, F, H, I );
vec3 max_sample = max4( E, F, H, I );
color = clamp(color, min_sample, max_sample);
FragColor = vec4(color, 1.0);

15
xbr/shaders/super-xbr/super-xbr-pass1.slang Normal file → Executable file
View file

@ -39,8 +39,10 @@ layout(push_constant) uniform Push
float MODE;
float XBR_EDGE_SHP;
float XBR_TEXTURE_SHP;
float XBR_EDGE_STR_P1;
} params;
#pragma parameter XBR_EDGE_STR_P1 "Xbr - Edge Strength p1" 0.0 0.0 5.0 0.5
#pragma parameter MODE "Mode - Normal, Details, Adaptive" 0.0 0.0 2.0 1.0
#pragma parameter XBR_EDGE_SHP "Adaptive Dynamic Edge Sharp" 0.4 0.0 3.0 0.1
#pragma parameter XBR_TEXTURE_SHP "Adaptive Static Edge Sharp" 1.0 0.0 2.0 0.1
@ -48,6 +50,7 @@ layout(push_constant) uniform Push
#define MODE params.MODE
#define XBR_EDGE_SHP params.XBR_EDGE_SHP
#define XBR_TEXTURE_SHP params.XBR_TEXTURE_SHP
#define XBR_EDGE_STR_P1 params.XBR_EDGE_STR_P1
layout(std140, set = 0, binding = 0) uniform UBO
{
@ -128,8 +131,8 @@ void main()
wp1 = 1.0;
wp2 = 0.0;
wp3 = 0.0;
wp4 = 1.0;
wp5 = -1.0;
wp4 = 0.0;
wp5 = 0.0;
wp6 = 0.0;
weight1 = (XBR_WEIGHT*1.75068/10.0);
@ -166,7 +169,7 @@ void main()
vec2 dir = fp - vec2(0.5,0.5);
if ((dir.x*dir.y)>0.0)
{
FragColor = (fp.x>0.5) ? texture(Source, vTexCoord) : texture(Original, vTexCoord);
FragColor = mix( texture(Original, vTexCoord), texture(Source, vTexCoord), step(0.0, dir.x));
}
else
{
@ -212,7 +215,7 @@ void main()
/* Calc edgeness in horizontal/vertical directions. */
float hv_edge = (hv_wd(wp1, wp2, wp3, wp4, wp5, wp6, f, i, e, h, c, i5, b, h5) - hv_wd(wp1, wp2, wp3, wp4, wp5, wp6, e, f, h, i, d, f4, g, i4));
float limits = XBR_EDGE_STR + 0.000001;
float limits = XBR_EDGE_STR_P1 + 0.000001;
float edge_strength = smoothstep(0.0, limits, abs(d_edge));
vec4 w1, w2;
@ -247,8 +250,8 @@ void main()
vec3 color = mix(mix(c1, c2, step(0.0, d_edge)), mix(c3, c4, step(0.0, hv_edge)), 1. - edge_strength);
/* Anti-ringing code. */
vec3 min_sample = min4( E, F, H, I ) + (1.-XBR_ANTI_RINGING)*mix((P2-H)*(F-P1), (P0-E)*(I-P3), step(0.0, d_edge));
vec3 max_sample = max4( E, F, H, I ) - (1.-XBR_ANTI_RINGING)*mix((P2-H)*(F-P1), (P0-E)*(I-P3), step(0.0, d_edge));
vec3 min_sample = min4( E, F, H, I );
vec3 max_sample = max4( E, F, H, I );
color = clamp(color, min_sample, max_sample);
FragColor = vec4(color, 1.0);

0
xbr/shaders/super-xbr/super-xbr-pass1b.slang Normal file → Executable file
View file

13
xbr/shaders/super-xbr/super-xbr-pass2.slang Normal file → Executable file
View file

@ -39,15 +39,18 @@ layout(push_constant) uniform Push
float MODE;
float XBR_EDGE_SHP;
float XBR_TEXTURE_SHP;
float XBR_EDGE_STR_P2;
} params;
#pragma parameter MODE "Mode - Normal, Details, Adaptive" 0.0 0.0 2.0 1.0
#pragma parameter XBR_EDGE_STR_P2 "Xbr - Edge Strength p2" 5.0 0.0 5.0 0.5
#pragma parameter XBR_EDGE_SHP "Adaptive Dynamic Edge Sharp" 0.4 0.0 3.0 0.1
#pragma parameter XBR_TEXTURE_SHP "Adaptive Static Edge Sharp" 1.0 0.0 2.0 0.1
#define MODE params.MODE
#define XBR_EDGE_SHP params.XBR_EDGE_SHP
#define XBR_TEXTURE_SHP params.XBR_TEXTURE_SHP
#define XBR_EDGE_STR_P2 params.XBR_EDGE_STR_P2
layout(std140, set = 0, binding = 0) uniform UBO
{
@ -139,10 +142,10 @@ void main()
float wp1, wp2, wp3, wp4, wp5, wp6, weight1, weight2;
if (MODE == 1.0)
{
wp1 = 1.0;
wp1 = 0.0;
wp2 = 0.0;
wp3 = 0.0;
wp4 = 0.0;
wp4 = 1.0;
wp5 = 0.0;
wp6 = 0.0;
@ -225,7 +228,7 @@ void main()
/* Calc edgeness in horizontal/vertical directions. */
float hv_edge = (hv_wd(wp1, wp2, wp3, wp4, wp5, wp6, f, i, e, h, c, i5, b, h5) - hv_wd(wp1, wp2, wp3, wp4, wp5, wp6, e, f, h, i, d, f4, g, i4));
float limits = XBR_EDGE_STR + 0.000001;
float limits = XBR_EDGE_STR_P2 + 0.000001;
float edge_strength = smoothstep(0.0, limits, abs(d_edge));
vec4 w1, w2;
@ -260,8 +263,8 @@ void main()
vec3 color = mix(mix(c1, c2, step(0.0, d_edge)), mix(c3, c4, step(0.0, hv_edge)), 1. - edge_strength);
/* Anti-ringing code. */
vec3 min_sample = min4( E, F, H, I ) + (1.-XBR_ANTI_RINGING)*mix((P2-H)*(F-P1), (P0-E)*(I-P3), step(0.0, d_edge));
vec3 max_sample = max4( E, F, H, I ) - (1.-XBR_ANTI_RINGING)*mix((P2-H)*(F-P1), (P0-E)*(I-P3), step(0.0, d_edge));
vec3 min_sample = min4( E, F, H, I );
vec3 max_sample = max4( E, F, H, I );
color = clamp(color, min_sample, max_sample);
FragColor = vec4(color, 1.0);

View file

@ -0,0 +1,261 @@
#version 450
/*
******* Super XBR Shader - pass1 *******
Copyright (c) 2015 Hyllian - sergiogdb@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#define XBR_EDGE_STR 0.6
#define XBR_WEIGHT 1.0
#define XBR_ANTI_RINGING 1.0
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float MODE;
float XBR_EDGE_SHP;
float XBR_TEXTURE_SHP;
float XBR_EDGE_STR_P1;
} params;
#pragma parameter XBR_EDGE_STR_P1 "Xbr - Edge Strength p1" 0.0 0.0 5.0 0.5
#pragma parameter MODE "Mode - Normal, Details, Adaptive" 0.0 0.0 2.0 1.0
#pragma parameter XBR_EDGE_SHP "Adaptive Dynamic Edge Sharp" 0.4 0.0 3.0 0.1
#pragma parameter XBR_TEXTURE_SHP "Adaptive Static Edge Sharp" 1.0 0.0 2.0 0.1
#define MODE params.MODE
#define XBR_EDGE_SHP params.XBR_EDGE_SHP
#define XBR_TEXTURE_SHP params.XBR_TEXTURE_SHP
#define XBR_EDGE_STR_P1 params.XBR_EDGE_STR_P1
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;
#define mul(a,b) (b*a)
const vec3 Y = vec3(.2126, .7152, .0722);
float RGBtoYUV(vec3 color)
{
return dot(color, Y);
}
float df(float A, float B)
{
return abs(A-B);
}
/*
P1
|P0|B |C |P1| C F4 |a0|b1|c2|d3|
|D |E |F |F4| B F I4 |b0|c1|d2|e3| |e1|i1|i2|e2|
|G |H |I |I4| P0 E A I P3 |c0|d1|e2|f3| |e3|i3|i4|e4|
|P2|H5|I5|P3| D H I5 |d0|e1|f2|g3|
G H5
P2
*/
float d_wd(float wp1, float wp2, float wp3, float wp4, float wp5, float wp6, float b0, float b1, float c0, float c1, float c2, float d0, float d1, float d2, float d3, float e1, float e2, float e3, float f2, float f3)
{
return (wp1*(df(c1,c2) + df(c1,c0) + df(e2,e1) + df(e2,e3)) + wp2*(df(d2,d3) + df(d0,d1)) + wp3*(df(d1,d3) + df(d0,d2)) + wp4*df(d1,d2) + wp5*(df(c0,c2) + df(e1,e3)) + wp6*(df(b0,b1) + df(f2,f3)));
}
float hv_wd(float wp1, float wp2, float wp3, float wp4, float wp5, float wp6, float i1, float i2, float i3, float i4, float e1, float e2, float e3, float e4)
{
return ( wp4*(df(i1,i2)+df(i3,i4)) + wp1*(df(i1,e1)+df(i2,e2)+df(i3,e3)+df(i4,e4)) + wp3*(df(i1,e2)+df(i3,e4)+df(e1,i2)+df(e3,i4)));
}
vec3 min4(vec3 a, vec3 b, vec3 c, vec3 d)
{
return min(a, min(b, min(c, d)));
}
vec3 max4(vec3 a, vec3 b, vec3 c, vec3 d)
{
return max(a, max(b, max(c, d)));
}
float max4float(float a, float b, float c, float d)
{
return max(a, max(b, max(c, d)));
}
#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 * 1.0001;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
layout(set = 0, binding = 3) uniform sampler2D PassPrev2;
#define Original PassPrev2
void main()
{
// settings //
float wp1, wp2, wp3, wp4, wp5, wp6, weight1, weight2;
if (MODE == 1.0)
{
wp1 = 1.0;
wp2 = 0.0;
wp3 = 0.0;
wp4 = 0.0;
wp5 = 0.0;
wp6 = 0.0;
weight1 = (XBR_WEIGHT*1.75068/10.0);
weight2 = (XBR_WEIGHT*1.29633/10.0/2.0);
}
else if (MODE == 2.0)
{
wp1 = 8.0;
wp2 = 0.0;
wp3 = 0.0;
wp4 = 0.0;
wp5 = 0.0;
wp6 = 0.0;
weight1 = (1.75068/10.0);
weight2 = (1.29633/10.0/2.0);
}
else
{
wp1 = 8.0;
wp2 = 0.0;
wp3 = 0.0;
wp4 = 0.0;
wp5 = 0.0;
wp6 = 0.0;
weight1 = (XBR_WEIGHT*1.75068/10.0);
weight2 = (XBR_WEIGHT*1.29633/10.0/2.0);
}
// end settings //
//Skip pixels on wrong grid
vec2 fp = fract(vTexCoord.xy * params.SourceSize.xy);
vec2 dir = fp - vec2(0.5,0.5);
if ((dir.x*dir.y)>0.0)
{
FragColor = mix( texture(Original, vTexCoord), texture(Source, vTexCoord), step(0.0, dir.x));
}
else
{
vec2 g1 = (fp.x>0.5) ? vec2(0.5/params.SourceSize.x, 0.0) : vec2(0.0, 0.5/params.SourceSize.y);
vec2 g2 = (fp.x>0.5) ? vec2(0.0, 0.5/params.SourceSize.y) : vec2(0.5/params.SourceSize.x, 0.0);
vec3 P0 = texture(Original, vTexCoord -3.0*g1 ).xyz;
vec3 P1 = texture(Source, vTexCoord -3.0*g2).xyz;
vec3 P2 = texture(Source, vTexCoord +3.0*g2).xyz;
vec3 P3 = texture(Original, vTexCoord +3.0*g1 ).xyz;
vec3 B = texture(Source, vTexCoord -2.0*g1 -g2).xyz;
vec3 C = texture(Original, vTexCoord -g1 -2.0*g2).xyz;
vec3 D = texture(Source, vTexCoord -2.0*g1 +g2).xyz;
vec3 E = texture(Original, vTexCoord -g1 ).xyz;
vec3 F = texture(Source, vTexCoord -g2).xyz;
vec3 G = texture(Original, vTexCoord -g1 +2.0*g2).xyz;
vec3 H = texture(Source, vTexCoord +g2).xyz;
vec3 I = texture(Original, vTexCoord +g1 ).xyz;
vec3 F4 = texture(Original, vTexCoord +g1 -2.0*g2).xyz;
vec3 I4 = texture(Source, vTexCoord +2.0*g1 -g2).xyz;
vec3 H5 = texture(Original, vTexCoord +g1 +2.0*g2).xyz;
vec3 I5 = texture(Source, vTexCoord +2.0*g1 +g2).xyz;
float b = RGBtoYUV( B );
float c = RGBtoYUV( C );
float d = RGBtoYUV( D );
float e = RGBtoYUV( E );
float f = RGBtoYUV( F );
float g = RGBtoYUV( G );
float h = RGBtoYUV( H );
float i = RGBtoYUV( I );
float i4 = RGBtoYUV( I4 ); float p0 = RGBtoYUV( P0 );
float i5 = RGBtoYUV( I5 ); float p1 = RGBtoYUV( P1 );
float h5 = RGBtoYUV( H5 ); float p2 = RGBtoYUV( P2 );
float f4 = RGBtoYUV( F4 ); float p3 = RGBtoYUV( P3 );
/* Calc edgeness in diagonal directions. */
float d_edge = (d_wd( wp1, wp2, wp3, wp4, wp5, wp6, d, b, g, e, c, p2, h, f, p1, h5, i, f4, i5, i4 ) - d_wd( wp1, wp2, wp3, wp4, wp5, wp6, c, f4, b, f, i4, p0, e, i, p3, d, h, i5, g, h5 ));
/* Calc edgeness in horizontal/vertical directions. */
float hv_edge = (hv_wd(wp1, wp2, wp3, wp4, wp5, wp6, f, i, e, h, c, i5, b, h5) - hv_wd(wp1, wp2, wp3, wp4, wp5, wp6, e, f, h, i, d, f4, g, i4));
float limits = XBR_EDGE_STR_P1 + 0.000001;
float edge_strength = smoothstep(0.0, limits, abs(d_edge));
vec4 w1, w2;
vec3 c3, c4;
if (MODE == 2.0)
{
float contrast = max(max4float(df(e,f),df(e,i),df(e,h),df(f,h)),max(df(f,i),df(h,i)))/(e+0.001);
float wgt1 = weight1*(smoothstep(0.0, 0.6, contrast)*XBR_EDGE_SHP + XBR_TEXTURE_SHP);
float wgt2 = weight2*(smoothstep(0.0, 0.6, contrast)*XBR_EDGE_SHP + XBR_TEXTURE_SHP);
/* Filter weights. Two taps only. */
w1 = vec4(-wgt1, wgt1+ 0.5, wgt1+ 0.5, -wgt1);
w2 = vec4(-wgt2, wgt2+0.25, wgt2+0.25, -wgt2);
c3 = mul(w2, mat4x3(P0+2.0*(D+G)+P2, B+2.0*(E+H)+H5, C+2.0*(F+I)+I5, P1+2.0*(F4+I4)+P3))/3.0;
c4 = mul(w2, mat4x3(P0+2.0*(C+B)+P1, D+2.0*(F+E)+F4, G+2.0*(I+H)+I4, P2+2.0*(I5+H5)+P3))/3.0;
}
else
{
/* Filter weights. Two taps only. */
w1 = vec4(-weight1, weight1+0.5, weight1+0.5, -weight1);
w2 = vec4(-weight2, weight2+0.25, weight2+0.25, -weight2);
c3 = mul(w2, mat4x3(D+G, E+H, F+I, F4+I4));
c4 = mul(w2, mat4x3(C+B, F+E, I+H, I5+H5));
}
/* Filtering and normalization in four direction generating four colors. */
vec3 c1 = mul(w1, mat4x3( P2, H, F, P1 ));
vec3 c2 = mul(w1, mat4x3( P0, E, I, P3 ));
/* Smoothly blends the two strongest directions (one in diagonal and the other in vert/horiz direction). */
vec3 color = mix(mix(c1, c2, step(0.0, d_edge)), mix(c3, c4, step(0.0, hv_edge)), 1. - edge_strength);
/* Anti-ringing code. */
vec3 min_sample = min4( E, F, H, I );
vec3 max_sample = max4( E, F, H, I );
color = clamp(color, min_sample, max_sample);
FragColor = vec4(color, 1.0);
}
}

127
xbr/super-xbr-6p-anime4k.slangp Executable file
View file

@ -0,0 +1,127 @@
shaders = "11"
shader0 = "shaders/super-xbr/super-xbr-pass0.slang"
filter_linear0 = "false"
wrap_mode0 = "clamp_to_border"
mipmap_input0 = "false"
alias0 = ""
float_framebuffer0 = "false"
srgb_framebuffer0 = "false"
scale_type_x0 = "source"
scale_x0 = "1.000000"
scale_type_y0 = "source"
scale_y0 = "1.000000"
shader1 = "shaders/super-xbr/super-xbr-pass1.slang"
filter_linear1 = "false"
wrap_mode1 = "clamp_to_border"
mipmap_input1 = "false"
alias1 = ""
float_framebuffer1 = "false"
srgb_framebuffer1 = "false"
scale_type_x1 = "source"
scale_x1 = "2.000000"
scale_type_y1 = "source"
scale_y1 = "2.000000"
shader2 = "shaders/super-xbr/super-xbr-pass2.slang"
filter_linear2 = "false"
wrap_mode2 = "clamp_to_border"
mipmap_input2 = "false"
alias2 = "PassPrev2"
float_framebuffer2 = "false"
srgb_framebuffer2 = "false"
scale_type_x2 = "source"
scale_x2 = "1.000000"
scale_type_y2 = "source"
scale_y2 = "1.000000"
shader3 = "shaders/super-xbr/super-xbr-pass0.slang"
filter_linear3 = "false"
wrap_mode3 = "clamp_to_border"
mipmap_input3 = "false"
alias3 = ""
float_framebuffer3 = "false"
srgb_framebuffer3 = "false"
scale_type_x3 = "source"
scale_x3 = "1.000000"
scale_type_y3 = "source"
scale_y3 = "1.000000"
shader4 = "shaders/super-xbr/super-xbr-pass3.slang"
filter_linear4 = "false"
wrap_mode4 = "clamp_to_border"
mipmap_input4 = "false"
alias4 = ""
float_framebuffer4 = "false"
srgb_framebuffer4 = "false"
scale_type_x4 = "source"
scale_x4 = "2.000000"
scale_type_y4 = "source"
scale_y4 = "2.000000"
shader5 = "shaders/super-xbr/super-xbr-pass2.slang"
filter_linear5 = "false"
wrap_mode5 = "clamp_to_border"
mipmap_input5 = "false"
alias5 = ""
float_framebuffer5 = "false"
srgb_framebuffer5 = "false"
scale_type_x5 = "source"
scale_x5 = "1.000000"
scale_type_y5 = "source"
scale_y5 = "1.000000"
shader6 = "../cubic/shaders/catmull-rom-fast.slang"
filter_linear6 = "true"
wrap_mode6 = "clamp_to_border"
mipmap_input6 = "false"
alias6 = ""
float_framebuffer6 = "false"
srgb_framebuffer6 = "false"
scale_type_x6 = "viewport"
scale_type_y6 = "viewport"
shader7 = "../sharpen/shaders/anime4k/anime4k-compute-lum.slang"
filter_linear7 = "false"
wrap_mode7 = "clamp_to_border"
mipmap_input7 = "false"
alias7 = ""
float_framebuffer7 = "false"
srgb_framebuffer7 = "false"
scale_type_x7 = "source"
scale_x7 = "1.000000"
scale_type_y7 = "source"
scale_y7 = "1.000000"
shader8 = "../sharpen/shaders/anime4k/anime4k-push.slang"
filter_linear8 = "false"
wrap_mode8 = "clamp_to_border"
mipmap_input8 = "false"
alias8 = ""
float_framebuffer8 = "false"
srgb_framebuffer8 = "false"
scale_type_x8 = "source"
scale_x8 = "1.000000"
scale_type_y8 = "source"
scale_y8 = "1.000000"
shader9 = "../sharpen/shaders/anime4k/anime4k-compute-gradient.slang"
filter_linear9 = "false"
wrap_mode9 = "clamp_to_border"
mipmap_input9 = "false"
alias9 = ""
float_framebuffer9 = "false"
srgb_framebuffer9 = "false"
scale_type_x9 = "source"
scale_x9 = "1.000000"
scale_type_y9 = "source"
scale_y9 = "1.000000"
shader10 = "../sharpen/shaders/anime4k/anime4k-pushgrad-weak.slang"
filter_linear10 = "false"
wrap_mode10 = "clamp_to_border"
mipmap_input10 = "false"
alias10 = ""
float_framebuffer10 = "false"
srgb_framebuffer10 = "false"
scale_type_x10 = "source"
scale_x10 = "1.000000"
scale_type_y10 = "source"
scale_y10 = "1.000000"
parameters = "MODE;XBR_EDGE_STR;XBR_WEIGHT;XBR_ANTI_RINGING;XBR_EDGE_STR;XBR_WEIGHT;XBR_ANTI_RINGING;STRENGTH_PUSH;STRENGTH_GRAD"
MODE = "1.0"
XBR_EDGE_STR = "5.000000"
XBR_WEIGHT = "1.000000"
XBR_ANTI_RINGING = "1.000000"
STRENGTH_PUSH = "0.300000"
STRENGTH_GRAD = "0.300000"

View file

@ -41,4 +41,4 @@ filter_linear6 = false
parameters = "MODE;XBR_EDGE_STR"
MODE = "1.0"
XBR_EDGE_STR = "2.0"
XBR_EDGE_STR = "5.0"