mirror of
https://github.com/italicsjenga/slang-shaders.git
synced 2024-11-22 15:51:30 +11:00
Merge pull request #309 from Hyllian/master
Add crt-super-xbr new version
This commit is contained in:
commit
044a870c0c
126
crt/crt-super-xbr.slangp
Normal file
126
crt/crt-super-xbr.slangp
Normal file
|
@ -0,0 +1,126 @@
|
|||
shaders = "11"
|
||||
|
||||
|
||||
shader0 = "shaders/crt-super-xbr/linearize.slang"
|
||||
filter_linear0 = "false"
|
||||
wrap_mode0 = "clamp_to_border"
|
||||
mipmap_input0 = "false"
|
||||
alias0 = "XbrSource"
|
||||
float_framebuffer0 = "false"
|
||||
srgb_framebuffer0 = "true"
|
||||
scale_type_x0 = "source"
|
||||
scale_x0 = "1.000000"
|
||||
scale_type_y0 = "source"
|
||||
scale_y0 = "1.000000"
|
||||
|
||||
shader1 = "shaders/crt-super-xbr/super-xbr-pass0.slang"
|
||||
filter_linear1 = "false"
|
||||
wrap_mode1 = "clamp_to_border"
|
||||
mipmap_input1 = "false"
|
||||
alias1 = ""
|
||||
float_framebuffer1 = "false"
|
||||
srgb_framebuffer1 = "true"
|
||||
scale_type_x1 = "source"
|
||||
scale_x1 = "1.000000"
|
||||
scale_type_y1 = "source"
|
||||
scale_y1 = "1.000000"
|
||||
|
||||
shader2 = "shaders/crt-super-xbr/super-xbr-pass1.slang"
|
||||
filter_linear2 = "false"
|
||||
wrap_mode2 = "clamp_to_border"
|
||||
mipmap_input2 = "false"
|
||||
alias2 = ""
|
||||
float_framebuffer2 = "false"
|
||||
srgb_framebuffer2 = "true"
|
||||
scale_type_x2 = "source"
|
||||
scale_x2 = "2.000000"
|
||||
scale_type_y2 = "source"
|
||||
scale_y2 = "2.000000"
|
||||
|
||||
shader3 = "shaders/crt-super-xbr/super-xbr-pass2.slang"
|
||||
filter_linear3 = "false"
|
||||
wrap_mode3 = "clamp_to_border"
|
||||
mipmap_input3 = "false"
|
||||
alias3 = ""
|
||||
float_framebuffer3 = "false"
|
||||
srgb_framebuffer3 = "true"
|
||||
scale_type_x3 = "source"
|
||||
scale_x3 = "1.000000"
|
||||
scale_type_y3 = "source"
|
||||
scale_y3 = "1.000000"
|
||||
|
||||
shader4 = "shaders/crt-super-xbr/custom-bicubic-x.slang"
|
||||
filter_linear4 = "false"
|
||||
wrap_mode4 = "clamp_to_border"
|
||||
mipmap_input4 = "false"
|
||||
alias4 = ""
|
||||
float_framebuffer4 = "false"
|
||||
srgb_framebuffer4 = "true"
|
||||
scale_type_x4 = "source"
|
||||
scale_x4 = "1.000000"
|
||||
scale_type_y4 = "source"
|
||||
scale_y4 = "1.000000"
|
||||
|
||||
shader5 = "shaders/crt-super-xbr/custom-bicubic-y.slang"
|
||||
filter_linear5 = "false"
|
||||
wrap_mode5 = "clamp_to_border"
|
||||
mipmap_input5 = "false"
|
||||
alias5 = ""
|
||||
float_framebuffer5 = "false"
|
||||
srgb_framebuffer5 = "true"
|
||||
scale_type_x5 = "source"
|
||||
scale_x5 = "1.000000"
|
||||
scale_type_y5 = "source"
|
||||
scale_y5 = "0.500000"
|
||||
|
||||
shader6 = "shaders/crt-super-xbr/crt-custom.slang"
|
||||
filter_linear6 = "true"
|
||||
wrap_mode6 = "clamp_to_border"
|
||||
mipmap_input6 = "false"
|
||||
alias6 = "CRT_PASS"
|
||||
float_framebuffer6 = "false"
|
||||
srgb_framebuffer6 = "true"
|
||||
scale_type_x6 = "viewport"
|
||||
scale_x6 = "1.000000"
|
||||
scale_type_y6 = "viewport"
|
||||
scale_y6 = "1.000000"
|
||||
|
||||
shader7 = "shaders/crt-super-xbr/threshold.slang"
|
||||
filter_linear7 = "false"
|
||||
wrap_mode7 = "clamp_to_border"
|
||||
mipmap_input7 = "false"
|
||||
alias7 = ""
|
||||
float_framebuffer7 = "false"
|
||||
srgb_framebuffer7 = "true"
|
||||
scale_type_x7 = "source"
|
||||
scale_x7 = "1.000000"
|
||||
scale_type_y7 = "source"
|
||||
scale_y7 = "1.000000"
|
||||
|
||||
shader8 = "shaders/crt-super-xbr/blur_horiz.slang"
|
||||
filter_linear8 = "true"
|
||||
wrap_mode8 = "clamp_to_border"
|
||||
mipmap_input8 = "true"
|
||||
alias8 = ""
|
||||
float_framebuffer8 = "false"
|
||||
srgb_framebuffer8 = "true"
|
||||
scale_type_x8 = "source"
|
||||
scale_x8 = "0.200000"
|
||||
scale_type_y8 = "source"
|
||||
scale_y8 = "0.200000"
|
||||
|
||||
shader9 = "shaders/crt-super-xbr/blur_vert.slang"
|
||||
filter_linear9 = "true"
|
||||
wrap_mode9 = "clamp_to_border"
|
||||
mipmap_input9 = "false"
|
||||
alias9 = ""
|
||||
float_framebuffer9 = "false"
|
||||
srgb_framebuffer9 = "true"
|
||||
|
||||
shader10 = "shaders/crt-super-xbr/custom-resolve.slang"
|
||||
filter_linear10 = "true"
|
||||
wrap_mode10 = "clamp_to_border"
|
||||
mipmap_input10 = "false"
|
||||
alias10 = ""
|
||||
float_framebuffer10 = "false"
|
||||
srgb_framebuffer10 = "true"
|
47
crt/shaders/crt-super-xbr/blur_horiz.slang
Normal file
47
crt/shaders/crt-super-xbr/blur_horiz.slang
Normal file
|
@ -0,0 +1,47 @@
|
|||
#version 450
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
vec4 OutputSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 SourceSize;
|
||||
} global;
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
#pragma format R8G8B8A8_SRGB
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
#define GLOW_FALLOFF 0.35
|
||||
#define TAPS 4
|
||||
|
||||
#define kernel(x) exp(-GLOW_FALLOFF * (x) * (x))
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 col = vec3(0.0);
|
||||
float dx = 4.0 * global.SourceSize.z; // Mipmapped
|
||||
|
||||
float k_total = 0.0;
|
||||
for (int i = -TAPS; i <= TAPS; i++)
|
||||
{
|
||||
float k = kernel(i);
|
||||
k_total += k;
|
||||
col += k * texture(Source, vTexCoord + vec2(float(i) * dx, 0.0)).rgb;
|
||||
}
|
||||
|
||||
FragColor = vec4(col / k_total, 1.0);
|
||||
}
|
46
crt/shaders/crt-super-xbr/blur_vert.slang
Normal file
46
crt/shaders/crt-super-xbr/blur_vert.slang
Normal file
|
@ -0,0 +1,46 @@
|
|||
#version 450
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
vec4 OutputSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 SourceSize;
|
||||
} global;
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
#define GLOW_FALLOFF 0.35
|
||||
#define TAPS 4
|
||||
|
||||
#define kernel(x) exp(-GLOW_FALLOFF * (x) * (x))
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 col = vec3(0.0);
|
||||
float dy = global.SourceSize.w;
|
||||
|
||||
float k_total = 0.0;
|
||||
for (int i = -TAPS; i <= TAPS; i++)
|
||||
{
|
||||
float k = kernel(i);
|
||||
k_total += k;
|
||||
col += k * texture(Source, vTexCoord + vec2(0.0, float(i) * dy)).rgb;
|
||||
}
|
||||
|
||||
FragColor = vec4(col / k_total, 1.0);
|
||||
}
|
254
crt/shaders/crt-super-xbr/crt-custom.slang
Normal file
254
crt/shaders/crt-super-xbr/crt-custom.slang
Normal file
|
@ -0,0 +1,254 @@
|
|||
#version 450
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
float BEAM_MIN_WIDTH;
|
||||
float BEAM_MAX_WIDTH;
|
||||
float SCANLINES_STRENGTH;
|
||||
float COLOR_BOOST;
|
||||
float SHARPNESS_HACK;
|
||||
float PHOSPHOR_LAYOUT;
|
||||
float MASK_INTENSITY;
|
||||
float InputGamma;
|
||||
float OutputGamma;
|
||||
float VSCANLINES;
|
||||
float CRT_ANTI_RINGING;
|
||||
float CRT_CURVATURE;
|
||||
float CRT_warpX;
|
||||
float CRT_warpY;
|
||||
float CRT_cornersize;
|
||||
float CRT_cornersmooth;
|
||||
} param;
|
||||
|
||||
#pragma parameter CRT_HYLLIAN_SINC "[CRT-HYLLIAN-SINC PARAMS]" 0.0 0.0 0.0 0.0
|
||||
#pragma parameter BEAM_MIN_WIDTH " MIN BEAM WIDTH" 0.92 0.0 1.0 0.01
|
||||
#pragma parameter BEAM_MAX_WIDTH " MAX BEAM WIDTH" 1.0 0.0 1.0 0.01
|
||||
#pragma parameter SCANLINES_STRENGTH " SCANLINES STRENGTH" 0.72 0.0 1.0 0.01
|
||||
#pragma parameter COLOR_BOOST " COLOR BOOST" 1.25 1.0 2.0 0.05
|
||||
#pragma parameter SHARPNESS_HACK " SHARPNESS_HACK" 1.0 1.0 4.0 1.0
|
||||
#pragma parameter PHOSPHOR_LAYOUT " PHOSPHOR LAYOUT" 4.0 0.0 24.0 1.0
|
||||
#pragma parameter MASK_INTENSITY " MASK INTENSITY" 0.7 0.0 1.0 0.1
|
||||
#pragma parameter VSCANLINES " SCANLINES DIRECTION" 0.0 0.0 1.0 1.0
|
||||
#pragma parameter CRT_CURVATURE "CRT-Curvature" 1.0 0.0 1.0 1.0
|
||||
#pragma parameter CRT_warpX "CRT-Curvature X-Axis" 0.015 0.0 0.125 0.005
|
||||
#pragma parameter CRT_warpY "CRT-Curvature Y-Axis" 0.015 0.0 0.125 0.005
|
||||
vec2 CRT_Distortion = vec2(param.CRT_warpX, param.CRT_warpY) * 15.;
|
||||
#pragma parameter CRT_cornersize "CRT-Corner Size" 0.01 0.001 1.0 0.005
|
||||
#define cornersize param.CRT_cornersize
|
||||
#pragma parameter CRT_cornersmooth "CRT-Corner Smoothness" 380.0 80.0 2080.0 100.0
|
||||
#define cornersmooth param.CRT_cornersmooth
|
||||
|
||||
|
||||
#pragma parameter CRT_ANTI_RINGING "CRT Anti-Ringing [ OFF | ON ]" 0.0 0.0 1.0 1.0
|
||||
|
||||
#define CRT_ANTI_RINGING param.CRT_ANTI_RINGING
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
vec4 OutputSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 SourceSize;
|
||||
} global;
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 1) in vec2 FragCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
/*
|
||||
Hyllian's CRT Shader - Sinc/Spline16 version
|
||||
|
||||
Copyright (C) 2011-2022 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.
|
||||
*/
|
||||
|
||||
#include "../../../include/subpixel_masks.h"
|
||||
|
||||
|
||||
#define scanlines_strength (2.0*param.SCANLINES_STRENGTH)
|
||||
#define beam_min_width param.BEAM_MIN_WIDTH
|
||||
#define beam_max_width param.BEAM_MAX_WIDTH
|
||||
#define color_boost param.COLOR_BOOST
|
||||
|
||||
#define pi 3.1415926535897932384626433832795
|
||||
#define wa (0.5*pi)
|
||||
#define wb (pi)
|
||||
|
||||
const vec2 corner_aspect = vec2(1.0, 0.75);
|
||||
|
||||
float corner(vec2 coord)
|
||||
{
|
||||
coord = (coord - vec2(0.5)) + vec2(0.5, 0.5);
|
||||
coord = min(coord, vec2(1.0) - coord) * corner_aspect;
|
||||
vec2 cdist = vec2(cornersize);
|
||||
coord = (cdist - min(coord, cdist));
|
||||
float dist = sqrt(dot(coord, coord));
|
||||
|
||||
return clamp((cdist.x - dist)*cornersmooth, 0.0, 1.0);
|
||||
}
|
||||
|
||||
|
||||
vec2 Warp(vec2 texCoord){
|
||||
|
||||
vec2 curvedCoords = texCoord * 2.0 - 1.0;
|
||||
float curvedCoordsDistance = sqrt(curvedCoords.x*curvedCoords.x+curvedCoords.y*curvedCoords.y);
|
||||
|
||||
curvedCoords = curvedCoords / curvedCoordsDistance;
|
||||
|
||||
curvedCoords = curvedCoords * (1.0-pow(vec2(1.0-(curvedCoordsDistance/1.4142135623730950488016887242097)),(1.0/(1.0+CRT_Distortion*0.2))));
|
||||
|
||||
curvedCoords = curvedCoords / (1.0-pow(vec2(0.29289321881345247559915563789515),(1.0/(vec2(1.0)+CRT_Distortion*0.2))));
|
||||
|
||||
curvedCoords = curvedCoords * 0.5 + 0.5;
|
||||
return curvedCoords;
|
||||
}
|
||||
|
||||
float weight(float x)
|
||||
{
|
||||
x = abs(x);
|
||||
|
||||
if (x < 1.0)
|
||||
{
|
||||
return
|
||||
(
|
||||
((x - 9.0 / 5.0) * x - 1.0 / 5.0 ) * x + 1.0
|
||||
);
|
||||
}
|
||||
else if ((x >= 1.0) && (x < 2.0))
|
||||
{
|
||||
return
|
||||
(
|
||||
(( -1.0 / 3.0 * (x - 1) + 4.0 / 5.0 ) * (x - 1) - 7.0 / 15.0 ) * (x - 1)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
vec4 weight4(float x)
|
||||
{
|
||||
return vec4(
|
||||
weight(x - 2.0),
|
||||
weight(x - 1.0),
|
||||
weight(x),
|
||||
weight(x + 1.0)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
vec3 resampler3(vec3 x)
|
||||
{
|
||||
vec3 res;
|
||||
res.x = (x.x<=0.001) ? wa*wb : sin(x.x*wa)*sin(x.x*wb)/(x.x*x.x);
|
||||
res.y = (x.y<=0.001) ? wa*wb : sin(x.y*wa)*sin(x.y*wb)/(x.y*x.y);
|
||||
res.z = (x.z<=0.001) ? wa*wb : sin(x.z*wa)*sin(x.z*wb)/(x.z*x.z);
|
||||
return res;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 TextureSize = mix(vec2(global.SourceSize.x * param.SHARPNESS_HACK, global.SourceSize.y), vec2(global.SourceSize.x, global.SourceSize.y * param.SHARPNESS_HACK), param.VSCANLINES);
|
||||
|
||||
vec2 dx = mix(vec2(1.0/TextureSize.x, 0.0), vec2(0.0, 1.0/TextureSize.y), param.VSCANLINES);
|
||||
vec2 dy = mix(vec2(0.0, 1.0/TextureSize.y), vec2(1.0/TextureSize.x, 0.0), param.VSCANLINES);
|
||||
|
||||
vec2 pp = vTexCoord.xy;
|
||||
pp = (param.CRT_CURVATURE > 0.5) ? Warp(pp) : pp;
|
||||
|
||||
vec2 pix_coord = pp.xy*TextureSize + vec2(-0.5, 0.5);
|
||||
|
||||
vec2 tc = mix((floor(pix_coord) + vec2(0.5, 0.5))/TextureSize, (floor(pix_coord) + vec2(1.5, -0.5))/TextureSize, param.VSCANLINES);
|
||||
|
||||
vec2 fp = mix(fract(pix_coord), fract(pix_coord.yx), param.VSCANLINES);
|
||||
|
||||
vec3 c00 = texture(Source, tc - dx - dy).xyz;
|
||||
vec3 c01 = texture(Source, tc - dy).xyz;
|
||||
vec3 c02 = texture(Source, tc + dx - dy).xyz;
|
||||
vec3 c03 = texture(Source, tc + 2.0*dx - dy).xyz;
|
||||
vec3 c10 = texture(Source, tc - dx ).xyz;
|
||||
vec3 c11 = texture(Source, tc ).xyz;
|
||||
vec3 c12 = texture(Source, tc + dx ).xyz;
|
||||
vec3 c13 = texture(Source, tc + 2.0*dx ).xyz;
|
||||
|
||||
mat4x3 color_matrix0 = mat4x3(c00, c01, c02, c03);
|
||||
mat4x3 color_matrix1 = mat4x3(c10, c11, c12, c13);
|
||||
|
||||
// Get weights for spline16 horizontal filter
|
||||
vec4 weights = weight4(1.0 - fp.x);
|
||||
|
||||
// Spline16 horizontal filter
|
||||
vec3 color0 = (color_matrix0 * weights)/dot(weights, vec4(1.0));
|
||||
vec3 color1 = (color_matrix1 * weights)/dot(weights, vec4(1.0));
|
||||
|
||||
// Get min/max samples
|
||||
vec3 min_sample0 = min(c01,c02);
|
||||
vec3 max_sample0 = max(c01,c02);
|
||||
vec3 min_sample1 = min(c11,c12);
|
||||
vec3 max_sample1 = max(c11,c12);
|
||||
|
||||
// Anti-ringing
|
||||
vec3 aux = color0;
|
||||
color0 = clamp(color0, min_sample0, max_sample0);
|
||||
color0 = mix(aux, color0, CRT_ANTI_RINGING * step(0.0, (c00-c01)*(c02-c03)));
|
||||
aux = color1;
|
||||
color1 = clamp(color1, min_sample1, max_sample1);
|
||||
color1 = mix(aux, color1, CRT_ANTI_RINGING * step(0.0, (c10-c11)*(c12-c13)));
|
||||
|
||||
// Apply scanlines. Sinc filter vertically.
|
||||
float pos0 = fp.y;
|
||||
float pos1 = 1 - fp.y;
|
||||
|
||||
vec3 lum0 = mix(vec3(beam_min_width), vec3(beam_max_width), color0);
|
||||
vec3 lum1 = mix(vec3(beam_min_width), vec3(beam_max_width), color1);
|
||||
|
||||
vec3 d0 = clamp(scanlines_strength*pos0/(lum0*lum0+0.0000001), 0.0, 1.0);
|
||||
vec3 d1 = clamp(scanlines_strength*pos1/(lum1*lum1+0.0000001), 0.0, 1.0);
|
||||
|
||||
d0 = resampler3(d0);
|
||||
d1 = resampler3(d1);
|
||||
|
||||
// Apply color enhancement, scanlines orientation, mask and gamma.
|
||||
vec3 color = color_boost*(color0*d0+color1*d1)/(wa*wb);
|
||||
|
||||
vec2 mask_coords = vTexCoord.xy * global.OutputSize.xy;
|
||||
|
||||
mask_coords = mix(mask_coords.xy, mask_coords.yx, param.VSCANLINES);
|
||||
|
||||
color.rgb*=mask_weights(mask_coords, param.MASK_INTENSITY, int(param.PHOSPHOR_LAYOUT));
|
||||
|
||||
FragColor = vec4(color, 1.0);
|
||||
|
||||
FragColor *= (param.CRT_CURVATURE > 0.5) ? corner(pp) : 1.0;
|
||||
}
|
93
crt/shaders/crt-super-xbr/custom-bicubic-x.slang
Normal file
93
crt/shaders/crt-super-xbr/custom-bicubic-x.slang
Normal file
|
@ -0,0 +1,93 @@
|
|||
#version 450
|
||||
|
||||
/*
|
||||
b-spline-x Shader
|
||||
|
||||
Copyright (C) 2011-2022 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;
|
||||
|
||||
// B-Spline bicubic parameters
|
||||
const float B = 0.0;
|
||||
const float C = 1.0;
|
||||
|
||||
const mat4 INV = mat4( (-B - 6.0*C)/6.0, (3.0*B + 12.0*C)/6.0, (-3.0*B - 6.0*C)/6.0, B/6.0,
|
||||
(12.0 - 9.0*B - 6.0*C)/6.0, (-18.0 + 12.0*B + 6.0*C)/6.0, 0.0, (6.0 - 2.0*B)/6.0,
|
||||
-(12.0 - 9.0*B - 6.0*C)/6.0, (18.0 - 15.0*B - 12.0*C)/6.0, (3.0*B + 6.0*C)/6.0, B/6.0,
|
||||
(B + 6.0*C)/6.0, -C, 0.0, 0.0);
|
||||
|
||||
#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;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
|
||||
vec2 ps = vec2(params.SourceSize.z, params.SourceSize.w);
|
||||
float dx = ps.x;
|
||||
float dy = ps.y;
|
||||
|
||||
vTexCoord = TexCoord * 1.0001 - vec2(0.5, 0.0)*ps;
|
||||
// vTexCoord = TexCoord * 1.0001 - vec2(1.0, 0.0)*ps;
|
||||
|
||||
t1 = vTexCoord.xyxy + vec4( -dx, 0.0, 0.0, 0.0);
|
||||
t2 = vTexCoord.xyxy + vec4( dx, 0.0, 2.0*dx, 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 = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 fp = fract(vTexCoord*params.SourceSize.xy);
|
||||
|
||||
vec3 C0 = texture(Source, t1.xy).xyz;
|
||||
vec3 C1 = texture(Source, t1.zw).xyz;
|
||||
vec3 C2 = texture(Source, t2.xy).xyz;
|
||||
vec3 C3 = texture(Source, t2.zw).xyz;
|
||||
|
||||
vec4 Px = vec4(fp.x*fp.x*fp.x, fp.x*fp.x, fp.x, 1.0) * INV;
|
||||
vec3 color = mat4x3(C0, C1, C2, C3) * Px;
|
||||
|
||||
FragColor = vec4(color, 1.0);
|
||||
}
|
92
crt/shaders/crt-super-xbr/custom-bicubic-y.slang
Normal file
92
crt/shaders/crt-super-xbr/custom-bicubic-y.slang
Normal file
|
@ -0,0 +1,92 @@
|
|||
#version 450
|
||||
|
||||
/*
|
||||
b-spline-y Shader
|
||||
|
||||
Copyright (C) 2011-2022 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;
|
||||
|
||||
// B-Spline bicubic parameters
|
||||
const float B = 0.0;
|
||||
const float C = 1.0;
|
||||
|
||||
const mat4 INV = mat4( (-B - 6.0*C)/6.0, (3.0*B + 12.0*C)/6.0, (-3.0*B - 6.0*C)/6.0, B/6.0,
|
||||
(12.0 - 9.0*B - 6.0*C)/6.0, (-18.0 + 12.0*B + 6.0*C)/6.0, 0.0, (6.0 - 2.0*B)/6.0,
|
||||
-(12.0 - 9.0*B - 6.0*C)/6.0, (18.0 - 15.0*B - 12.0*C)/6.0, (3.0*B + 6.0*C)/6.0, B/6.0,
|
||||
(B + 6.0*C)/6.0, -C, 0.0, 0.0);
|
||||
|
||||
#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;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
|
||||
vec2 ps = vec2(params.SourceSize.z, params.SourceSize.w);
|
||||
float dx = ps.x;
|
||||
float dy = ps.y;
|
||||
|
||||
vTexCoord = TexCoord * 1.0001 - vec2(0.0, 0.5)*ps;
|
||||
|
||||
t1 = vTexCoord.xyxy + vec4( 0.0, -dy, 0.0, 0.0);
|
||||
t2 = vTexCoord.xyxy + vec4( 0.0, dy, 0.0, 2.0*dy);
|
||||
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 1) in vec4 t1;
|
||||
layout(location = 2) in vec4 t2;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 fp = fract(vTexCoord*params.SourceSize.xy);
|
||||
|
||||
vec3 C0 = texture(Source, t1.xy).xyz;
|
||||
vec3 C1 = texture(Source, t1.zw).xyz;
|
||||
vec3 C2 = texture(Source, t2.xy).xyz;
|
||||
vec3 C3 = texture(Source, t2.zw).xyz;
|
||||
|
||||
vec4 Py = vec4(fp.y*fp.y*fp.y, fp.y*fp.y, fp.y, 1.0) * INV;
|
||||
vec3 color = mat4x3(C0, C1, C2, C3) * Py;
|
||||
|
||||
FragColor = vec4(color, 1.0);
|
||||
}
|
53
crt/shaders/crt-super-xbr/custom-resolve.slang
Normal file
53
crt/shaders/crt-super-xbr/custom-resolve.slang
Normal file
|
@ -0,0 +1,53 @@
|
|||
#version 450
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
float BLOOM_STRENGTH;
|
||||
float SOURCE_BOOST;
|
||||
float OUTPUT_GAMMA;
|
||||
} params;
|
||||
|
||||
#pragma parameter BLOOM_STRENGTH "Bloom Strength" 0.10 0.0 1.0 0.01
|
||||
#pragma parameter SOURCE_BOOST "Bloom Color Boost" 1.15 1.0 2.0 0.05
|
||||
#pragma parameter OUTPUT_GAMMA "OUTPUT GAMMA" 2.2 1.0 3.0 0.1
|
||||
|
||||
#define BLOOM_STRENGTH params.BLOOM_STRENGTH
|
||||
#define SOURCE_BOOST params.SOURCE_BOOST
|
||||
#define OUTPUT_GAMMA params.OUTPUT_GAMMA
|
||||
|
||||
#define INV_OUTPUT_GAMMA (1.0 / OUTPUT_GAMMA)
|
||||
#define saturate(c) clamp(c, 0.0, 1.0)
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
} global;
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
layout(set = 0, binding = 3) uniform sampler2D CRT_PASS;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 source = SOURCE_BOOST * texture(CRT_PASS, vTexCoord).rgb;
|
||||
vec3 bloom = texture(Source, vTexCoord).rgb;
|
||||
source += BLOOM_STRENGTH * bloom;
|
||||
FragColor = vec4(pow(saturate(source), vec3(INV_OUTPUT_GAMMA,INV_OUTPUT_GAMMA,INV_OUTPUT_GAMMA)), 1.0);
|
||||
}
|
40
crt/shaders/crt-super-xbr/linearize.slang
Normal file
40
crt/shaders/crt-super-xbr/linearize.slang
Normal file
|
@ -0,0 +1,40 @@
|
|||
#version 450
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
float INPUT_GAMMA;
|
||||
} params;
|
||||
|
||||
#pragma parameter INPUT_GAMMA "Input Gamma" 2.4 2.0 2.6 0.02
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
vec4 OutputSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 SourceSize;
|
||||
} global;
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
#pragma format R8G8B8A8_SRGB
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 color = texture(Source, vTexCoord).rgb;
|
||||
|
||||
FragColor = vec4(pow(color, vec3(params.INPUT_GAMMA)), 1.0);
|
||||
}
|
238
crt/shaders/crt-super-xbr/super-xbr-pass0.slang
Normal file
238
crt/shaders/crt-super-xbr/super-xbr-pass0.slang
Normal file
|
@ -0,0 +1,238 @@
|
|||
#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_P0;
|
||||
float XBR_WEIGHT;
|
||||
float XBR_ANTI_RINGING;
|
||||
float MODE;
|
||||
float XBR_EDGE_SHP;
|
||||
float XBR_TEXTURE_SHP;
|
||||
} params;
|
||||
|
||||
#pragma parameter MODE "Mode - Normal, Details, Adaptive" 1.0 0.0 2.0 1.0
|
||||
#pragma parameter XBR_EDGE_STR_P0 "Xbr - Edge Strength p0" 1.0 0.0 5.0 0.5
|
||||
#pragma parameter XBR_WEIGHT "Xbr - Filter Weight" 0.0 0.0 1.0 0.1
|
||||
#pragma parameter XBR_EDGE_SHP "Adaptive Dynamic Edge Sharp" 0.4 0.0 3.0 0.1
|
||||
#pragma parameter XBR_TEXTURE_SHP "Adaptive Static Edge Sharp" 1.0 0.0 2.0 0.1
|
||||
|
||||
#define XBR_EDGE_STR_P0 params.XBR_EDGE_STR_P0
|
||||
#define XBR_WEIGHT params.XBR_WEIGHT
|
||||
#define MODE params.MODE
|
||||
#define XBR_EDGE_SHP params.XBR_EDGE_SHP
|
||||
#define XBR_TEXTURE_SHP params.XBR_TEXTURE_SHP
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
} global;
|
||||
|
||||
#define mul(a,b) (b*a)
|
||||
|
||||
const vec3 Y = vec3(.2126, .7152, .0722);
|
||||
|
||||
float RGBtoYUV(vec3 color)
|
||||
{
|
||||
return dot(color, Y);
|
||||
}
|
||||
|
||||
float df(float A, float B)
|
||||
{
|
||||
return abs(A-B);
|
||||
}
|
||||
|
||||
/*
|
||||
P1
|
||||
|P0|B |C |P1| C F4 |a0|b1|c2|d3|
|
||||
|D |E |F |F4| B F I4 |b0|c1|d2|e3| |e1|i1|i2|e2|
|
||||
|G |H |I |I4| P0 E A I P3 |c0|d1|e2|f3| |e3|i3|i4|e4|
|
||||
|P2|H5|I5|P3| D H I5 |d0|e1|f2|g3|
|
||||
G H5
|
||||
P2
|
||||
*/
|
||||
|
||||
|
||||
float d_wd(float wp1, float wp2, float wp3, float wp4, float wp5, float wp6, float b0, float b1, float c0, float c1, float c2, float d0, float d1, float d2, float d3, float e1, float e2, float e3, float f2, float f3)
|
||||
{
|
||||
return (wp1*(df(c1,c2) + df(c1,c0) + df(e2,e1) + df(e2,e3)) + wp2*(df(d2,d3) + df(d0,d1)) + wp3*(df(d1,d3) + df(d0,d2)) + wp4*df(d1,d2) + wp5*(df(c0,c2) + df(e1,e3)) + wp6*(df(b0,b1) + df(f2,f3)));
|
||||
}
|
||||
|
||||
float hv_wd(float wp1, float wp2, float wp3, float wp4, float wp5, float wp6, float i1, float i2, float i3, float i4, float e1, float e2, float e3, float e4)
|
||||
{
|
||||
return ( wp4*(df(i1,i2)+df(i3,i4)) + wp1*(df(i1,e1)+df(i2,e2)+df(i3,e3)+df(i4,e4)) + wp3*(df(i1,e2)+df(i3,e4)+df(e1,i2)+df(e3,i4)));
|
||||
}
|
||||
|
||||
vec3 min4(vec3 a, vec3 b, vec3 c, vec3 d)
|
||||
{
|
||||
return min(a, min(b, min(c, d)));
|
||||
}
|
||||
|
||||
vec3 max4(vec3 a, vec3 b, vec3 c, vec3 d)
|
||||
{
|
||||
return max(a, max(b, max(c, d)));
|
||||
}
|
||||
|
||||
float max4float(float a, float b, float c, float d)
|
||||
{
|
||||
return max(a, max(b, max(c, d)));
|
||||
}
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
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 * 1.0001;
|
||||
|
||||
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()
|
||||
{
|
||||
// settings //
|
||||
float wp1, wp2, wp3, wp4, wp5, wp6, weight1, weight2;
|
||||
|
||||
wp1 = 2.0;
|
||||
wp2 = 1.0;
|
||||
wp3 = -1.0;
|
||||
wp4 = 4.0;
|
||||
wp5 = -1.0;
|
||||
wp6 = 1.0;
|
||||
|
||||
weight1 = (XBR_WEIGHT*1.29633/10.0);
|
||||
weight2 = (XBR_WEIGHT*1.75068/10.0/2.0);
|
||||
|
||||
// end settings //
|
||||
|
||||
vec3 P0 = texture(Source, t1.xy).xyz;
|
||||
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( wp1, wp2, wp3, wp4, wp5, wp6, d, b, g, e, c, p2, h, f, p1, h5, i, f4, i5, i4 ) - d_wd( wp1, wp2, wp3, wp4, wp5, wp6, c, f4, b, f, i4, p0, e, i, p3, d, h, i5, g, h5 ));
|
||||
|
||||
/* Calc edgeness in horizontal/vertical directions. */
|
||||
float hv_edge = (hv_wd(wp1, wp2, wp3, wp4, wp5, wp6, f, i, e, h, c, i5, b, h5) - hv_wd(wp1, wp2, wp3, wp4, wp5, wp6, e, f, h, i, d, f4, g, i4));
|
||||
|
||||
float limits = XBR_EDGE_STR_P0 + 0.000001;
|
||||
float edge_strength = smoothstep(0.0, limits, abs(d_edge));
|
||||
|
||||
vec4 w1, w2;
|
||||
vec3 c3, c4;
|
||||
if (MODE == 2.0)
|
||||
{
|
||||
float contrast = max(max4float(df(e,f),df(e,i),df(e,h),df(f,h)),max(df(f,i),df(h,i)))/(e+0.001);
|
||||
|
||||
float wgt1 = weight1*(smoothstep(0.0, 0.6, contrast)*XBR_EDGE_SHP + XBR_TEXTURE_SHP);
|
||||
float wgt2 = weight2*(smoothstep(0.0, 0.6, contrast)*XBR_EDGE_SHP + XBR_TEXTURE_SHP);
|
||||
|
||||
/* Filter weights. Two taps only. */
|
||||
w1 = vec4(-wgt1, wgt1+ 0.5, wgt1+ 0.5, -wgt1);
|
||||
w2 = vec4(-wgt2, wgt2+0.25, wgt2+0.25, -wgt2);
|
||||
c3 = mul(w2, mat4x3(P0+2.0*(D+G)+P2, B+2.0*(E+H)+H5, C+2.0*(F+I)+I5, P1+2.0*(F4+I4)+P3))/3.0;
|
||||
c4 = mul(w2, mat4x3(P0+2.0*(C+B)+P1, D+2.0*(F+E)+F4, G+2.0*(I+H)+I4, P2+2.0*(I5+H5)+P3))/3.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Filter weights. Two taps only. */
|
||||
w1 = vec4(-weight1, weight1+0.5, weight1+0.5, -weight1);
|
||||
w2 = vec4(-weight2, weight2+0.25, weight2+0.25, -weight2);
|
||||
c3 = mul(w2, mat4x3(D+G, E+H, F+I, F4+I4));
|
||||
c4 = mul(w2, mat4x3(C+B, F+E, I+H, I5+H5));
|
||||
}
|
||||
|
||||
/* Filtering and normalization in four direction generating four colors. */
|
||||
vec3 c1 = mul(w1, mat4x3( P2, H, F, P1 ));
|
||||
vec3 c2 = mul(w1, mat4x3( P0, E, I, P3 ));
|
||||
|
||||
/* Smoothly blends the two strongest directions (one in diagonal and the other in vert/horiz direction). */
|
||||
vec3 color = mix(mix(c1, c2, step(0.0, d_edge)), mix(c3, c4, step(0.0, hv_edge)), 1. - edge_strength);
|
||||
|
||||
/* Anti-ringing code. */
|
||||
vec3 min_sample = min4( E, F, H, I );
|
||||
vec3 max_sample = max4( E, F, H, I );
|
||||
color = clamp(color, min_sample, max_sample);
|
||||
|
||||
FragColor = vec4(color, 1.0);
|
||||
}
|
258
crt/shaders/crt-super-xbr/super-xbr-pass1.slang
Normal file
258
crt/shaders/crt-super-xbr/super-xbr-pass1.slang
Normal file
|
@ -0,0 +1,258 @@
|
|||
#version 450
|
||||
|
||||
/*
|
||||
|
||||
******* Super XBR Shader - pass1 *******
|
||||
|
||||
Copyright (c) 2015 Hyllian - sergiogdb@gmail.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#define XBR_WEIGHT 1.0
|
||||
#define XBR_ANTI_RINGING 1.0
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
float MODE;
|
||||
float XBR_EDGE_SHP;
|
||||
float XBR_TEXTURE_SHP;
|
||||
float XBR_EDGE_STR_P1;
|
||||
} params;
|
||||
|
||||
#pragma parameter XBR_EDGE_STR_P1 "Xbr - Edge Strength p1" 1.0 0.0 5.0 0.5
|
||||
#pragma parameter MODE "Mode - Normal, Details, Adaptive" 1.0 0.0 2.0 1.0
|
||||
#pragma parameter XBR_EDGE_SHP "Adaptive Dynamic Edge Sharp" 0.4 0.0 3.0 0.1
|
||||
#pragma parameter XBR_TEXTURE_SHP "Adaptive Static Edge Sharp" 1.0 0.0 2.0 0.1
|
||||
|
||||
#define MODE params.MODE
|
||||
#define XBR_EDGE_SHP params.XBR_EDGE_SHP
|
||||
#define XBR_TEXTURE_SHP params.XBR_TEXTURE_SHP
|
||||
#define XBR_EDGE_STR_P1 params.XBR_EDGE_STR_P1
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
} global;
|
||||
|
||||
#define mul(a,b) (b*a)
|
||||
|
||||
const vec3 Y = vec3(.2126, .7152, .0722);
|
||||
|
||||
float RGBtoYUV(vec3 color)
|
||||
{
|
||||
return dot(color, Y);
|
||||
}
|
||||
|
||||
float df(float A, float B)
|
||||
{
|
||||
return abs(A-B);
|
||||
}
|
||||
|
||||
/*
|
||||
P1
|
||||
|P0|B |C |P1| C F4 |a0|b1|c2|d3|
|
||||
|D |E |F |F4| B F I4 |b0|c1|d2|e3| |e1|i1|i2|e2|
|
||||
|G |H |I |I4| P0 E A I P3 |c0|d1|e2|f3| |e3|i3|i4|e4|
|
||||
|P2|H5|I5|P3| D H I5 |d0|e1|f2|g3|
|
||||
G H5
|
||||
P2
|
||||
*/
|
||||
|
||||
float d_wd(float wp1, float wp2, float wp3, float wp4, float wp5, float wp6, float b0, float b1, float c0, float c1, float c2, float d0, float d1, float d2, float d3, float e1, float e2, float e3, float f2, float f3)
|
||||
{
|
||||
return (wp1*(df(c1,c2) + df(c1,c0) + df(e2,e1) + df(e2,e3)) + wp2*(df(d2,d3) + df(d0,d1)) + wp3*(df(d1,d3) + df(d0,d2)) + wp4*df(d1,d2) + wp5*(df(c0,c2) + df(e1,e3)) + wp6*(df(b0,b1) + df(f2,f3)));
|
||||
}
|
||||
|
||||
float hv_wd(float wp1, float wp2, float wp3, float wp4, float wp5, float wp6, float i1, float i2, float i3, float i4, float e1, float e2, float e3, float e4)
|
||||
{
|
||||
return ( wp4*(df(i1,i2)+df(i3,i4)) + wp1*(df(i1,e1)+df(i2,e2)+df(i3,e3)+df(i4,e4)) + wp3*(df(i1,e2)+df(i3,e4)+df(e1,i2)+df(e3,i4)));
|
||||
}
|
||||
|
||||
vec3 min4(vec3 a, vec3 b, vec3 c, vec3 d)
|
||||
{
|
||||
return min(a, min(b, min(c, d)));
|
||||
}
|
||||
vec3 max4(vec3 a, vec3 b, vec3 c, vec3 d)
|
||||
{
|
||||
return max(a, max(b, max(c, d)));
|
||||
}
|
||||
|
||||
float max4float(float a, float b, float c, float d)
|
||||
{
|
||||
return max(a, max(b, max(c, d)));
|
||||
}
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord * 1.0001;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
layout(set = 0, binding = 3) uniform sampler2D XbrSource;
|
||||
|
||||
void main()
|
||||
{
|
||||
// settings //
|
||||
float wp1, wp2, wp3, wp4, wp5, wp6, weight1, weight2;
|
||||
if (MODE == 1.0)
|
||||
{
|
||||
wp1 = 1.0;
|
||||
wp2 = 0.0;
|
||||
wp3 = 0.0;
|
||||
wp4 = 0.0;
|
||||
wp5 = 0.0;
|
||||
wp6 = 0.0;
|
||||
|
||||
weight1 = (XBR_WEIGHT*1.29633/10.0);
|
||||
weight2 = (XBR_WEIGHT*1.75068/10.0/2.0);
|
||||
}
|
||||
else if (MODE == 2.0)
|
||||
{
|
||||
wp1 = 8.0;
|
||||
wp2 = 0.0;
|
||||
wp3 = 0.0;
|
||||
wp4 = 0.0;
|
||||
wp5 = 0.0;
|
||||
wp6 = 0.0;
|
||||
|
||||
weight1 = (1.29633/10.0);
|
||||
weight2 = (1.75068/10.0/2.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
wp1 = 8.0;
|
||||
wp2 = 0.0;
|
||||
wp3 = 0.0;
|
||||
wp4 = 0.0;
|
||||
wp5 = 0.0;
|
||||
wp6 = 0.0;
|
||||
|
||||
weight1 = (XBR_WEIGHT*1.29633/10.0);
|
||||
weight2 = (XBR_WEIGHT*1.75068/10.0/2.0);
|
||||
}
|
||||
// end settings //
|
||||
|
||||
//Skip pixels on wrong grid
|
||||
vec2 fp = fract(vTexCoord.xy * params.SourceSize.xy);
|
||||
vec2 dir = fp - vec2(0.5,0.5);
|
||||
if ((dir.x*dir.y)>0.0)
|
||||
{
|
||||
FragColor = mix( texture(XbrSource, vTexCoord), texture(Source, vTexCoord), step(0.0, dir.x));
|
||||
}
|
||||
else
|
||||
{
|
||||
vec2 g1 = (fp.x>0.5) ? vec2(0.5/params.SourceSize.x, 0.0) : vec2(0.0, 0.5/params.SourceSize.y);
|
||||
vec2 g2 = (fp.x>0.5) ? vec2(0.0, 0.5/params.SourceSize.y) : vec2(0.5/params.SourceSize.x, 0.0);
|
||||
|
||||
vec3 P0 = texture(XbrSource, 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(XbrSource, vTexCoord +3.0*g1 ).xyz;
|
||||
|
||||
vec3 B = texture(Source, vTexCoord -2.0*g1 -g2).xyz;
|
||||
vec3 C = texture(XbrSource, vTexCoord -g1 -2.0*g2).xyz;
|
||||
vec3 D = texture(Source, vTexCoord -2.0*g1 +g2).xyz;
|
||||
vec3 E = texture(XbrSource, vTexCoord -g1 ).xyz;
|
||||
vec3 F = texture(Source, vTexCoord -g2).xyz;
|
||||
vec3 G = texture(XbrSource, vTexCoord -g1 +2.0*g2).xyz;
|
||||
vec3 H = texture(Source, vTexCoord +g2).xyz;
|
||||
vec3 I = texture(XbrSource, vTexCoord +g1 ).xyz;
|
||||
|
||||
vec3 F4 = texture(XbrSource, vTexCoord +g1 -2.0*g2).xyz;
|
||||
vec3 I4 = texture(Source, vTexCoord +2.0*g1 -g2).xyz;
|
||||
vec3 H5 = texture(XbrSource, vTexCoord +g1 +2.0*g2).xyz;
|
||||
vec3 I5 = texture(Source, vTexCoord +2.0*g1 +g2).xyz;
|
||||
|
||||
float b = RGBtoYUV( B );
|
||||
float c = RGBtoYUV( C );
|
||||
float d = RGBtoYUV( D );
|
||||
float e = RGBtoYUV( E );
|
||||
float f = RGBtoYUV( F );
|
||||
float g = RGBtoYUV( G );
|
||||
float h = RGBtoYUV( H );
|
||||
float i = RGBtoYUV( I );
|
||||
|
||||
float i4 = RGBtoYUV( I4 ); float p0 = RGBtoYUV( P0 );
|
||||
float i5 = RGBtoYUV( I5 ); float p1 = RGBtoYUV( P1 );
|
||||
float h5 = RGBtoYUV( H5 ); float p2 = RGBtoYUV( P2 );
|
||||
float f4 = RGBtoYUV( F4 ); float p3 = RGBtoYUV( P3 );
|
||||
|
||||
/* Calc edgeness in diagonal directions. */
|
||||
float d_edge = (d_wd( wp1, wp2, wp3, wp4, wp5, wp6, d, b, g, e, c, p2, h, f, p1, h5, i, f4, i5, i4 ) - d_wd( wp1, wp2, wp3, wp4, wp5, wp6, c, f4, b, f, i4, p0, e, i, p3, d, h, i5, g, h5 ));
|
||||
|
||||
/* Calc edgeness in horizontal/vertical directions. */
|
||||
float hv_edge = (hv_wd(wp1, wp2, wp3, wp4, wp5, wp6, f, i, e, h, c, i5, b, h5) - hv_wd(wp1, wp2, wp3, wp4, wp5, wp6, e, f, h, i, d, f4, g, i4));
|
||||
|
||||
float limits = XBR_EDGE_STR_P1 + 0.000001;
|
||||
float edge_strength = smoothstep(0.0, limits, abs(d_edge));
|
||||
|
||||
vec4 w1, w2;
|
||||
vec3 c3, c4;
|
||||
if (MODE == 2.0)
|
||||
{
|
||||
float contrast = max(max4float(df(e,f),df(e,i),df(e,h),df(f,h)),max(df(f,i),df(h,i)))/(e+0.001);
|
||||
|
||||
float wgt1 = weight1*(smoothstep(0.0, 0.6, contrast)*XBR_EDGE_SHP + XBR_TEXTURE_SHP);
|
||||
float wgt2 = weight2*(smoothstep(0.0, 0.6, contrast)*XBR_EDGE_SHP + XBR_TEXTURE_SHP);
|
||||
|
||||
/* Filter weights. Two taps only. */
|
||||
w1 = vec4(-wgt1, wgt1+ 0.5, wgt1+ 0.5, -wgt1);
|
||||
w2 = vec4(-wgt2, wgt2+0.25, wgt2+0.25, -wgt2);
|
||||
c3 = mul(w2, mat4x3(P0+2.0*(D+G)+P2, B+2.0*(E+H)+H5, C+2.0*(F+I)+I5, P1+2.0*(F4+I4)+P3))/3.0;
|
||||
c4 = mul(w2, mat4x3(P0+2.0*(C+B)+P1, D+2.0*(F+E)+F4, G+2.0*(I+H)+I4, P2+2.0*(I5+H5)+P3))/3.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Filter weights. Two taps only. */
|
||||
w1 = vec4(-weight1, weight1+0.5, weight1+0.5, -weight1);
|
||||
w2 = vec4(-weight2, weight2+0.25, weight2+0.25, -weight2);
|
||||
c3 = mul(w2, mat4x3(D+G, E+H, F+I, F4+I4));
|
||||
c4 = mul(w2, mat4x3(C+B, F+E, I+H, I5+H5));
|
||||
}
|
||||
|
||||
/* Filtering and normalization in four direction generating four colors. */
|
||||
vec3 c1 = mul(w1, mat4x3( P2, H, F, P1 ));
|
||||
vec3 c2 = mul(w1, mat4x3( P0, E, I, P3 ));
|
||||
|
||||
/* Smoothly blends the two strongest directions (one in diagonal and the other in vert/horiz direction). */
|
||||
vec3 color = mix(mix(c1, c2, step(0.0, d_edge)), mix(c3, c4, step(0.0, hv_edge)), 1. - edge_strength);
|
||||
|
||||
/* Anti-ringing code. */
|
||||
vec3 min_sample = min4( E, F, H, I );
|
||||
vec3 max_sample = max4( E, F, H, I );
|
||||
color = clamp(color, min_sample, max_sample);
|
||||
|
||||
FragColor = vec4(color, 1.0);
|
||||
}
|
||||
}
|
270
crt/shaders/crt-super-xbr/super-xbr-pass2.slang
Normal file
270
crt/shaders/crt-super-xbr/super-xbr-pass2.slang
Normal file
|
@ -0,0 +1,270 @@
|
|||
#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_WEIGHT = 1.0;
|
||||
const float XBR_ANTI_RINGING = 1.0;
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
float MODE;
|
||||
float XBR_EDGE_SHP;
|
||||
float XBR_TEXTURE_SHP;
|
||||
float XBR_EDGE_STR_P2;
|
||||
} params;
|
||||
|
||||
#pragma parameter MODE "Mode - Normal, Details, Adaptive" 1.0 0.0 2.0 1.0
|
||||
#pragma parameter XBR_EDGE_STR_P2 "Xbr - Edge Strength p2" 1.0 0.0 5.0 0.5
|
||||
#pragma parameter XBR_EDGE_SHP "Adaptive Dynamic Edge Sharp" 0.4 0.0 3.0 0.1
|
||||
#pragma parameter XBR_TEXTURE_SHP "Adaptive Static Edge Sharp" 1.0 0.0 2.0 0.1
|
||||
|
||||
#define MODE params.MODE
|
||||
#define XBR_EDGE_SHP params.XBR_EDGE_SHP
|
||||
#define XBR_TEXTURE_SHP params.XBR_TEXTURE_SHP
|
||||
#define XBR_EDGE_STR_P2 params.XBR_EDGE_STR_P2
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
} global;
|
||||
|
||||
#define mul(a,b) (b*a)
|
||||
|
||||
const vec3 Y = vec3(.2126, .7152, .0722);
|
||||
|
||||
float RGBtoYUV(vec3 color)
|
||||
{
|
||||
return dot(color, Y);
|
||||
}
|
||||
|
||||
float df(float A, float B)
|
||||
{
|
||||
return abs(A-B);
|
||||
}
|
||||
|
||||
/*
|
||||
P1
|
||||
|P0|B |C |P1| C F4 |a0|b1|c2|d3|
|
||||
|D |E |F |F4| B F I4 |b0|c1|d2|e3| |e1|i1|i2|e2|
|
||||
|G |H |I |I4| P0 E A I P3 |c0|d1|e2|f3| |e3|i3|i4|e4|
|
||||
|P2|H5|I5|P3| D H I5 |d0|e1|f2|g3|
|
||||
G H5
|
||||
P2
|
||||
*/
|
||||
|
||||
float d_wd(float wp1, float wp2, float wp3, float wp4, float wp5, float wp6, float b0, float b1, float c0, float c1, float c2, float d0, float d1, float d2, float d3, float e1, float e2, float e3, float f2, float f3)
|
||||
{
|
||||
return (wp1*(df(c1,c2) + df(c1,c0) + df(e2,e1) + df(e2,e3)) + wp2*(df(d2,d3) + df(d0,d1)) + wp3*(df(d1,d3) + df(d0,d2)) + wp4*df(d1,d2) + wp5*(df(c0,c2) + df(e1,e3)) + wp6*(df(b0,b1) + df(f2,f3)));
|
||||
}
|
||||
|
||||
float hv_wd(float wp1, float wp2, float wp3, float wp4, float wp5, float wp6, float i1, float i2, float i3, float i4, float e1, float e2, float e3, float e4)
|
||||
{
|
||||
return ( wp4*(df(i1,i2)+df(i3,i4)) + wp1*(df(i1,e1)+df(i2,e2)+df(i3,e3)+df(i4,e4)) + wp3*(df(i1,e2)+df(i3,e4)+df(e1,i2)+df(e3,i4)));
|
||||
}
|
||||
|
||||
vec3 min4(vec3 a, vec3 b, vec3 c, vec3 d)
|
||||
{
|
||||
return min(a, min(b, min(c, d)));
|
||||
}
|
||||
vec3 max4(vec3 a, vec3 b, vec3 c, vec3 d)
|
||||
{
|
||||
return max(a, max(b, max(c, d)));
|
||||
}
|
||||
|
||||
float max4float(float a, float b, float c, float d)
|
||||
{
|
||||
return max(a, max(b, max(c, d)));
|
||||
}
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
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 * 1.0001;
|
||||
|
||||
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()
|
||||
{
|
||||
// settings //
|
||||
float wp1, wp2, wp3, wp4, wp5, wp6, weight1, weight2;
|
||||
if (MODE == 1.0)
|
||||
{
|
||||
wp1 = 0.0;
|
||||
wp2 = 0.0;
|
||||
wp3 = 0.0;
|
||||
wp4 = 1.0;
|
||||
wp5 = 0.0;
|
||||
wp6 = 0.0;
|
||||
|
||||
weight1 = (XBR_WEIGHT*1.29633/10.0);
|
||||
weight2 = (XBR_WEIGHT*1.75068/10.0/2.0);
|
||||
}
|
||||
else if (MODE == 2.0)
|
||||
{
|
||||
wp1 = 1.0;
|
||||
wp2 = 0.0;
|
||||
wp3 = 1.0;
|
||||
wp4 = 3.0;
|
||||
wp5 = -2.0;
|
||||
wp6 = 0.0;
|
||||
|
||||
weight1 = (1.29633/10.0);
|
||||
weight2 = (1.75068/10.0/2.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
wp1 = 1.0;
|
||||
wp2 = 0.0;
|
||||
wp3 = 2.0;
|
||||
wp4 = 3.0;
|
||||
wp5 = -2.0;
|
||||
wp6 = 1.0;
|
||||
|
||||
weight1 = (XBR_WEIGHT*1.29633/10.0);
|
||||
weight2 = (XBR_WEIGHT*1.75068/10.0/2.0);
|
||||
}
|
||||
// end settings //
|
||||
|
||||
vec3 P0 = texture(Source, t1.xy).xyz;
|
||||
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( wp1, wp2, wp3, wp4, wp5, wp6, d, b, g, e, c, p2, h, f, p1, h5, i, f4, i5, i4 ) - d_wd( wp1, wp2, wp3, wp4, wp5, wp6, c, f4, b, f, i4, p0, e, i, p3, d, h, i5, g, h5 ));
|
||||
|
||||
/* Calc edgeness in horizontal/vertical directions. */
|
||||
float hv_edge = (hv_wd(wp1, wp2, wp3, wp4, wp5, wp6, f, i, e, h, c, i5, b, h5) - hv_wd(wp1, wp2, wp3, wp4, wp5, wp6, e, f, h, i, d, f4, g, i4));
|
||||
|
||||
float limits = XBR_EDGE_STR_P2 + 0.000001;
|
||||
float edge_strength = smoothstep(0.0, limits, abs(d_edge));
|
||||
|
||||
vec4 w1, w2;
|
||||
vec3 c3, c4;
|
||||
if (MODE == 2.0)
|
||||
{
|
||||
float contrast = max(max4float(df(e,f),df(e,i),df(e,h),df(f,h)),max(df(f,i),df(h,i)))/(e+0.001);
|
||||
|
||||
float wgt1 = weight1*(smoothstep(0.0, 0.6, contrast)*XBR_EDGE_SHP + XBR_TEXTURE_SHP);
|
||||
float wgt2 = weight2*(smoothstep(0.0, 0.6, contrast)*XBR_EDGE_SHP + XBR_TEXTURE_SHP);
|
||||
|
||||
/* Filter weights. Two taps only. */
|
||||
w1 = vec4(-wgt1, wgt1+ 0.5, wgt1+ 0.5, -wgt1);
|
||||
w2 = vec4(-wgt2, wgt2+0.25, wgt2+0.25, -wgt2);
|
||||
c3 = mul(w2, mat4x3(P0+2.0*(D+G)+P2, B+2.0*(E+H)+H5, C+2.0*(F+I)+I5, P1+2.0*(F4+I4)+P3))/3.0;
|
||||
c4 = mul(w2, mat4x3(P0+2.0*(C+B)+P1, D+2.0*(F+E)+F4, G+2.0*(I+H)+I4, P2+2.0*(I5+H5)+P3))/3.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Filter weights. Two taps only. */
|
||||
w1 = vec4(-weight1, weight1+0.5, weight1+0.5, -weight1);
|
||||
w2 = vec4(-weight2, weight2+0.25, weight2+0.25, -weight2);
|
||||
c3 = mul(w2, mat4x3(D+G, E+H, F+I, F4+I4));
|
||||
c4 = mul(w2, mat4x3(C+B, F+E, I+H, I5+H5));
|
||||
}
|
||||
|
||||
/* Filtering and normalization in four direction generating four colors. */
|
||||
vec3 c1 = mul(w1, mat4x3( P2, H, F, P1 ));
|
||||
vec3 c2 = mul(w1, mat4x3( P0, E, I, P3 ));
|
||||
|
||||
/* Smoothly blends the two strongest directions (one in diagonal and the other in vert/horiz direction). */
|
||||
vec3 color = mix(mix(c1, c2, step(0.0, d_edge)), mix(c3, c4, step(0.0, hv_edge)), 1. - edge_strength);
|
||||
|
||||
/* Anti-ringing code. */
|
||||
vec3 min_sample = min4( E, F, H, I );
|
||||
vec3 max_sample = max4( E, F, H, I );
|
||||
color = clamp(color, min_sample, max_sample);
|
||||
|
||||
FragColor = vec4(color, 1.0);
|
||||
}
|
43
crt/shaders/crt-super-xbr/threshold.slang
Normal file
43
crt/shaders/crt-super-xbr/threshold.slang
Normal file
|
@ -0,0 +1,43 @@
|
|||
#version 450
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
float GLOW_WHITEPOINT;
|
||||
float GLOW_ROLLOFF;
|
||||
} params;
|
||||
|
||||
#pragma parameter GLOW_WHITEPOINT "Glow Whitepoint" 1.0 0.5 1.1 0.02
|
||||
#pragma parameter GLOW_ROLLOFF "Glow Rolloff" 3.0 1.2 6.0 0.1
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
vec4 OutputSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 SourceSize;
|
||||
} global;
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
#pragma format R8G8B8A8_SRGB
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 color = 1.15 * texture(Source, vTexCoord).rgb;
|
||||
vec3 factor = clamp(color / params.GLOW_WHITEPOINT, 0.0, 1.0);
|
||||
|
||||
FragColor = vec4(pow(factor, vec3(params.GLOW_ROLLOFF)), 1.0);
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
shaders = "7"
|
||||
shader0 = "../ntsc/shaders/ntsc-adaptive/ntsc-pass1.slang"
|
||||
filter_linear0 = "false"
|
||||
wrap_mode0 = "clamp_to_border"
|
||||
frame_count_mod0 = "2"
|
||||
mipmap_input0 = "false"
|
||||
alias0 = ""
|
||||
float_framebuffer0 = "true"
|
||||
srgb_framebuffer0 = "false"
|
||||
scale_type_x0 = "source"
|
||||
scale_x0 = "4.000000"
|
||||
scale_type_y0 = "source"
|
||||
scale_y0 = "1.000000"
|
||||
shader1 = "../ntsc/shaders/ntsc-adaptive/ntsc-pass2.slang"
|
||||
filter_linear1 = "false"
|
||||
wrap_mode1 = "clamp_to_border"
|
||||
mipmap_input1 = "false"
|
||||
alias1 = ""
|
||||
float_framebuffer1 = "false"
|
||||
srgb_framebuffer1 = "true"
|
||||
scale_type_x1 = "source"
|
||||
scale_x1 = "0.500000"
|
||||
scale_type_y1 = "source"
|
||||
scale_y1 = "1.000000"
|
||||
shader2 = "../crt/shaders/hyllian/crt-hyllian-curvature.slang"
|
||||
filter_linear2 = "false"
|
||||
wrap_mode2 = "clamp_to_border"
|
||||
mipmap_input2 = "false"
|
||||
alias2 = "CRTPass"
|
||||
float_framebuffer2 = "false"
|
||||
srgb_framebuffer2 = "true"
|
||||
scale_type_x2 = "viewport"
|
||||
scale_x2 = "1.000000"
|
||||
scale_type_y2 = "viewport"
|
||||
scale_y2 = "1.000000"
|
||||
shader3 = "../crt/shaders/glow/threshold.slang"
|
||||
filter_linear3 = "false"
|
||||
wrap_mode3 = "clamp_to_border"
|
||||
mipmap_input3 = "false"
|
||||
alias3 = ""
|
||||
float_framebuffer3 = "false"
|
||||
srgb_framebuffer3 = "true"
|
||||
shader4 = "../crt/shaders/glow/blur_horiz.slang"
|
||||
filter_linear4 = "true"
|
||||
wrap_mode4 = "clamp_to_border"
|
||||
mipmap_input4 = "true"
|
||||
alias4 = ""
|
||||
float_framebuffer4 = "false"
|
||||
srgb_framebuffer4 = "true"
|
||||
scale_type_x4 = "viewport"
|
||||
scale_x4 = "0.200000"
|
||||
scale_type_y4 = "viewport"
|
||||
scale_y4 = "0.200000"
|
||||
shader5 = "../crt/shaders/glow/blur_vert.slang"
|
||||
filter_linear5 = "true"
|
||||
wrap_mode5 = "clamp_to_border"
|
||||
mipmap_input5 = "false"
|
||||
alias5 = ""
|
||||
float_framebuffer5 = "false"
|
||||
srgb_framebuffer5 = "true"
|
||||
shader6 = "../crt/shaders/glow/resolve.slang"
|
||||
filter_linear6 = "true"
|
||||
wrap_mode6 = "clamp_to_border"
|
||||
mipmap_input6 = "false"
|
||||
alias6 = ""
|
||||
float_framebuffer6 = "false"
|
||||
srgb_framebuffer6 = "false"
|
||||
parameters = "linearize;quality;BEAM_PROFILE;HFILTER_PROFILE;BEAM_MIN_WIDTH;BEAM_MAX_WIDTH;SCANLINES_STRENGTH;COLOR_BOOST;PHOSPHOR_LAYOUT;MASK_INTENSITY;CRT_ANTI_RINGING;InputGamma;OutputGamma;VSCANLINES;CRT_CURVATURE;CRT_warpX;CRT_warpY;CRT_cornersize;CRT_cornersmooth;GLOW_WHITEPOINT;GLOW_ROLLOFF;BLOOM_STRENGTH;OUTPUT_GAMMA;CURVATURE;warpX;warpY;cornersize;cornersmooth;noise_amt;shadowMask;maskDark;maskLight"
|
||||
BEAM_PROFILE = "1.000000"
|
||||
HFILTER_PROFILE = "1.000000"
|
||||
BEAM_MIN_WIDTH = "1.000000"
|
||||
BEAM_MAX_WIDTH = "1.000000"
|
||||
SCANLINES_STRENGTH = "0.620000"
|
||||
COLOR_BOOST = "1.400000"
|
||||
PHOSPHOR_LAYOUT = "4.000000"
|
||||
MASK_INTENSITY = "0.700000"
|
||||
CRT_ANTI_RINGING = "1.000000"
|
||||
InputGamma = "1.000000"
|
||||
OutputGamma = "1.000000"
|
||||
VSCANLINES = "0.000000"
|
||||
CRT_CURVATURE = "1.000000"
|
||||
CRT_warpX = "0.031000"
|
||||
CRT_warpY = "0.041000"
|
||||
CRT_cornersize = "0.010000"
|
||||
CRT_cornersmooth = "1000.000000"
|
||||
GLOW_WHITEPOINT = "0.500000"
|
||||
GLOW_ROLLOFF = "1.200000"
|
||||
BLOOM_STRENGTH = "0.100000"
|
||||
OUTPUT_GAMMA = "2.200000"
|
||||
CURVATURE = "0.000000"
|
||||
warpX = "0.031000"
|
||||
warpY = "0.041000"
|
||||
cornersize = "0.010000"
|
||||
cornersmooth = "1000.000000"
|
||||
noise_amt = "1.000000"
|
||||
shadowMask = "0.000000"
|
||||
maskDark = "0.500000"
|
||||
maskLight = "1.500000"
|
||||
linearize = "1.0"
|
||||
quality = "0.0"
|
Loading…
Reference in a new issue