Translated all of the shaders to allow the super-xbr-2p preset to work.

Final image doesn't seem to be quite right - horizontal lines are bumpy.
This commit is contained in:
Arzed Five 2016-07-19 18:04:16 +01:00
parent 27efe97300
commit 5de3ce96a2
6 changed files with 778 additions and 0 deletions

View file

@ -0,0 +1,19 @@
shaders = 3
shader0 = 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 = 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 = super-xbr/custom-jinc2-sharper.slang
filter_linear2 = false

View file

@ -0,0 +1,161 @@
#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(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
uint FrameCount;
} global;
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
/* VERTEX_SHADER */
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
#define JINC2_WINDOW_SINC 0.42
#define JINC2_SINC 0.92
#define JINC2_AR_STRENGTH 0.0
// END PARAMETERS //
/*
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 (JINC2_WINDOW_SINC*pi)
#define wb (JINC2_SINC*pi)
vec3 Y = vec3(0.299, 0.587, 0.114);
// 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)
{
return (x == vec4(0.0)) ? vec4(wa*wb) : sin(x*wa)*sin(x*wb)/(x*x);
}
void main()
{
vec2 dx = vec2(1.0, 0.0);
vec2 dy = vec2(0.0, 1.0);
vec2 pc = vTexCoord*global.SourceSize.xy;
vec2 tc = (floor(pc - vec2(0.5, 0.5)) + vec2(0.5, 0.5));
mat4x4 weights = mat4x4(
resampler(vec4(d(pc, tc -dx -dy), d(pc, tc -dy), d(pc, tc +dx -dy), d(pc, tc+2.0*dx -dy))),
resampler(vec4(d(pc, tc -dx ), d(pc, tc ), d(pc, tc +dx ), d(pc, tc+2.0*dx ))),
resampler(vec4(d(pc, tc -dx +dy), d(pc, tc +dy), d(pc, tc +dx +dy), d(pc, tc+2.0*dx +dy))),
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*global.SourceSize.zw;
dy = dy*global.SourceSize.zw;
tc = tc*global.SourceSize.zw;
// 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;
vec3 color;
color = mat4x3(c00, c10, c20, c30) * weights[0];
color+= mat4x3(c01, c11, c21, c31) * weights[1];
color+= mat4x3(c02, c12, c22, c32) * weights[2];
color+= mat4x3(c03, c13, c23, c33) * weights[3];
color = color / dot( vec4(1.0) * weights, vec4(1.0) );
// 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, JINC2_AR_STRENGTH);
// final sum and weight normalization
FragColor = vec4(color, 1.0);
}

View file

@ -0,0 +1,3 @@
#define XBR_EDGE_STR 0.6
#define XBR_WEIGHT 1.0
#define XBR_ANTI_RINGING 1.0

View file

@ -0,0 +1,203 @@
#version 450
#include "super-xbr-params.inc"
/*
******* 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(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
uint FrameCount;
} global;
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
layout(location = 1) out vec4 t1;
layout(location = 2) out vec4 t2;
layout(location = 3) out vec4 t3;
layout(location = 4) out vec4 t4;
/* VERTEX_SHADER */
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
vec2 ps = vec2(global.SourceSize.z, global.SourceSize.w);
float dx = ps.x;
float dy = ps.y;
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;
#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)
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)));
}
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 = mat4x3( P2, H, F, P1 ) * w1;
vec3 c2 = mat4x3( P0, E, I, P3 ) * w1;
vec3 c3 = mat4x3(D+G, E+H, F+I, F4+I4) * w2;
vec3 c4 = mat4x3(C+B, F+E, I+H, I5+H5) * w2;
/* 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
#include "super-xbr-params.inc"
/*
******* 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.
*/
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
uint FrameCount;
vec4 OriginalHistorySize1;
} global;
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
/* VERTEX_SHADER */
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 OriginalHistory1;
#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)
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)));
}
void main()
{
//Skip pixels on wrong grid
vec2 fp = fract(vTexCoord*global.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(OriginalHistory1, vTexCoord);
vec2 g1 = (fp.x>0.5) ? vec2(0.5*global.SourceSize.z, 0.0) : vec2(0.0, 0.5*global.SourceSize.w);
vec2 g2 = (fp.x>0.5) ? vec2(0.0, 0.5*global.SourceSize.w) : vec2(0.5*global.SourceSize.z, 0.0);
vec3 P0 = texture(OriginalHistory1, 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(OriginalHistory1, vTexCoord +3.0*g1 ).xyz;
vec3 B = texture( Source, vTexCoord -2.0*g1 -g2).xyz;
vec3 C = texture(OriginalHistory1, vTexCoord -g1 -2.0*g2).xyz;
vec3 D = texture( Source, vTexCoord -2.0*g1 +g2).xyz;
vec3 E = texture(OriginalHistory1, vTexCoord -g1 ).xyz;
vec3 F = texture( Source, vTexCoord -g2).xyz;
vec3 G = texture(OriginalHistory1, vTexCoord -g1 +2.0*g2).xyz;
vec3 H = texture( Source, vTexCoord +g2).xyz;
vec3 I = texture(OriginalHistory1, vTexCoord +g1 ).xyz;
vec3 F4 = texture(OriginalHistory1, vTexCoord +g1 -2.0*g2).xyz;
vec3 I4 = texture( Source, vTexCoord +2.0*g1 -g2).xyz;
vec3 H5 = texture(OriginalHistory1, 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 = mat4x3( P2, H, F, P1 ) * w1;
vec3 c2 = mat4x3( P0, E, I, P3 ) * w1;
vec3 c3 = mat4x3(D+G, E+H, F+I, F4+I4) * w2;
vec3 c4 = mat4x3(C+B, F+E, I+H, I5+H5) * w2;
/* 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,200 @@
#version 450
#include "super-xbr-params.inc"
/*
******* 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.
*/
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
uint FrameCount;
} global;
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
layout(location = 1) out vec4 t1;
layout(location = 2) out vec4 t2;
layout(location = 3) out vec4 t3;
layout(location = 4) out vec4 t4;
/* VERTEX_SHADER */
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
vec2 ps = vec2(global.SourceSize.z, global.SourceSize.w);
float dx = ps.x;
float dy = ps.y;
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;
#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)
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)));
}
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 = mat4x3( P2, H, F, P1 ) * w1;
vec3 c2 = mat4x3( P0, E, I, P3 ) * w1;
vec3 c3 = mat4x3(D+G, E+H, F+I, F4+I4) * w2;
vec3 c4 = mat4x3(C+B, F+E, I+H, I5+H5) * w2;
/* 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);
}