add super-xbr shaders and presets

This commit is contained in:
hunterk 2017-04-06 15:42:27 -05:00
parent 8f07c63b0c
commit 6a9f22741c
25 changed files with 3731 additions and 0 deletions

View file

@ -0,0 +1,96 @@
#version 450
/*
Hyllian's Deposterize Shader - Pass0
Copyright (C) 2011/2016 Hyllian/Jararaca - sergiogdb@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 EQ_THRESH1;
float DIFF_THRESH1;
} params;
#pragma parameter EQ_THRESH1 "Eq Limit Horizontal" 0.01 0.0 1.0 0.01
#pragma parameter DIFF_THRESH1 "Diff Limit Horizontal" 0.06 0.0 1.0 0.01
#define EQ params.EQ_THRESH1
#define DF params.DIFF_THRESH1
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;
vec3 df3(vec3 c1, vec3 c2)
{
return abs(c1 - c2);
}
bvec3 eq3(vec3 A, vec3 B)
{
return lessThanEqual(df3(A, B) , vec3(EQ));
}
#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 vec4 t1;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
vec2 ps = vec2(params.SourceSize.zw);
float dx = ps.x;
float dy = ps.y;
t1 = vTexCoord.xxxy + vec4( -dx, 0, dx, 0); // D E F
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in vec4 t1;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
void main()
{
vec3 res;
vec3 D = texture(Source, t1.xw).rgb;
vec3 E = texture(Source, t1.yw).rgb;
vec3 F = texture(Source, t1.zw).rgb;
bvec3 test1 = eq3(D, F);
bvec3 test2 = eq3(D, E);
bvec3 test3 = eq3(E, F);
bvec3 test4 = lessThanEqual(df3(E, F) , vec3(DF, DF, DF));
bvec3 test5 = lessThanEqual(df3(D, E) , vec3(DF, DF, DF));
res = ((test1 == bvec3(false)) && ((test4 == bvec3(true)) && (test2 == bvec3(true)) || (test5 == bvec3(true)) && (test3 == bvec3(true)))) ? 0.5*(D+F) : E;
FragColor = vec4(res, 1.0);
}

View file

@ -0,0 +1,96 @@
#version 450
/*
Hyllian's Deposterize Shader - Pass1
Copyright (C) 2011/2016 Hyllian/Jararaca - sergiogdb@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 EQ_THRESH2;
float DIFF_THRESH2;
} params;
#pragma parameter EQ_THRESH2 "Eq Limit Vertical" 0.01 0.0 1.0 0.01
#pragma parameter DIFF_THRESH2 "Diff Limit Vertical" 0.06 0.0 1.0 0.01
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;
#define EQ params.EQ_THRESH2
#define DF params.DIFF_THRESH2
vec3 df3(vec3 c1, vec3 c2)
{
return abs(c1 - c2);
}
bvec3 eq3(vec3 A, vec3 B)
{
return lessThanEqual(df3(A, B) , vec3(EQ));
}
#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 vec4 t1;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
vec2 ps = vec2(params.SourceSize.zw);
float dx = ps.x;
float dy = ps.y;
t1 = vTexCoord.xyyy + vec4( 0, -dy, 0, dy); // B E H
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in vec4 t1;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
void main()
{
vec3 res;
vec3 B = texture(Source, t1.xy).rgb;
vec3 E = texture(Source, t1.xz).rgb;
vec3 H = texture(Source, t1.xw).rgb;
bvec3 test1 = eq3(B, H);
bvec3 test2 = eq3(B, E);
bvec3 test3 = eq3(E, H);
bvec3 test4 = lessThanEqual(df3(E, H) , vec3(DF, DF, DF));
bvec3 test5 = lessThanEqual(df3(B, E) , vec3(DF, DF, DF));
res = ((test1 == bvec3(false)) && ((test4 == bvec3(true)) && (test2 == bvec3(true)) || (test5 == bvec3(true)) && (test3 == bvec3(true)))) ? 0.5*(B+H) : E;
FragColor = vec4(res, 1.0);
}

98
xbr/README.md Normal file
View file

@ -0,0 +1,98 @@
xBR Shaders
=======
These shaders uses the xBR algorithm to scale. xBR (scale by rules) works by detecting edges and interpolating pixels along them. It has some empyrical rules developed to detect the edges in many directions. There are many versions implemented and they differs basically by the number of directions considered and the way interpolations are done.
xbr-lvl1-noblend.cg
--------------
The most basic xBR shader. Level 1 means it only detects two edge directions (45º and 135º). The interpolation doesn't blend pixel colors. It uses the most similar color from one of its neighbors. So, the final result uses the original color palette. And because of that, it only works properly at odd scale factors (3x, 5x, 7x...).
Recommended sampling: `Point`
Recommended scale factors: `multiple odd scale factors`
xbr-lvl2-noblend.cg
--------------
An evolution from last shader. Level 2 means it can detect four edge directions, which shows as better rounded objects on screen. The interpolation doesn't blend pixel colors. It uses the most similar color from one of its neighbors. So, the final result uses the original color palette. And because of that, it only works properly at odd scale factors (3x, 5x, 7x...).
Recommended sampling: `Point`
Recommended scale factors: `multiple odd scale factors`
xbr-lvl2.cg
--------------
It can detect four edge directions, which shows as better rounded objects on screen. The interpolation blends pixel colors, so that the final image is smoother than the noblend versions. It works well in any integer scale factor.
Recommended sampling: `Point`
Recommended scale factors: `Integer multiples`
xbr-lvl2-multipass.cg
--------------
It's the same as the last one. But this one divides the calculations among multiple shaders. So, this one is faster than the single versions.
Recommended sampling: `Point`
Recommended scale factors: `Integer multiples`
xbr-lvl2-fast.cg
--------------
This is a simplified lvl2 implementation. Much faster than the standard version, though it sacrifices some quality.
Recommended sampling: `Point`
Recommended scale factors: `Integer multiples`
xbr-lvl3-noblend.cg
--------------
Level 3 means it can detect six edge directions, which shows as better rounded objects on screen. The interpolation doesn't blend pixel colors. It uses the most similar color from one of its neighbors. So, the final result uses the original color palette. And because of that, it only works properly at odd scale factors (3x, 5x, 7x...).
Recommended sampling: `Point`
Recommended scale factors: `multiple odd scale factors`
xbr-lvl3.cg
--------------
It can detect six edge directions, which shows as even better rounded objects on screen than the lvl2. The interpolation blends pixel colors, so that the final image is smoother than the noblend versions. It works well in any integer scale factor.
Recommended sampling: `Point`
Recommended scale factors: `Integer multiples`
xbr-lvl3-multipass.cg
--------------
It's the same as the last one. But this one divides the calculations among multiple shaders. So, this one is faster than the single versions.
Recommended sampling: `Point`
Recommended scale factors: `Integer multiples`
xbr-mlv4-multipass.cg
--------------
This shader is the latest evolution of the standard xBR algorithm. It can can detect eight edge directions, which shows as better rounded objects on screen. Besides, it has a non-greedy selection of edges internally, which means it doesn't automatically chooses to interpolate along the steeper edge. The interpolation blends pixel colors, so that the final image is smoother than the noblend versions. It works well in any integer scale factor.
Recommended sampling: `Point`
Recommended scale factors: `Integer multiples`
xbr-hybrid.cg
--------------
This shader combines xBR with reverse-aa. It's recommended for games with smooth color gradients.
Recommended sampling: `Point`
super-xbr-2p.cg
--------------
Super-xBR uses parts of the xBR algorithm and combines with other linear interpolation ones. It is intended for games with smooth color gradients. Compared to the hybrid ones, Super-xBR provides a much better image, without discontinuities.
Recommended sampling: `Point`
Recommended scale factors: `Integer multiples`
super-xbr-3p-smoother.cg
--------------
The same as the last one with an additional step to increase smoothness. This one provides even better image quality, though a bit slower.
Recommended sampling: `Point`
Recommended scale factors: `Integer multiples`

View file

@ -0,0 +1,180 @@
#version 450
/*
Hyllian's jinc windowed-jinc 2-lobe sharper with anti-ringing Shader
Copyright (C) 2011-2014 Hyllian/Jararaca - sergiogdb@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 JINC2_WINDOW_SINC;
float JINC2_SINC;
float JINC2_AR_STRENGTH;
} params;
#pragma parameter JINC2_WINDOW_SINC "Window Sinc Param" 0.42 0.0 1.0 0.01
#pragma parameter JINC2_SINC "Sinc Param" 0.92 0.0 1.0 0.01
#pragma parameter JINC2_AR_STRENGTH "Anti-ringing Strength" 0.0 0.0 1.0 0.1
#define mul(a,b) (b*a)
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;
/*
This is an approximation of Jinc(x)*Jinc(x*r1/r2) for x < 2.5,
where r1 and r2 are the first two zeros of jinc function.
For a jinc 2-lobe best approximation, use A=0.5 and B=0.825.
*/
// A=0.5, B=0.825 is the best jinc approximation for x<2.5. if B=1.0, it's a lanczos filter.
// Increase A to get more blur. Decrease it to get a sharper picture.
// B = 0.825 to get rid of dithering. Increase B to get a fine sharpness, though dithering returns.
#define halfpi 1.5707963267948966192313216916398
#define pi 3.1415926535897932384626433832795
#define wa (params.JINC2_WINDOW_SINC*pi)
#define wb (params.JINC2_SINC*pi)
const vec3 Y = vec3(0.299, 0.587, 0.114);
float df(float A, float B)
{
return abs(A-B);
}
// Calculates the distance between two points
float d(vec2 pt1, vec2 pt2)
{
vec2 v = pt2 - pt1;
return sqrt(dot(v,v));
}
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)));
}
vec4 resampler(vec4 x)
{
vec4 res;
res = (x == vec4(0.0, 0.0, 0.0, 0.0)) ? vec4(wa*wb) : sin(x*wa)*sin(x*wb)/(x*x);
return res;
}
#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()
{
vec3 color;
mat4x4 weights;
vec2 dx = vec2(1.0, 0.0);
vec2 dy = vec2(0.0, 1.0);
vec2 pc = vTexCoord * params.SourceSize.xy;
vec2 tc = (floor(pc-vec2(0.5,0.5))+vec2(0.5,0.5));
weights[0] = resampler(vec4(d(pc, tc -dx -dy), d(pc, tc -dy), d(pc, tc +dx -dy), d(pc, tc+2.0*dx -dy)));
weights[1] = resampler(vec4(d(pc, tc -dx ), d(pc, tc ), d(pc, tc +dx ), d(pc, tc+2.0*dx )));
weights[2] = resampler(vec4(d(pc, tc -dx +dy), d(pc, tc +dy), d(pc, tc +dx +dy), d(pc, tc+2.0*dx +dy)));
weights[3] = resampler(vec4(d(pc, tc -dx+2.0*dy), d(pc, tc +2.0*dy), d(pc, tc +dx+2.0*dy), d(pc, tc+2.0*dx+2.0*dy)));
//weights[0][0] = weights[0][3] = weights[3][0] = weights[3][3] = 0.0;
dx = dx / params.SourceSize.xy;
dy = dy / params.SourceSize.xy;
tc = tc / params.SourceSize.xy;
// reading the texels
vec3 c00 = texture(Source, tc -dx -dy).xyz;
vec3 c10 = texture(Source, tc -dy).xyz;
vec3 c20 = texture(Source, tc +dx -dy).xyz;
vec3 c30 = texture(Source, tc+2.0*dx -dy).xyz;
vec3 c01 = texture(Source, tc -dx ).xyz;
vec3 c11 = texture(Source, tc ).xyz;
vec3 c21 = texture(Source, tc +dx ).xyz;
vec3 c31 = texture(Source, tc+2.0*dx ).xyz;
vec3 c02 = texture(Source, tc -dx +dy).xyz;
vec3 c12 = texture(Source, tc +dy).xyz;
vec3 c22 = texture(Source, tc +dx +dy).xyz;
vec3 c32 = texture(Source, tc+2.0*dx +dy).xyz;
vec3 c03 = texture(Source, tc -dx+2.0*dy).xyz;
vec3 c13 = texture(Source, tc +2.0*dy).xyz;
vec3 c23 = texture(Source, tc +dx+2.0*dy).xyz;
vec3 c33 = texture(Source, tc+2.0*dx+2.0*dy).xyz;
color = mul(weights[0], mat4x3(c00, c10, c20, c30));
color+= mul(weights[1], mat4x3(c01, c11, c21, c31));
color+= mul(weights[2], mat4x3(c02, c12, c22, c32));
color+= mul(weights[3], mat4x3(c03, c13, c23, c33));
color = color/(dot(mul(weights, vec4(1.)), vec4(1.)));
// Anti-ringing
// Get min/max samples
pc = vTexCoord;
c00 = texture(Source, pc ).xyz;
c11 = texture(Source, pc +dx ).xyz;
c21 = texture(Source, pc -dx ).xyz;
c12 = texture(Source, pc +dy).xyz;
c22 = texture(Source, pc -dy).xyz;
vec3 min_sample = min4(c11, c21, c12, c22);
vec3 max_sample = max4(c11, c21, c12, c22);
min_sample = min(min_sample, c00);
max_sample = max(max_sample, c00);
vec3 aux = color;
color = clamp(color, min_sample, max_sample);
color = mix(aux, color, params.JINC2_AR_STRENGTH);
FragColor = vec4(color, 1.);
}

View file

@ -0,0 +1,255 @@
#version 450
/*
******* Super XBR 3D Shader - pass0 *******
Copyright (c) 2016 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 XBR_EDGE_STR;
float XBR_WEIGHT;
float XBR_ANTI_RINGING;
} params;
#pragma parameter XBR_EDGE_STR "Xbr - Edge Strength p0" 0.6 0.0 5.0 0.5
#pragma parameter XBR_WEIGHT "Xbr - Filter Weight" 1.0 0.00 1.50 0.05
#pragma parameter XBR_ANTI_RINGING "Xbr - Anti-Ringing Level" 1.0 0.0 1.0 1.0
#define XBR_EDGE_STR params.XBR_EDGE_STR
#define XBR_WEIGHT params.XBR_WEIGHT
#define XBR_ANTI_RINGING params.XBR_ANTI_RINGING
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;
#define mul(a,b) (b*a)
#define XBR_RES 2.0
#define wp1 1.0
#define wp2 0.0
#define wp3 0.0
#define wp4 2.0
#define wp5 -1.0
#define wp6 0.0
#define weight1 (XBR_WEIGHT*1.29633/10.0)
#define weight2 (XBR_WEIGHT*1.75068/10.0/2.0)
const vec3 Y = vec3(.2126, .7152, .0722);
const vec3 dtt = vec3(65536.,255.,1.);
vec4 reduce4(vec3 A, vec3 B, vec3 C, vec3 D)
{
return mul(mat4x3(A, B, C, D), dtt);
}
float RGBtoYUV(vec3 color)
{
return dot(color, Y);
}
float df(float A, float B)
{
return abs(A-B);
}
bool eq(float A, float B)
{
return (df(A, B) < 15.0);
}
/*
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 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 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)));
}
#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()
{
//Skip pixels on wrong grid
if (any(lessThan(fract(vTexCoord*params.SourceSize.xy/XBR_RES) , vec2(0.5,0.5))))
{
FragColor = texture(Source, vTexCoord);
}
else
{
vec2 tex = (floor(vTexCoord*params.SourceSize.xy/XBR_RES) + vec2(0.5, 0.5))*XBR_RES/params.SourceSize.xy;
vec2 g1 = vec2(XBR_RES/params.SourceSize.x, 0.0);
vec2 g2 = vec2(0.0, XBR_RES/params.SourceSize.y);
vec3 P0 = texture(Source, vTexCoord -g1 -g2).xyz;
vec3 P1 = texture(Source, vTexCoord +2.0*g1 -g2).xyz;
vec3 P2 = texture(Source, vTexCoord -g1+2.0*g2).xyz;
vec3 P3 = texture(Source, vTexCoord +2.0*g1+2.0*g2).xyz;
vec3 B = texture(Source, vTexCoord -g2).xyz;
vec3 C = texture(Source, vTexCoord +g1-g2).xyz;
vec3 D = texture(Source, vTexCoord -g1 ).xyz;
vec3 E = texture(Source, vTexCoord ).xyz;
vec3 F = texture(Source, vTexCoord +g1 ).xyz;
vec3 G = texture(Source, vTexCoord -g1+g2).xyz;
vec3 H = texture(Source, vTexCoord +g2).xyz;
vec3 I = texture(Source, vTexCoord +g1+g2).xyz;
vec3 F4 = texture(Source, vTexCoord +2.0*g1 ).xyz;
vec3 I4 = texture(Source, vTexCoord +g2+2.0*g1 ).xyz;
vec3 H5 = texture(Source, vTexCoord +2.0*g2 ).xyz;
vec3 I5 = texture(Source, vTexCoord +2.0*g2+g1 ).xyz;
vec3 F6 = texture(Source, tex +g1+0.25*g1+0.25*g2).xyz;
vec3 F7 = texture(Source, tex +g1+0.25*g1-0.25*g2).xyz;
vec3 F8 = texture(Source, tex +g1-0.25*g1-0.25*g2).xyz;
vec3 F9 = texture(Source, tex +g1-0.25*g1+0.25*g2).xyz;
vec3 H6 = texture(Source, tex +0.25*g1+0.25*g2+g2).xyz;
vec3 H7 = texture(Source, tex +0.25*g1-0.25*g2+g2).xyz;
vec3 H8 = texture(Source, tex -0.25*g1-0.25*g2+g2).xyz;
vec3 H9 = texture(Source, tex -0.25*g1+0.25*g2+g2).xyz;
vec4 f0 = reduce4(F6, F7, F8, F9);
vec4 h0 = reduce4(H6, H7, H8, H9);
bool block_3d = ((f0.xyz == f0.yzw) && (h0.xyz == h0.yzw));
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 );
/*
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
*/
/* Calc edgeness in diagonal directions. */
float d_edge = (d_wd( d, b, g, e, c, p2, h, f, p1, h5, i, f4, i5, i4 ) - d_wd( 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(f, i, e, h, c, i5, b, h5) - hv_wd(e, f, h, i, d, f4, g, i4));
float limits = XBR_EDGE_STR + 0.000001;
float edge_strength = smoothstep(0.0, limits, abs(d_edge));
/* Filter weights. Two taps only. */
vec4 w1 = vec4(-weight1, weight1+0.5, weight1+0.5, -weight1);
vec4 w2 = vec4(-weight2, weight2+0.25, weight2+0.25, -weight2);
/* 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 ));
vec3 c3 = mul(w2, mat4x3(D+G, E+H, F+I, F4+I4));
vec3 c4 = mul(w2, mat4x3(C+B, F+E, I+H, I5+H5));
bool ir_lv1 = (((e!=f) && (e!=h)) && ( !eq(f,b) && !eq(f,c) || !eq(h,d) && !eq(h,g) || eq(e,i) && (!eq(f,f4) && !eq(f,i4) || !eq(h,h5) && !eq(h,i5)) || eq(e,g) || eq(e,c)) );
/* 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);
/*
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
*/
/* 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));
color = clamp(color, min_sample, max_sample);
color = block_3d ? color : E;
FragColor = vec4(color, 1.0);
}
}

View file

@ -0,0 +1,232 @@
#version 450
/*
******* Super XBR 3D Shader - pass1 *******
Copyright (c) 2016 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;
} params;
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;
const float XBR_EDGE_STR = 0.0;
const float XBR_WEIGHT = 0.0;
const float XBR_ANTI_RINGING = 0.0;
#define mul(a,b) (b*a)
#define XBR_RES 2.0
#define wp1 1.0
#define wp2 0.0
#define wp3 0.0
#define wp4 2.0
#define wp5 -1.0
#define wp6 0.0
#define weight1 (XBR_WEIGHT*1.75068/10.0)
#define weight2 (XBR_WEIGHT*1.29633/10.0/2.0)
const vec3 Y = vec3(.2126, .7152, .0722);
const vec3 dtt = vec3(65536.,255.,1.);
vec4 reduce4(vec3 A, vec3 B, vec3 C, vec3 D)
{
return mul(mat4x3(A, B, C, D), dtt);
}
float RGBtoYUV(vec3 color)
{
return dot(color, Y);
}
float df(float A, float B)
{
return abs(A-B);
}
bool eq(float A, float B)
{
return (df(A, B) < 15.0);
}
/*
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 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 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)));
}
#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;
layout(set = 0, binding = 3) uniform sampler2D Original;
void main()
{
//Skip pixels on wrong grid
vec2 dir = fract(vTexCoord*params.SourceSize.xy/XBR_RES) - vec2(0.5,0.5);
if ((dir.x*dir.y)>0.0){
FragColor = texture(Source, vTexCoord);
}else{
vec2 tex = (floor(vTexCoord*params.SourceSize.xy/XBR_RES) + vec2(0.5, 0.5))*XBR_RES/params.SourceSize.xy;
vec2 g1 = vec2((XBR_RES/2.0)/params.SourceSize.x, 0.0);
vec2 g2 = vec2(0.0, (XBR_RES/2.0)/params.SourceSize.y);
vec3 P0 = texture(Source, 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(Source, vTexCoord +3.0*g1 ).xyz;
vec3 B = texture(Source, vTexCoord -2.0*g1 -g2).xyz;
vec3 C = texture(Source, vTexCoord -g1 -2.0*g2).xyz;
vec3 D = texture(Source, vTexCoord -2.0*g1 +g2).xyz;
vec3 E = texture(Source, vTexCoord -g1 ).xyz;
vec3 F = texture(Source, vTexCoord -g2).xyz;
vec3 G = texture(Source, vTexCoord -g1 +2.0*g2).xyz;
vec3 H = texture(Source, vTexCoord +g2).xyz;
vec3 I = texture(Source, vTexCoord +g1 ).xyz;
vec3 F4 = texture(Source,vTexCoord +g1 -2.0*g2).xyz;
vec3 I4 = texture(Source,vTexCoord +2.0*g1 -g2).xyz;
vec3 H5 = texture(Source,vTexCoord +g1 +2.0*g2).xyz;
vec3 I5 = texture(Source,vTexCoord +2.0*g1 +g2).xyz;
vec3 A = texture(Source, vTexCoord).xyz;
g1 *= 2.0;
g2 *= 2.0;
vec3 F6 = texture(Original, tex +g1+0.25*g1+0.25*g2).xyz;
vec3 F7 = texture(Original, tex +g1+0.25*g1-0.25*g2).xyz;
vec3 F8 = texture(Original, tex +g1-0.25*g1-0.25*g2).xyz;
vec3 F9 = texture(Original, tex +g1-0.25*g1+0.25*g2).xyz;
vec3 H6 = texture(Original, tex +0.25*g1+0.25*g2+g2).xyz;
vec3 H7 = texture(Original, tex +0.25*g1-0.25*g2+g2).xyz;
vec3 H8 = texture(Original, tex -0.25*g1-0.25*g2+g2).xyz;
vec3 H9 = texture(Original, tex -0.25*g1+0.25*g2+g2).xyz;
vec4 f0 = reduce4(F6, F7, F8, F9);
vec4 h0 = reduce4(H6, H7, H8, H9);
bool block_3d = ((f0.xyz==f0.yzw) && (h0.xyz==h0.yzw));
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( d, b, g, e, c, p2, h, f, p1, h5, i, f4, i5, i4 ) - d_wd( 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(f, i, e, h, c, i5, b, h5) - hv_wd(e, f, h, i, d, f4, g, i4));
float limits = XBR_EDGE_STR + 0.000001;
float edge_strength = smoothstep(0.0, limits, abs(d_edge));
/* Filter weights. Two taps only. */
vec4 w1 = vec4(-weight1, weight1+0.5, weight1+0.5, -weight1);
vec4 w2 = vec4(-weight2, weight2+0.25, weight2+0.25, -weight2);
/* 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 ));
vec3 c3 = mul(w2, mat4x3(D+G, E+H, F+I, F4+I4));
vec3 c4 = mul(w2, mat4x3(C+B, F+E, I+H, I5+H5));
bool ir_lv1 = (((e!=f) && (e!=h)) && ( !eq(f,b) && !eq(f,c) || !eq(h,d) && !eq(h,g) || eq(e,i) && (!eq(f,f4) && !eq(f,i4) || !eq(h,h5) && !eq(h,i5)) || eq(e,g) || eq(e,c)) );
/* 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 ) + (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));
color = clamp(color, min_sample, max_sample);
color = block_3d ? color : A;
FragColor = vec4(color, 1.0);
}
}

View file

@ -0,0 +1,246 @@
#version 450
/*
******* Super XBR Shader - pass2 ******* This pass is optional.
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.
*/
const float XBR_EDGE_STR = 0.0;
const float XBR_WEIGHT = 0.0;
const float XBR_ANTI_RINGING = 0.0;
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;
#define mul(a,b) (b*a)
#define XBR_RES 2.0
#define wp1 1.0
#define wp2 0.0
#define wp3 0.0
#define wp4 0.0
#define wp5 -1.0
#define wp6 0.0
#define weight1 (XBR_WEIGHT*1.29633/10.0)
#define weight2 (XBR_WEIGHT*1.75068/10.0/2.0)
const vec3 Y = vec3(.2126, .7152, .0722);
const vec3 dtt = vec3(65536.,255.,1.);
vec4 reduce4(vec3 A, vec3 B, vec3 C, vec3 D)
{
return mul(mat4x3(A, B, C, D), dtt);
}
float RGBtoYUV(vec3 color)
{
return dot(color, Y);
}
float df(float A, float B)
{
return abs(A-B);
}
bool eq(float A, float B)
{
return (df(A, B) < 15.0);
}
/*
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 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 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)));
}
#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 vec4 t1;
layout(location = 2) out vec4 t2;
layout(location = 3) out vec4 t3;
layout(location = 4) out vec4 t4;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
float dx = params.SourceSize.z;
float dy = params.SourceSize.w;
t1 = vTexCoord.xyxy + vec4(-2.0*dx, -2.0*dy, dx, dy);
t2 = vTexCoord.xyxy + vec4( -dx, -2.0*dy, 0, dy);
t3 = vTexCoord.xyxy + vec4(-2.0*dx, -dy, dx, 0);
t4 = vTexCoord.xyxy + vec4( -dx, -dy, 0, 0);
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in vec4 t1;
layout(location = 2) in vec4 t2;
layout(location = 3) in vec4 t3;
layout(location = 4) in vec4 t4;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
layout(set = 0, binding = 3) uniform sampler2D Original;
void main()
{
vec2 tex = (floor(vTexCoord*params.SourceSize.xy/XBR_RES) + vec2(0.5, 0.5))*XBR_RES/params.SourceSize.xy;
vec2 g1 = vec2(XBR_RES/params.SourceSize.x, 0.0);
vec2 g2 = vec2(0.0, XBR_RES/params.SourceSize.y);
vec3 P0 = texture(Source, t1.xy).xyz;
vec3 P1 = texture(Source, t1.zy).xyz;
vec3 P2 = texture(Source, t1.xw).xyz;
vec3 P3 = texture(Source, t1.zw).xyz;
vec3 B = texture(Source, t2.xy).xyz;
vec3 C = texture(Source, t2.zy).xyz;
vec3 H5 = texture(Source, t2.xw).xyz;
vec3 I5 = texture(Source, t2.zw).xyz;
vec3 D = texture(Source, t3.xy).xyz;
vec3 F4 = texture(Source, t3.zy).xyz;
vec3 G = texture(Source, t3.xw).xyz;
vec3 I4 = texture(Source, t3.zw).xyz;
vec3 E = texture(Source, t4.xy).xyz;
vec3 F = texture(Source, t4.zy).xyz;
vec3 H = texture(Source, t4.xw).xyz;
vec3 I = texture(Source, t4.zw).xyz;
vec3 A = texture(Source, vTexCoord).xyz;
vec3 F6 = texture(Original, tex +g1+0.25*g1+0.25*g2).xyz;
vec3 F7 = texture(Original, tex +g1+0.25*g1-0.25*g2).xyz;
vec3 F8 = texture(Original, tex +g1-0.25*g1-0.25*g2).xyz;
vec3 F9 = texture(Original, tex +g1-0.25*g1+0.25*g2).xyz;
vec3 H6 = texture(Original, tex +0.25*g1+0.25*g2+g2).xyz;
vec3 H7 = texture(Original, tex +0.25*g1-0.25*g2+g2).xyz;
vec3 H8 = texture(Original, tex -0.25*g1-0.25*g2+g2).xyz;
vec3 H9 = texture(Original, tex -0.25*g1+0.25*g2+g2).xyz;
vec4 f0 = reduce4(F6, F7, F8, F9);
vec4 h0 = reduce4(H6, H7, H8, H9);
bool block_3d = ((f0.xyz==f0.yzw) && (h0.xyz==h0.yzw));
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 );
/*
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
*/
/* Calc edgeness in diagonal directions. */
float d_edge = (d_wd( d, b, g, e, c, p2, h, f, p1, h5, i, f4, i5, i4 ) - d_wd( 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(f, i, e, h, c, i5, b, h5) - hv_wd(e, f, h, i, d, f4, g, i4));
float limits = XBR_EDGE_STR + 0.000001;
float edge_strength = smoothstep(0.0, limits, abs(d_edge));
/* Filter weights. Two taps only. */
vec4 w1 = vec4(-weight1, weight1+0.5, weight1+0.5, -weight1);
vec4 w2 = vec4(-weight2, weight2+0.25, weight2+0.25, -weight2);
/* 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 ));
vec3 c3 = mul(w2, mat4x3(D+G, E+H, F+I, F4+I4));
vec3 c4 = mul(w2, mat4x3(C+B, F+E, I+H, I5+H5));
bool ir_lv1 = (((e!=f) && (e!=h)) && ( !eq(f,b) && !eq(f,c) || !eq(h,d) && !eq(h,g) || eq(e,i) && (!eq(f,f4) && !eq(f,i4) || !eq(h,h5) && !eq(h,i5)) || eq(e,g) || eq(e,c)) );
/* 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 ) + (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));
color = clamp(color, min_sample, max_sample);
color = block_3d ? color : A;
FragColor = vec4(color, 1.0);
}

View file

@ -0,0 +1,255 @@
#version 450
/*
******* Super 4XBR 3D Shader - pass0 *******
Copyright (c) 2016 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 XBR_EDGE_STR;
float XBR_WEIGHT;
float XBR_ANTI_RINGING;
} params;
#pragma parameter XBR_EDGE_STR "Xbr - Edge Strength p0" 0.6 0.0 5.0 0.5
#pragma parameter XBR_WEIGHT "Xbr - Filter Weight" 1.0 0.00 1.50 0.05
#pragma parameter XBR_ANTI_RINGING "Xbr - Anti-Ringing Level" 1.0 0.0 1.0 1.0
#define XBR_EDGE_STR params.XBR_EDGE_STR
#define XBR_WEIGHT params.XBR_WEIGHT
#define XBR_ANTI_RINGING params.XBR_ANTI_RINGING
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;
#define mul(a,b) (b*a)
#define XBR_RES 4.0
#define wp1 1.0
#define wp2 0.0
#define wp3 0.0
#define wp4 2.0
#define wp5 -1.0
#define wp6 0.0
#define weight1 (XBR_WEIGHT*1.29633/10.0)
#define weight2 (XBR_WEIGHT*1.75068/10.0/2.0)
const vec3 Y = vec3(.2126, .7152, .0722);
const vec3 dtt = vec3(65536.,255.,1.);
vec4 reduce4(vec3 A, vec3 B, vec3 C, vec3 D)
{
return mul(mat4x3(A, B, C, D), dtt);
}
float RGBtoYUV(vec3 color)
{
return dot(color, Y);
}
float df(float A, float B)
{
return abs(A-B);
}
bool eq(float A, float B)
{
return (df(A, B) < 15.0);
}
/*
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 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 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)));
}
#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()
{
//Skip pixels on wrong grid
if (any(lessThan(fract(vTexCoord*params.SourceSize.xy/XBR_RES) , vec2(0.5,0.5))))
{
FragColor = texture(Source, vTexCoord);
}
else
{
vec2 tex = (floor(vTexCoord*params.SourceSize.xy/XBR_RES) + vec2(0.5, 0.5))*XBR_RES/params.SourceSize.xy;
vec2 g1 = vec2(XBR_RES/params.SourceSize.x, 0.0);
vec2 g2 = vec2(0.0, XBR_RES/params.SourceSize.y);
vec3 P0 = texture(Source, vTexCoord -g1 -g2).xyz;
vec3 P1 = texture(Source, vTexCoord +2.0*g1 -g2).xyz;
vec3 P2 = texture(Source, vTexCoord -g1+2.0*g2).xyz;
vec3 P3 = texture(Source, vTexCoord +2.0*g1+2.0*g2).xyz;
vec3 B = texture(Source, vTexCoord -g2).xyz;
vec3 C = texture(Source, vTexCoord +g1-g2).xyz;
vec3 D = texture(Source, vTexCoord -g1 ).xyz;
vec3 E = texture(Source, vTexCoord ).xyz;
vec3 F = texture(Source, vTexCoord +g1 ).xyz;
vec3 G = texture(Source, vTexCoord -g1+g2).xyz;
vec3 H = texture(Source, vTexCoord +g2).xyz;
vec3 I = texture(Source, vTexCoord +g1+g2).xyz;
vec3 F4 = texture(Source, vTexCoord +2.0*g1 ).xyz;
vec3 I4 = texture(Source, vTexCoord +g2+2.0*g1 ).xyz;
vec3 H5 = texture(Source, vTexCoord +2.0*g2 ).xyz;
vec3 I5 = texture(Source, vTexCoord +2.0*g2+g1 ).xyz;
vec3 F6 = texture(Source, tex +g1+0.25*g1+0.25*g2).xyz;
vec3 F7 = texture(Source, tex +g1+0.25*g1-0.25*g2).xyz;
vec3 F8 = texture(Source, tex +g1-0.25*g1-0.25*g2).xyz;
vec3 F9 = texture(Source, tex +g1-0.25*g1+0.25*g2).xyz;
vec3 H6 = texture(Source, tex +0.25*g1+0.25*g2+g2).xyz;
vec3 H7 = texture(Source, tex +0.25*g1-0.25*g2+g2).xyz;
vec3 H8 = texture(Source, tex -0.25*g1-0.25*g2+g2).xyz;
vec3 H9 = texture(Source, tex -0.25*g1+0.25*g2+g2).xyz;
vec4 f0 = reduce4(F6, F7, F8, F9);
vec4 h0 = reduce4(H6, H7, H8, H9);
bool block_3d = ((f0.xyz == f0.yzw) && (h0.xyz == h0.yzw));
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 );
/*
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
*/
/* Calc edgeness in diagonal directions. */
float d_edge = (d_wd( d, b, g, e, c, p2, h, f, p1, h5, i, f4, i5, i4 ) - d_wd( 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(f, i, e, h, c, i5, b, h5) - hv_wd(e, f, h, i, d, f4, g, i4));
float limits = XBR_EDGE_STR + 0.000001;
float edge_strength = smoothstep(0.0, limits, abs(d_edge));
/* Filter weights. Two taps only. */
vec4 w1 = vec4(-weight1, weight1+0.5, weight1+0.5, -weight1);
vec4 w2 = vec4(-weight2, weight2+0.25, weight2+0.25, -weight2);
/* 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 ));
vec3 c3 = mul(w2, mat4x3(D+G, E+H, F+I, F4+I4));
vec3 c4 = mul(w2, mat4x3(C+B, F+E, I+H, I5+H5));
bool ir_lv1 = (((e!=f) && (e!=h)) && ( !eq(f,b) && !eq(f,c) || !eq(h,d) && !eq(h,g) || eq(e,i) && (!eq(f,f4) && !eq(f,i4) || !eq(h,h5) && !eq(h,i5)) || eq(e,g) || eq(e,c)) );
/* 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);
/*
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
*/
/* 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));
color = clamp(color, min_sample, max_sample);
color = block_3d ? color : E;
FragColor = vec4(color, 1.0);
}
}

View file

@ -0,0 +1,230 @@
#version 450
/*
******* Super 4XBR 3D Shader - pass1 *******
Copyright (c) 2016 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;
} params;
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;
const float XBR_EDGE_STR = 0.0;
const float XBR_WEIGHT = 0.0;
const float XBR_ANTI_RINGING = 0.0;
#define mul(a,b) (b*a)
#define XBR_RES 4.0
#define wp1 1.0
#define wp2 0.0
#define wp3 0.0
#define wp4 4.0
#define wp5 0.0
#define wp6 0.0
#define weight1 (XBR_WEIGHT*1.75068/10.0)
#define weight2 (XBR_WEIGHT*1.29633/10.0/2.0)
const vec3 Y = vec3(.2126, .7152, .0722);
const vec3 dtt = vec3(65536.,255.,1.);
vec4 reduce4(vec3 A, vec3 B, vec3 C, vec3 D)
{
return mul(mat4x3(A, B, C, D), dtt);
}
float RGBtoYUV(vec3 color)
{
return dot(color, Y);
}
float df(float A, float B)
{
return abs(A-B);
}
bool eq(float A, float B)
{
return (df(A, B) < 15.0);
}
/*
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 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 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)));
}
#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;
layout(set = 0, binding = 3) uniform sampler2D Original;
void main()
{
//Skip pixels on wrong grid
vec2 dir = fract(vTexCoord*params.SourceSize.xy/XBR_RES) - vec2(0.5,0.5);
if ((dir.x*dir.y)>0.0) {
FragColor = texture(Source, vTexCoord);
}else{
vec2 tex = (floor(vTexCoord*params.SourceSize.xy/XBR_RES) + vec2(0.5, 0.5))*XBR_RES/params.SourceSize.xy;
vec2 g1 = vec2((XBR_RES/2.0)/params.SourceSize.x, 0.0);
vec2 g2 = vec2(0.0, (XBR_RES/2.0)/params.SourceSize.y);
vec3 P0 = texture(Source, 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(Source, vTexCoord +3.0*g1 ).xyz;
vec3 B = texture(Source, vTexCoord -2.0*g1 -g2).xyz;
vec3 C = texture(Source, vTexCoord -g1 -2.0*g2).xyz;
vec3 D = texture(Source, vTexCoord -2.0*g1 +g2).xyz;
vec3 E = texture(Source, vTexCoord -g1 ).xyz;
vec3 F = texture(Source, vTexCoord -g2).xyz;
vec3 G = texture(Source, vTexCoord -g1 +2.0*g2).xyz;
vec3 H = texture(Source, vTexCoord +g2).xyz;
vec3 I = texture(Source, vTexCoord +g1 ).xyz;
vec3 F4 = texture(Source,vTexCoord +g1 -2.0*g2).xyz;
vec3 I4 = texture(Source,vTexCoord +2.0*g1 -g2).xyz;
vec3 H5 = texture(Source,vTexCoord +g1 +2.0*g2).xyz;
vec3 I5 = texture(Source,vTexCoord +2.0*g1 +g2).xyz;
vec3 A = texture(Source, vTexCoord).xyz;
g1 *= 2.0;
g2 *= 2.0;
vec3 F6 = texture(Original, tex +g1+0.25*g1+0.25*g2).xyz;
vec3 F7 = texture(Original, tex +g1+0.25*g1-0.25*g2).xyz;
vec3 F8 = texture(Original, tex +g1-0.25*g1-0.25*g2).xyz;
vec3 F9 = texture(Original, tex +g1-0.25*g1+0.25*g2).xyz;
vec3 H6 = texture(Original, tex +0.25*g1+0.25*g2+g2).xyz;
vec3 H7 = texture(Original, tex +0.25*g1-0.25*g2+g2).xyz;
vec3 H8 = texture(Original, tex -0.25*g1-0.25*g2+g2).xyz;
vec3 H9 = texture(Original, tex -0.25*g1+0.25*g2+g2).xyz;
vec4 f0 = reduce4(F6, F7, F8, F9);
vec4 h0 = reduce4(H6, H7, H8, H9);
bool block_3d = ((f0.xyz==f0.yzw) && (h0.xyz==h0.yzw));
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( d, b, g, e, c, p2, h, f, p1, h5, i, f4, i5, i4 ) - d_wd( 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(f, i, e, h, c, i5, b, h5) - hv_wd(e, f, h, i, d, f4, g, i4));
float limits = XBR_EDGE_STR + 0.000001;
float edge_strength = smoothstep(0.0, limits, abs(d_edge));
/* Filter weights. Two taps only. */
vec4 w1 = vec4(-weight1, weight1+0.5, weight1+0.5, -weight1);
vec4 w2 = vec4(-weight2, weight2+0.25, weight2+0.25, -weight2);
/* 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 ));
vec3 c3 = mul(w2, mat4x3(D+G, E+H, F+I, F4+I4));
vec3 c4 = mul(w2, mat4x3(C+B, F+E, I+H, I5+H5));
bool ir_lv1 = (((e!=f) && (e!=h)) && ( !eq(f,b) && !eq(f,c) || !eq(h,d) && !eq(h,g) || eq(e,i) && (!eq(f,f4) && !eq(f,i4) || !eq(h,h5) && !eq(h,i5)) || eq(e,g) || eq(e,c)) );
/* 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 ) + (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));
color = clamp(color, min_sample, max_sample);
color = block_3d ? color : A;
FragColor = vec4(color, 1.0);
}
}

View file

@ -0,0 +1,246 @@
#version 450
/*
******* Super 4XBR 3D Shader - pass1 *******
Copyright (c) 2016 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;
} params;
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;
const float XBR_EDGE_STR = 0.0;
const float XBR_WEIGHT = 0.0;
const float XBR_ANTI_RINGING = 0.0;
#define mul(a,b) (b*a)
#define XBR_RES 4.0
#define wp1 1.0
#define wp2 0.0
#define wp3 0.0
#define wp4 0.0
#define wp5 -1.0
#define wp6 0.0
#define weight1 (XBR_WEIGHT*1.29633/10.0)
#define weight2 (XBR_WEIGHT*1.75068/10.0/2.0)
const vec3 Y = vec3(.2126, .7152, .0722);
const vec3 dtt = vec3(65536.,255.,1.);
vec4 reduce4(vec3 A, vec3 B, vec3 C, vec3 D)
{
return mul(mat4x3(A, B, C, D), dtt);
}
float RGBtoYUV(vec3 color)
{
return dot(color, Y);
}
float df(float A, float B)
{
return abs(A-B);
}
bool eq(float A, float B)
{
return (df(A, B) < 15.0);
}
/*
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 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 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)));
}
#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 vec4 t1;
layout(location = 2) out vec4 t2;
layout(location = 3) out vec4 t3;
layout(location = 4) out vec4 t4;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
float dx = params.SourceSize.z;
float dy = params.SourceSize.w;
t1 = vTexCoord.xyxy + vec4(-2.0*dx, -2.0*dy, dx, dy);
t2 = vTexCoord.xyxy + vec4( -dx, -2.0*dy, 0, dy);
t3 = vTexCoord.xyxy + vec4(-2.0*dx, -dy, dx, 0);
t4 = vTexCoord.xyxy + vec4( -dx, -dy, 0, 0);
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in vec4 t1;
layout(location = 2) in vec4 t2;
layout(location = 3) in vec4 t3;
layout(location = 4) in vec4 t4;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
layout(set = 0, binding = 3) uniform sampler2D Original;
void main()
{
vec2 tex = (floor(vTexCoord*params.SourceSize.xy/XBR_RES) + vec2(0.5, 0.5))*XBR_RES/params.SourceSize.xy;
vec2 g1 = vec2((XBR_RES/2.0)/params.SourceSize.x, 0.0);
vec2 g2 = vec2(0.0, (XBR_RES/2.0)/params.SourceSize.y);
vec3 P0 = texture(Source, t1.xy).xyz;
vec3 P1 = texture(Source, t1.zy).xyz;
vec3 P2 = texture(Source, t1.xw).xyz;
vec3 P3 = texture(Source, t1.zw).xyz;
vec3 B = texture(Source, t2.xy).xyz;
vec3 C = texture(Source, t2.zy).xyz;
vec3 H5 = texture(Source, t2.xw).xyz;
vec3 I5 = texture(Source, t2.zw).xyz;
vec3 D = texture(Source, t3.xy).xyz;
vec3 F4 = texture(Source, t3.zy).xyz;
vec3 G = texture(Source, t3.xw).xyz;
vec3 I4 = texture(Source, t3.zw).xyz;
vec3 E = texture(Source, t4.xy).xyz;
vec3 F = texture(Source, t4.zy).xyz;
vec3 H = texture(Source, t4.xw).xyz;
vec3 I = texture(Source, t4.zw).xyz;
vec3 A = texture(Source, vTexCoord).xyz;
vec3 F6 = texture(Original, tex +g1+0.25*g1+0.25*g2).xyz;
vec3 F7 = texture(Original, tex +g1+0.25*g1-0.25*g2).xyz;
vec3 F8 = texture(Original, tex +g1-0.25*g1-0.25*g2).xyz;
vec3 F9 = texture(Original, tex +g1-0.25*g1+0.25*g2).xyz;
vec3 H6 = texture(Original, tex +0.25*g1+0.25*g2+g2).xyz;
vec3 H7 = texture(Original, tex +0.25*g1-0.25*g2+g2).xyz;
vec3 H8 = texture(Original, tex -0.25*g1-0.25*g2+g2).xyz;
vec3 H9 = texture(Original, tex -0.25*g1+0.25*g2+g2).xyz;
vec4 f0 = reduce4(F6, F7, F8, F9);
vec4 h0 = reduce4(H6, H7, H8, H9);
bool block_3d = ((f0.xyz==f0.yzw) && (h0.xyz==h0.yzw));
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 );
/*
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
*/
/* Calc edgeness in diagonal directions. */
float d_edge = (d_wd( d, b, g, e, c, p2, h, f, p1, h5, i, f4, i5, i4 ) - d_wd( 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(f, i, e, h, c, i5, b, h5) - hv_wd(e, f, h, i, d, f4, g, i4));
float limits = XBR_EDGE_STR + 0.000001;
float edge_strength = smoothstep(0.0, limits, abs(d_edge));
/* Filter weights. Two taps only. */
vec4 w1 = vec4(-weight1, weight1+0.5, weight1+0.5, -weight1);
vec4 w2 = vec4(-weight2, weight2+0.25, weight2+0.25, -weight2);
/* 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 ));
vec3 c3 = mul(w2, mat4x3(D+G, E+H, F+I, F4+I4));
vec3 c4 = mul(w2, mat4x3(C+B, F+E, I+H, I5+H5));
bool ir_lv1 = (((e!=f) && (e!=h)) && ( !eq(f,b) && !eq(f,c) || !eq(h,d) && !eq(h,g) || eq(e,i) && (!eq(f,f4) && !eq(f,i4) || !eq(h,h5) && !eq(h,i5)) || eq(e,g) || eq(e,c)) );
/* 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 ) + (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));
color = clamp(color, min_sample, max_sample);
color = block_3d ? color : A;
FragColor = vec4(color, 1.0);
}

View file

@ -0,0 +1,246 @@
#version 450
/*
******* Super 4XBR Shader - pass2 *******
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.
*/
const float XBR_EDGE_STR = 0.0;
const float XBR_WEIGHT = 0.0;
const float XBR_ANTI_RINGING = 0.0;
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;
#define mul(a,b) (b*a)
#define XBR_RES 2.0
#define wp1 1.0
#define wp2 0.0
#define wp3 0.0
#define wp4 2.0
#define wp5 -1.0
#define wp6 0.0
#define weight1 (XBR_WEIGHT*1.29633/10.0)
#define weight2 (XBR_WEIGHT*1.75068/10.0/2.0)
const vec3 Y = vec3(.2126, .7152, .0722);
const vec3 dtt = vec3(65536.,255.,1.);
vec4 reduce4(vec3 A, vec3 B, vec3 C, vec3 D)
{
return mul(mat4x3(A, B, C, D), dtt);
}
float RGBtoYUV(vec3 color)
{
return dot(color, Y);
}
float df(float A, float B)
{
return abs(A-B);
}
bool eq(float A, float B)
{
return (df(A, B) < 15.0);
}
/*
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 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 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)));
}
#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;
layout(set = 0, binding = 3) uniform sampler2D Original;
void main()
{
//Skip pixels on wrong grid
if (any(lessThan(fract(vTexCoord*params.SourceSize.xy/XBR_RES) , vec2(0.5,0.5))))
{
FragColor = texture(Source, vTexCoord);
}
else
{
vec2 tex = (floor(vTexCoord*params.SourceSize.xy/XBR_RES) + vec2(0.5, 0.5))*XBR_RES/params.SourceSize.xy;
vec2 g1 = vec2(XBR_RES/params.SourceSize.x, 0.0);
vec2 g2 = vec2(0.0, XBR_RES/params.SourceSize.y);
vec3 P0 = texture(Source, vTexCoord -g1 -g2).xyz;
vec3 P1 = texture(Source, vTexCoord +2.0*g1 -g2).xyz;
vec3 P2 = texture(Source, vTexCoord -g1+2.0*g2).xyz;
vec3 P3 = texture(Source, vTexCoord +2.0*g1+2.0*g2).xyz;
vec3 B = texture(Source, vTexCoord -g2).xyz;
vec3 C = texture(Source, vTexCoord +g1-g2).xyz;
vec3 D = texture(Source, vTexCoord -g1 ).xyz;
vec3 E = texture(Source, vTexCoord ).xyz;
vec3 F = texture(Source, vTexCoord +g1 ).xyz;
vec3 G = texture(Source, vTexCoord -g1+g2).xyz;
vec3 H = texture(Source, vTexCoord +g2).xyz;
vec3 I = texture(Source, vTexCoord +g1+g2).xyz;
vec3 F4 = texture(Source, vTexCoord +2.0*g1 ).xyz;
vec3 I4 = texture(Source, vTexCoord +g2+2.0*g1 ).xyz;
vec3 H5 = texture(Source, vTexCoord +2.0*g2 ).xyz;
vec3 I5 = texture(Source, vTexCoord +2.0*g2+g1 ).xyz;
vec3 F6 = texture(Source, tex +g1+0.25*g1+0.25*g2).xyz;
vec3 F7 = texture(Source, tex +g1+0.25*g1-0.25*g2).xyz;
vec3 F8 = texture(Source, tex +g1-0.25*g1-0.25*g2).xyz;
vec3 F9 = texture(Source, tex +g1-0.25*g1+0.25*g2).xyz;
vec3 H6 = texture(Source, tex +0.25*g1+0.25*g2+g2).xyz;
vec3 H7 = texture(Source, tex +0.25*g1-0.25*g2+g2).xyz;
vec3 H8 = texture(Source, tex -0.25*g1-0.25*g2+g2).xyz;
vec3 H9 = texture(Source, tex -0.25*g1+0.25*g2+g2).xyz;
vec4 f0 = reduce4(F6, F7, F8, F9);
vec4 h0 = reduce4(H6, H7, H8, H9);
bool block_3d = ((f0.xyz == f0.yzw) && (h0.xyz == h0.yzw));
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 );
/*
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
*/
/* Calc edgeness in diagonal directions. */
float d_edge = (d_wd( d, b, g, e, c, p2, h, f, p1, h5, i, f4, i5, i4 ) - d_wd( 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(f, i, e, h, c, i5, b, h5) - hv_wd(e, f, h, i, d, f4, g, i4));
float limits = XBR_EDGE_STR + 0.000001;
float edge_strength = smoothstep(0.0, limits, abs(d_edge));
/* Filter weights. Two taps only. */
vec4 w1 = vec4(-weight1, weight1+0.5, weight1+0.5, -weight1);
vec4 w2 = vec4(-weight2, weight2+0.25, weight2+0.25, -weight2);
/* 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 ));
vec3 c3 = mul(w2, mat4x3(D+G, E+H, F+I, F4+I4));
vec3 c4 = mul(w2, mat4x3(C+B, F+E, I+H, I5+H5));
bool ir_lv1 = (((e!=f) && (e!=h)) && ( !eq(f,b) && !eq(f,c) || !eq(h,d) && !eq(h,g) || eq(e,i) && (!eq(f,f4) && !eq(f,i4) || !eq(h,h5) && !eq(h,i5)) || eq(e,g) || eq(e,c)) );
/* 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);
/*
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
*/
/* 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));
color = clamp(color, min_sample, max_sample);
color = block_3d ? color : E;
FragColor = vec4(color, 1.0);
}
}

View file

@ -0,0 +1,247 @@
#version 450
/*
******* Super 4XBR Shader - pass3 *******
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.
*/
const float XBR_EDGE_STR = 0.0;
const float XBR_WEIGHT = 0.0;
const float XBR_ANTI_RINGING = 0.0;
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;
#define mul(a,b) (b*a)
#define XBR_RES 2.0
#define wp1 1.0
#define wp2 0.0
#define wp3 0.0
#define wp4 4.0
#define wp5 0.0
#define wp6 0.0
#define weight1 (XBR_WEIGHT*1.75068/10.0)
#define weight2 (XBR_WEIGHT*1.29633/10.0/2.0)
const vec3 Y = vec3(.2126, .7152, .0722);
const vec3 dtt = vec3(65536.,255.,1.);
vec4 reduce4(vec3 A, vec3 B, vec3 C, vec3 D)
{
return mul(mat4x3(A, B, C, D), dtt);
}
float RGBtoYUV(vec3 color)
{
return dot(color, Y);
}
float df(float A, float B)
{
return abs(A-B);
}
bool eq(float A, float B)
{
return (df(A, B) < 15.0);
}
/*
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 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 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)));
}
#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;
layout(set = 0, binding = 3) uniform sampler2D Original;
void main()
{
//Skip pixels on wrong grid
vec2 dir = fract(vTexCoord*params.SourceSize.xy/XBR_RES) - vec2(0.5,0.5);
if ((dir.x*dir.y)>0.0) FragColor = texture(Source, vTexCoord);
vec2 tex = (floor(vTexCoord*params.SourceSize.xy/XBR_RES) + vec2(0.5, 0.5))*XBR_RES/params.SourceSize.xy;
vec2 g1 = vec2((XBR_RES/2.0)/params.SourceSize.x, 0.0);
vec2 g2 = vec2(0.0, (XBR_RES/2.0)/params.SourceSize.y);
vec3 P0 = texture(Source, 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(Source, vTexCoord +3.0*g1 ).xyz;
vec3 B = texture(Source, vTexCoord -2.0*g1 -g2).xyz;
vec3 C = texture(Source, vTexCoord -g1 -2.0*g2).xyz;
vec3 D = texture(Source, vTexCoord -2.0*g1 +g2).xyz;
vec3 E = texture(Source, vTexCoord -g1 ).xyz;
vec3 F = texture(Source, vTexCoord -g2).xyz;
vec3 G = texture(Source, vTexCoord -g1 +2.0*g2).xyz;
vec3 H = texture(Source, vTexCoord +g2).xyz;
vec3 I = texture(Source, vTexCoord +g1 ).xyz;
vec3 F4 = texture(Source, vTexCoord +g1 -2.0*g2).xyz;
vec3 I4 = texture(Source, vTexCoord +2.0*g1 -g2).xyz;
vec3 H5 = texture(Source, vTexCoord +g1 +2.0*g2).xyz;
vec3 I5 = texture(Source, vTexCoord +2.0*g1 +g2).xyz;
vec3 A = texture(Source, vTexCoord).xyz;
g1 *= 2.0;
g2 *= 2.0;
vec3 F6 = texture(Original, tex +g1+0.25*g1+0.25*g2).xyz;
vec3 F7 = texture(Original, tex +g1+0.25*g1-0.25*g2).xyz;
vec3 F8 = texture(Original, tex +g1-0.25*g1-0.25*g2).xyz;
vec3 F9 = texture(Original, tex +g1-0.25*g1+0.25*g2).xyz;
vec3 H6 = texture(Original, tex +0.25*g1+0.25*g2+g2).xyz;
vec3 H7 = texture(Original, tex +0.25*g1-0.25*g2+g2).xyz;
vec3 H8 = texture(Original, tex -0.25*g1-0.25*g2+g2).xyz;
vec3 H9 = texture(Original, tex -0.25*g1+0.25*g2+g2).xyz;
vec4 f0 = reduce4(F6, F7, F8, F9);
vec4 h0 = reduce4(H6, H7, H8, H9);
bool block_3d = ((f0.xyz == f0.yzw) && (h0.xyz == h0.yzw));
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 );
/*
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
*/
/* Calc edgeness in diagonal directions. */
float d_edge = (d_wd( d, b, g, e, c, p2, h, f, p1, h5, i, f4, i5, i4 ) - d_wd( 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(f, i, e, h, c, i5, b, h5) - hv_wd(e, f, h, i, d, f4, g, i4));
float limits = XBR_EDGE_STR + 0.000001;
float edge_strength = smoothstep(0.0, limits, abs(d_edge));
/* Filter weights. Two taps only. */
vec4 w1 = vec4(-weight1, weight1+0.5, weight1+0.5, -weight1);
vec4 w2 = vec4(-weight2, weight2+0.25, weight2+0.25, -weight2);
/* 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 ));
vec3 c3 = mul(w2, mat4x3(D+G, E+H, F+I, F4+I4));
vec3 c4 = mul(w2, mat4x3(C+B, F+E, I+H, I5+H5));
bool ir_lv1 = (((e!=f) && (e!=h)) && ( !eq(f,b) && !eq(f,c) || !eq(h,d) && !eq(h,g) || eq(e,i) && (!eq(f,f4) && !eq(f,i4) || !eq(h,h5) && !eq(h,i5)) || eq(e,g) || eq(e,c)) );
/* 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);
/*
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
*/
/* 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));
color = clamp(color, min_sample, max_sample);
color = block_3d ? color : E;
FragColor = vec4(color, 1.0);
}

View file

@ -0,0 +1,248 @@
#version 450
/*
******* Super 4XBR Shader - pass3f ******* This pass is optional.
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.
*/
const float XBR_EDGE_STR = 0.0;
const float XBR_WEIGHT = 0.0;
const float XBR_ANTI_RINGING = 0.0;
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;
#define mul(a,b) (b*a)
#define XBR_RES 2.0
#define wp1 1.0
#define wp2 0.0
#define wp3 0.0
#define wp4 0.0
#define wp5 -1.0
#define wp6 0.0
#define weight1 (XBR_WEIGHT*1.29633/10.0)
#define weight2 (XBR_WEIGHT*1.75068/10.0/2.0)
const vec3 Y = vec3(.2126, .7152, .0722);
const vec3 dtt = vec3(65536.,255.,1.);
vec4 reduce4(vec3 A, vec3 B, vec3 C, vec3 D)
{
return mul(mat4x3(A, B, C, D), dtt);
}
float RGBtoYUV(vec3 color)
{
return dot(color, Y);
}
float df(float A, float B)
{
return abs(A-B);
}
bool eq(float A, float B)
{
return (df(A, B) < 15.0);
}
/*
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 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 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)));
}
#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 vec4 t1;
layout(location = 2) out vec4 t2;
layout(location = 3) out vec4 t3;
layout(location = 4) out vec4 t4;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
float dx = params.SourceSize.z;
float dy = params.SourceSize.w;
t1 = vTexCoord.xyxy + vec4(-2.0*dx, -2.0*dy, dx, dy);
t2 = vTexCoord.xyxy + vec4( -dx, -2.0*dy, 0, dy);
t3 = vTexCoord.xyxy + vec4(-2.0*dx, -dy, dx, 0);
t4 = vTexCoord.xyxy + vec4( -dx, -dy, 0, 0);
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in vec4 t1;
layout(location = 2) in vec4 t2;
layout(location = 3) in vec4 t3;
layout(location = 4) in vec4 t4;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
layout(set = 0, binding = 3) uniform sampler2D Original;
void main()
{
vec2 tex = (floor(vTexCoord*params.SourceSize.xy/XBR_RES) + vec2(0.5, 0.5))*XBR_RES/params.SourceSize.xy;
vec2 g1 = vec2(XBR_RES/params.SourceSize.x, 0.0);
vec2 g2 = vec2(0.0, XBR_RES/params.SourceSize.y);
vec3 P0 = texture(Source, t1.xy).xyz;
vec3 P1 = texture(Source, t1.zy).xyz;
vec3 P2 = texture(Source, t1.xw).xyz;
vec3 P3 = texture(Source, t1.zw).xyz;
vec3 B = texture(Source, t2.xy).xyz;
vec3 C = texture(Source, t2.zy).xyz;
vec3 H5 = texture(Source, t2.xw).xyz;
vec3 I5 = texture(Source, t2.zw).xyz;
vec3 D = texture(Source, t3.xy).xyz;
vec3 F4 = texture(Source, t3.zy).xyz;
vec3 G = texture(Source, t3.xw).xyz;
vec3 I4 = texture(Source, t3.zw).xyz;
vec3 E = texture(Source, t4.xy).xyz;
vec3 F = texture(Source, t4.zy).xyz;
vec3 H = texture(Source, t4.xw).xyz;
vec3 I = texture(Source, t4.zw).xyz;
vec3 A = texture(Source, vTexCoord).xyz;
vec3 F6 = texture(Original, tex +g1+0.25*g1+0.25*g2).xyz;
vec3 F7 = texture(Original, tex +g1+0.25*g1-0.25*g2).xyz;
vec3 F8 = texture(Original, tex +g1-0.25*g1-0.25*g2).xyz;
vec3 F9 = texture(Original, tex +g1-0.25*g1+0.25*g2).xyz;
vec3 H6 = texture(Original, tex +0.25*g1+0.25*g2+g2).xyz;
vec3 H7 = texture(Original, tex +0.25*g1-0.25*g2+g2).xyz;
vec3 H8 = texture(Original, tex -0.25*g1-0.25*g2+g2).xyz;
vec3 H9 = texture(Original, tex -0.25*g1+0.25*g2+g2).xyz;
vec4 f0 = reduce4(F6, F7, F8, F9);
vec4 h0 = reduce4(H6, H7, H8, H9);
bool block_3d = ((f0.xyz==f0.yzw) && (h0.xyz==h0.yzw));
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 );
/*
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
*/
/* Calc edgeness in diagonal directions. */
float d_edge = (d_wd( d, b, g, e, c, p2, h, f, p1, h5, i, f4, i5, i4 ) - d_wd( 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(f, i, e, h, c, i5, b, h5) - hv_wd(e, f, h, i, d, f4, g, i4));
float limits = XBR_EDGE_STR + 0.000001;
float edge_strength = smoothstep(0.0, limits, abs(d_edge));
/* Filter weights. Two taps only. */
vec4 w1 = vec4(-weight1, weight1+0.5, weight1+0.5, -weight1);
vec4 w2 = vec4(-weight2, weight2+0.25, weight2+0.25, -weight2);
/* 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 ));
vec3 c3 = mul(w2, mat4x3(D+G, E+H, F+I, F4+I4));
vec3 c4 = mul(w2, mat4x3(C+B, F+E, I+H, I5+H5));
bool ir_lv1 = (((e!=f) && (e!=h)) && ( !eq(f,b) && !eq(f,c) || !eq(h,d) && !eq(h,g) || eq(e,i) && (!eq(f,f4) && !eq(f,i4) || !eq(h,h5) && !eq(h,i5)) || eq(e,g) || eq(e,c)) );
/* 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 ) + (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));
color = clamp(color, min_sample, max_sample);
color = block_3d ? color : A;
FragColor = vec4(color, 1.0);
}

View file

@ -0,0 +1,203 @@
#version 450
/*
******* Super XBR Shader - pass0 *******
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.
*/
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float XBR_EDGE_STR;
float XBR_WEIGHT;
float XBR_ANTI_RINGING;
} 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
#define XBR_EDGE_STR params.XBR_EDGE_STR
#define XBR_WEIGHT params.XBR_WEIGHT
#define XBR_ANTI_RINGING params.XBR_ANTI_RINGING
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;
#define mul(a,b) (b*a)
#define wp1 1.0
#define wp2 0.0
#define wp3 0.0
#define wp4 2.0
#define wp5 -1.0
#define wp6 0.0
#define weight1 (XBR_WEIGHT*1.29633/10.0)
#define weight2 (XBR_WEIGHT*1.75068/10.0/2.0)
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 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 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)));
}
#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 vec4 t1;
layout(location = 2) out vec4 t2;
layout(location = 3) out vec4 t3;
layout(location = 4) out vec4 t4;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
float dx = params.SourceSize.z;
float dy = params.SourceSize.w;
t1 = vTexCoord.xyxy + vec4(-dx, -dy, 2.0*dx, 2.0*dy);
t2 = vTexCoord.xyxy + vec4( 0, -dy, dx, 2.0*dy);
t3 = vTexCoord.xyxy + vec4(-dx, 0, 2.0*dx, dy);
t4 = vTexCoord.xyxy + vec4( 0, 0, dx, dy);
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in vec4 t1;
layout(location = 2) in vec4 t2;
layout(location = 3) in vec4 t3;
layout(location = 4) in vec4 t4;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
void main()
{
vec3 P0 = texture(Source, t1.xy).xyz;
vec3 P1 = texture(Source, t1.zy).xyz;
vec3 P2 = texture(Source, t1.xw).xyz;
vec3 P3 = texture(Source, t1.zw).xyz;
vec3 B = texture(Source, t2.xy).xyz;
vec3 C = texture(Source, t2.zy).xyz;
vec3 H5 = texture(Source, t2.xw).xyz;
vec3 I5 = texture(Source, t2.zw).xyz;
vec3 D = texture(Source, t3.xy).xyz;
vec3 F4 = texture(Source, t3.zy).xyz;
vec3 G = texture(Source, t3.xw).xyz;
vec3 I4 = texture(Source, t3.zw).xyz;
vec3 E = texture(Source, t4.xy).xyz;
vec3 F = texture(Source, t4.zy).xyz;
vec3 H = texture(Source, t4.xw).xyz;
vec3 I = texture(Source, t4.zw).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( d, b, g, e, c, p2, h, f, p1, h5, i, f4, i5, i4 ) - d_wd( 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(f, i, e, h, c, i5, b, h5) - hv_wd(e, f, h, i, d, f4, g, i4));
float limits = XBR_EDGE_STR + 0.000001;
float edge_strength = smoothstep(0.0, limits, abs(d_edge));
/* Filter weights. Two taps only. */
vec4 w1 = vec4(-weight1, weight1+0.5, weight1+0.5, -weight1);
vec4 w2 = vec4(-weight2, weight2+0.25, weight2+0.25, -weight2);
/* 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 ));
vec3 c3 = mul(w2, mat4x3(D+G, E+H, F+I, F4+I4));
vec3 c4 = mul(w2, mat4x3(C+B, F+E, I+H, I5+H5));
/* 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 ) + (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));
color = clamp(color, min_sample, max_sample);
FragColor = vec4(color, 1.0);
}

View file

@ -0,0 +1,190 @@
#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.
*/
const float XBR_EDGE_STR = 0.6;
const float XBR_WEIGHT = 1.0;
const float XBR_ANTI_RINGING = 1.0;
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;
#define mul(a,b) (b*a)
#define wp1 1.0
#define wp2 0.0
#define wp3 0.0
#define wp4 4.0
#define wp5 0.0
#define wp6 0.0
#define weight1 (XBR_WEIGHT*1.75068/10.0)
#define weight2 (XBR_WEIGHT*1.29633/10.0/2.0)
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 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 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)));
}
#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;
layout(set = 0, binding = 3) uniform sampler2D Original;
void main()
{
//Skip pixels on wrong grid
vec2 fp = fract(vTexCoord*params.SourceSize.xy);
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);
}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( d, b, g, e, c, p2, h, f, p1, h5, i, f4, i5, i4 ) - d_wd( 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(f, i, e, h, c, i5, b, h5) - hv_wd(e, f, h, i, d, f4, g, i4));
float limits = XBR_EDGE_STR + 0.000001;
float edge_strength = smoothstep(0.0, limits, abs(d_edge));
/* Filter weights. Two taps only. */
vec4 w1 = vec4(-weight1, weight1+0.5, weight1+0.5, -weight1);
vec4 w2 = vec4(-weight2, weight2+0.25, weight2+0.25, -weight2);
/* 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 ));
vec3 c3 = mul(w2, mat4x3(D+G, E+H, F+I, F4+I4));
vec3 c4 = mul(w2, mat4x3(C+B, F+E, I+H, I5+H5));
/* 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 ) + (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));
color = clamp(color, min_sample, max_sample);
FragColor = vec4(color, 1.0);
}
}

View file

@ -0,0 +1,192 @@
#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.
*/
const float XBR_EDGE_STR = 0.6;
const float XBR_WEIGHT = 1.0;
const float XBR_ANTI_RINGING = 1.0;
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;
#define mul(a,b) (b*a)
#define XBR_RES 2.0
#define wp1 1.0
#define wp2 0.0
#define wp3 0.0
#define wp4 4.0
#define wp5 0.0
#define wp6 0.0
#define weight1 (XBR_WEIGHT*1.75068/10.0)
#define weight2 (XBR_WEIGHT*1.29633/10.0/2.0)
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 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 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)));
}
#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;
layout(set = 0, binding = 3) uniform sampler2D PassPrev2;
void main()
{
//Skip pixels on wrong grid
vec2 fp = fract(vTexCoord*params.SourceSize.xy);
vec2 dir = fp - vec2(0.5,0.5);
if ((dir.x*dir.y)>0.0) {
FragColor = (fp.x>0.5) ? texture(Source, vTexCoord) : texture(PassPrev2, vTexCoord);
}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(PassPrev2, 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(PassPrev2, vTexCoord +3.0*g1 ).xyz;
vec3 B = texture(Source, vTexCoord -2.0*g1 -g2).xyz;
vec3 C = texture(PassPrev2, vTexCoord -g1 -2.0*g2).xyz;
vec3 D = texture(Source, vTexCoord -2.0*g1 +g2).xyz;
vec3 E = texture(PassPrev2, vTexCoord -g1 ).xyz;
vec3 F = texture(Source, vTexCoord -g2).xyz;
vec3 G = texture(PassPrev2, vTexCoord -g1 +2.0*g2).xyz;
vec3 H = texture(Source, vTexCoord +g2).xyz;
vec3 I = texture(PassPrev2, vTexCoord +g1 ).xyz;
vec3 F4 = texture(PassPrev2, vTexCoord +g1 -2.0*g2).xyz;
vec3 I4 = texture(Source, vTexCoord +2.0*g1 -g2).xyz;
vec3 H5 = texture(PassPrev2, 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( d, b, g, e, c, p2, h, f, p1, h5, i, f4, i5, i4 ) - d_wd( 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(f, i, e, h, c, i5, b, h5) - hv_wd(e, f, h, i, d, f4, g, i4));
float limits = XBR_EDGE_STR + 0.000001;
float edge_strength = smoothstep(0.0, limits, abs(d_edge));
/* Filter weights. Two taps only. */
vec4 w1 = vec4(-weight1, weight1+0.5, weight1+0.5, -weight1);
vec4 w2 = vec4(-weight2, weight2+0.25, weight2+0.25, -weight2);
/* 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 ));
vec3 c3 = mul(w2, mat4x3(D+G, E+H, F+I, F4+I4));
vec3 c4 = mul(w2, mat4x3(C+B, F+E, I+H, I5+H5));
/* 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 ) + (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));
color = clamp(color, min_sample, max_sample);
FragColor = vec4(color, 1.0);
}
}

View file

@ -0,0 +1,204 @@
#version 450
/*
******* Super XBR Shader - pass2 ******* This pass is optional.
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.
*/
const float XBR_EDGE_STR = 0.6;
const float XBR_WEIGHT = 1.0;
const float XBR_ANTI_RINGING = 1.0;
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;
#define mul(a,b) (b*a)
#define wp1 1.0
#define wp2 0.0
#define wp3 0.0
#define wp4 0.0
#define wp5 -1.0
#define wp6 0.0
#define weight1 (XBR_WEIGHT*1.29633/10.0)
#define weight2 (XBR_WEIGHT*1.75068/10.0/2.0)
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 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 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)));
}
#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 vec4 t1;
layout(location = 2) out vec4 t2;
layout(location = 3) out vec4 t3;
layout(location = 4) out vec4 t4;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
float dx = params.SourceSize.z;
float dy = params.SourceSize.w;
t1 = vTexCoord.xyxy + vec4(-2.0*dx, -2.0*dy, dx, dy);
t2 = vTexCoord.xyxy + vec4( -dx, -2.0*dy, 0, dy);
t3 = vTexCoord.xyxy + vec4(-2.0*dx, -dy, dx, 0);
t4 = vTexCoord.xyxy + vec4( -dx, -dy, 0, 0);
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in vec4 t1;
layout(location = 2) in vec4 t2;
layout(location = 3) in vec4 t3;
layout(location = 4) in vec4 t4;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
void main()
{
vec3 P0 = texture(Source, t1.xy).xyz;
vec3 P1 = texture(Source, t1.zy).xyz;
vec3 P2 = texture(Source, t1.xw).xyz;
vec3 P3 = texture(Source, t1.zw).xyz;
vec3 B = texture(Source, t2.xy).xyz;
vec3 C = texture(Source, t2.zy).xyz;
vec3 H5 = texture(Source, t2.xw).xyz;
vec3 I5 = texture(Source, t2.zw).xyz;
vec3 D = texture(Source, t3.xy).xyz;
vec3 F4 = texture(Source, t3.zy).xyz;
vec3 G = texture(Source, t3.xw).xyz;
vec3 I4 = texture(Source, t3.zw).xyz;
vec3 E = texture(Source, t4.xy).xyz;
vec3 F = texture(Source, t4.zy).xyz;
vec3 H = texture(Source, t4.xw).xyz;
vec3 I = texture(Source, t4.zw).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 );
/*
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
*/
/* Calc edgeness in diagonal directions. */
float d_edge = (d_wd( d, b, g, e, c, p2, h, f, p1, h5, i, f4, i5, i4 ) - d_wd( 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(f, i, e, h, c, i5, b, h5) - hv_wd(e, f, h, i, d, f4, g, i4));
float limits = XBR_EDGE_STR + 0.000001;
float edge_strength = smoothstep(0.0, limits, abs(d_edge));
/* Filter weights. Two taps only. */
vec4 w1 = vec4(-weight1, weight1+0.5, weight1+0.5, -weight1);
vec4 w2 = vec4(-weight2, weight2+0.25, weight2+0.25, -weight2);
/* 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 ));
vec3 c3 = mul(w2, mat4x3(D+G, E+H, F+I, F4+I4));
vec3 c4 = mul(w2, mat4x3(C+B, F+E, I+H, I5+H5));
/* 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 ) + (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));
color = clamp(color, min_sample, max_sample);
FragColor = vec4(color, 1.0);
}

View file

@ -0,0 +1,16 @@
shaders = "3"
shader0 = "shaders/super-xbr/super-2xbr-3d-pass0.slang"
filter_linear0 = false
scale_type_x0 = "source"
scale_x0 = "1.000000"
scale_type_y0 = "source"
scale_y0 = "1.000000"
shader1 = "shaders/super-xbr/super-2xbr-3d-pass1.slang"
filter_linear1 = false
scale_type_x1 = "source"
scale_x1 = "1.000000"
scale_type_y1 = "source"
scale_y1 = "1.000000"
shader2 = "shaders/super-xbr/custom-jinc2-sharper.slang"
filter_linear2 = false

View file

@ -0,0 +1,22 @@
shaders = "4"
shader0 = "shaders/super-xbr/super-2xbr-3d-pass0.slang"
filter_linear0 = false
scale_type_x0 = "source"
scale_x0 = "1.000000"
scale_type_y0 = "source"
scale_y0 = "1.000000"
shader1 = "shaders/super-xbr/super-2xbr-3d-pass1.slang"
filter_linear1 = false
scale_type_x1 = "source"
scale_x1 = "1.000000"
scale_type_y1 = "source"
scale_y1 = "1.000000"
shader2 = "shaders/super-xbr/super-2xbr-3d-pass2.slang"
filter_linear2 = false
scale_type_x2 = "source"
scale_x2 = "1.000000"
scale_type_y2 = "source"
scale_y2 = "1.000000"
shader3 = "shaders/super-xbr/custom-jinc2-sharper.slang"
filter_linear3 = false

View file

@ -0,0 +1,28 @@
shaders = "5"
shader0 = "shaders/super-xbr/super-4xbr-3d-pass0.slang"
filter_linear0 = false
scale_type_x0 = "source"
scale_x0 = "1.000000"
scale_type_y0 = "source"
scale_y0 = "1.000000"
shader1 = "shaders/super-xbr/super-4xbr-3d-pass1.slang"
filter_linear1 = false
scale_type_x1 = "source"
scale_x1 = "1.000000"
scale_type_y1 = "source"
scale_y1 = "1.000000"
shader2 = "shaders/super-xbr/super-4xbr-3d-pass2.slang"
filter_linear2 = false
scale_type_x2 = "source"
scale_x2 = "1.000000"
scale_type_y2 = "source"
scale_y2 = "1.000000"
shader3 = "shaders/super-xbr/super-4xbr-3d-pass3.slang"
filter_linear3 = false
scale_type_x3 = "source"
scale_x3 = "1.000000"
scale_type_y3 = "source"
scale_y3 = "1.000000"
shader4 = "shaders/super-xbr/custom-jinc2-sharper.slang"
filter_linear4 = false

View file

@ -0,0 +1,40 @@
shaders = "7"
shader0 = "shaders/super-xbr/super-4xbr-3d-pass0.slang"
filter_linear0 = false
scale_type_x0 = "source"
scale_x0 = "1.000000"
scale_type_y0 = "source"
scale_y0 = "1.000000"
shader1 = "shaders/super-xbr/super-4xbr-3d-pass1.slang"
filter_linear1 = false
scale_type_x1 = "source"
scale_x1 = "1.000000"
scale_type_y1 = "source"
scale_y1 = "1.000000"
shader2 = "shaders/super-xbr/super-4xbr-3d-pass1f.slang"
filter_linear2 = false
scale_type_x2 = "source"
scale_x2 = "1.000000"
scale_type_y2 = "source"
scale_y2 = "1.000000"
shader3 = "shaders/super-xbr/super-4xbr-3d-pass2.slang"
filter_linear3 = false
scale_type_x3 = "source"
scale_x3 = "1.000000"
scale_type_y3 = "source"
scale_y3 = "1.000000"
shader4 = "shaders/super-xbr/super-4xbr-3d-pass3.slang"
filter_linear4 = false
scale_type_x4 = "source"
scale_x4 = "1.000000"
scale_type_y4 = "source"
scale_y4 = "1.000000"
shader5 = "shaders/super-xbr/super-4xbr-3d-pass3f.slang"
filter_linear5 = false
scale_type_x5 = "source"
scale_x5 = "1.000000"
scale_type_y5 = "source"
scale_y5 = "1.000000"
shader6 = "../stock.slang"
filter_linear6 = true

16
xbr/super-xbr-2p.slangp Normal file
View file

@ -0,0 +1,16 @@
shaders = "3"
shader0 = "shaders/super-xbr/super-xbr-pass0.slang"
filter_linear0 = 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
scale_type_x1 = "source"
scale_x1 = "2.000000"
scale_type_y1 = "source"
scale_y1 = "2.000000"
shader2 = "shaders/super-xbr/custom-jinc2-sharper.slang"
filter_linear2 = false

View file

@ -0,0 +1,22 @@
shaders = "4"
shader0 = "shaders/super-xbr/super-xbr-pass0.slang"
filter_linear0 = 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
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
scale_type_x2 = "source"
scale_x2 = "1.000000"
scale_type_y2 = "source"
scale_y2 = "1.000000"
shader3 = "shaders/super-xbr/custom-jinc2-sharper.slang"
filter_linear3 = false

41
xbr/super-xbr-6p.slangp Normal file
View file

@ -0,0 +1,41 @@
shaders = "7"
shader0 = "shaders/super-xbr/super-xbr-pass0.slang"
filter_linear0 = 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
scale_type_x1 = "source"
scale_x1 = "2.000000"
scale_type_y1 = "source"
scale_y1 = "2.000000"
alias2 = "PassPrev2"
shader2 = "shaders/super-xbr/super-xbr-pass2.slang"
filter_linear2 = 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
scale_type_x3 = "source"
scale_x3 = "1.000000"
scale_type_y3 = "source"
scale_y3 = "1.000000"
shader4 = "shaders/super-xbr/super-xbr-pass1b.slang"
filter_linear4 = 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
scale_type_x5 = "source"
scale_x5 = "1.000000"
scale_type_y5 = "source"
scale_y5 = "1.000000"
shader6 = "shaders/super-xbr/custom-jinc2-sharper.slang"
filter_linear6 = false

View file

@ -0,0 +1,82 @@
shaders = "6"
shader0 = "..\misc\deposterize-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 = "..\misc\deposterize-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 = "1.000000"
scale_type_y1 = "source"
scale_y1 = "1.000000"
shader2 = "..\xbr\shaders\super-xbr\super-xbr-pass0.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 = "2.000000"
scale_type_y2 = "source"
scale_y2 = "2.000000"
shader3 = "..\xbr\shaders\super-xbr\super-xbr-pass1.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 = "..\xbr\shaders\super-xbr\super-xbr-pass2.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 = "1.000000"
scale_type_y4 = "source"
scale_y4 = "1.000000"
shader5 = "..\xbr\shaders\super-xbr\custom-jinc2-sharper.slang"
filter_linear5 = "false"
wrap_mode5 = "clamp_to_border"
mipmap_input5 = "false"
alias5 = ""
float_framebuffer5 = "false"
srgb_framebuffer5 = "false"
parameters = "EQ_THRESH1;DIFF_THRESH1;EQ_THRESH2;DIFF_THRESH2;XBR_EDGE_STR;XBR_HV_EDGE_STR;XBR_WEIGHT;XBR_WEIGHT2;XBR_ANTI_RINGING;WP1;WP2;WP3;WP4;WP5;WP6;JINC2_WINDOW_SINC;JINC2_SINC;JINC2_AR_STRENGTH"
EQ_THRESH1 = "0.010000"
DIFF_THRESH1 = "0.060000"
EQ_THRESH2 = "0.010000"
DIFF_THRESH2 = "0.060000"
XBR_EDGE_STR = "2.000000"
XBR_HV_EDGE_STR = "2.000000"
XBR_WEIGHT = "1.000000"
XBR_WEIGHT2 = "1.000000"
XBR_ANTI_RINGING = "0.000000"
WP1 = "2.000000"
WP2 = "1.000000"
WP3 = "-1.000000"
WP4 = "4.000000"
WP5 = "-1.000000"
WP6 = "1.000000"
JINC2_WINDOW_SINC = "0.420000"
JINC2_SINC = "0.920000"
JINC2_AR_STRENGTH = "0.000000"