2016-07-16 09:28:48 +10:00
|
|
|
#version 450
|
|
|
|
|
2016-08-03 15:24:41 +10:00
|
|
|
layout(push_constant) uniform Push
|
|
|
|
{
|
|
|
|
float BRIGHT_BOOST;
|
|
|
|
float DILATION;
|
|
|
|
float GAMMA_INPUT;
|
|
|
|
float GAMMA_OUTPUT;
|
|
|
|
float MASK_SIZE;
|
|
|
|
float MASK_STAGGER;
|
|
|
|
float MASK_STRENGTH;
|
|
|
|
float MASK_DOT_HEIGHT;
|
|
|
|
float MASK_DOT_WIDTH;
|
|
|
|
float SCANLINE_CUTOFF;
|
|
|
|
float SCANLINE_BEAM_WIDTH_MAX;
|
|
|
|
float SCANLINE_BEAM_WIDTH_MIN;
|
|
|
|
float SCANLINE_BRIGHT_MAX;
|
|
|
|
float SCANLINE_BRIGHT_MIN;
|
|
|
|
float SCANLINE_STRENGTH;
|
|
|
|
float SHARPNESS_H;
|
|
|
|
float SHARPNESS_V;
|
|
|
|
} param;
|
|
|
|
|
|
|
|
#pragma parameter SHARPNESS_H "Sharpness Horizontal" 0.5 0.0 1.0 0.05
|
|
|
|
#pragma parameter SHARPNESS_V "Sharpness Vertical" 1.0 0.0 1.0 0.05
|
|
|
|
#pragma parameter MASK_STRENGTH "Mask Strength" 0.3 0.0 1.0 0.01
|
|
|
|
#pragma parameter MASK_DOT_WIDTH "Mask Dot Width" 1.0 1.0 100.0 1.0
|
|
|
|
#pragma parameter MASK_DOT_HEIGHT "Mask Dot Height" 1.0 1.0 100.0 1.0
|
|
|
|
#pragma parameter MASK_STAGGER "Mask Stagger" 0.0 0.0 100.0 1.0
|
|
|
|
#pragma parameter MASK_SIZE "Mask Size" 1.0 1.0 100.0 1.0
|
|
|
|
#pragma parameter SCANLINE_STRENGTH "Scanline Strength" 1.0 0.0 1.0 0.05
|
|
|
|
#pragma parameter SCANLINE_BEAM_WIDTH_MIN "Scanline Beam Width Min." 1.5 0.5 5.0 0.5
|
|
|
|
#pragma parameter SCANLINE_BEAM_WIDTH_MAX "Scanline Beam Width Max." 1.5 0.5 5.0 0.5
|
|
|
|
#pragma parameter SCANLINE_BRIGHT_MIN "Scanline Brightness Min." 0.35 0.0 1.0 0.05
|
|
|
|
#pragma parameter SCANLINE_BRIGHT_MAX "Scanline Brightness Max." 0.65 0.0 1.0 0.05
|
|
|
|
#pragma parameter SCANLINE_CUTOFF "Scanline Cutoff" 400.0 1.0 1000.0 1.0
|
|
|
|
#pragma parameter GAMMA_INPUT "Gamma Input" 2.0 0.1 5.0 0.1
|
|
|
|
#pragma parameter GAMMA_OUTPUT "Gamma Output" 1.8 0.1 5.0 0.1
|
|
|
|
#pragma parameter BRIGHT_BOOST "Brightness Boost" 1.2 1.0 2.0 0.01
|
|
|
|
#pragma parameter DILATION "Dilation" 1.0 0.0 1.0 1.0
|
|
|
|
|
2016-07-16 09:28:48 +10:00
|
|
|
layout(std140, set = 0, binding = 0) uniform UBO
|
|
|
|
{
|
2016-08-03 15:24:41 +10:00
|
|
|
mat4 MVP;
|
|
|
|
vec4 OutputSize;
|
|
|
|
vec4 OriginalSize;
|
|
|
|
vec4 SourceSize;
|
2016-07-16 09:28:48 +10:00
|
|
|
} global;
|
|
|
|
|
|
|
|
#pragma stage vertex
|
|
|
|
layout(location = 0) in vec4 Position;
|
|
|
|
layout(location = 1) in vec2 TexCoord;
|
|
|
|
layout(location = 0) out vec2 vTexCoord;
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2016-08-03 15:24:41 +10:00
|
|
|
gl_Position = global.MVP * Position;
|
|
|
|
vTexCoord = TexCoord;
|
2016-07-16 09:28:48 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
CRT Shader by EasyMode
|
|
|
|
License: GPL
|
|
|
|
|
|
|
|
A flat CRT shader ideally for 1080p or higher displays.
|
|
|
|
|
|
|
|
Recommended Settings:
|
|
|
|
|
|
|
|
Video
|
2016-07-22 01:10:09 +10:00
|
|
|
- Aspect Ratio: 4:3
|
2016-07-16 09:28:48 +10:00
|
|
|
- Integer Scale: Off
|
|
|
|
|
|
|
|
Shader
|
|
|
|
- Filter: Nearest
|
2016-07-22 01:10:09 +10:00
|
|
|
- Scale: Don't Care
|
2016-07-16 09:28:48 +10:00
|
|
|
|
|
|
|
Example RGB Mask Parameter Settings:
|
|
|
|
|
|
|
|
Aperture Grille (Default)
|
2016-07-22 01:10:09 +10:00
|
|
|
- Dot Width: 1
|
2016-07-16 09:28:48 +10:00
|
|
|
- Dot Height: 1
|
2016-07-22 01:10:09 +10:00
|
|
|
- Stagger: 0
|
2016-07-16 09:28:48 +10:00
|
|
|
|
|
|
|
Lottes' Shadow Mask
|
2016-07-22 01:10:09 +10:00
|
|
|
- Dot Width: 2
|
2016-07-16 09:28:48 +10:00
|
|
|
- Dot Height: 1
|
2016-07-22 01:10:09 +10:00
|
|
|
- Stagger: 3
|
2016-07-16 09:28:48 +10:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma stage fragment
|
2016-07-22 01:10:09 +10:00
|
|
|
layout(location = 0) in vec2 vTexCoord;
|
2016-07-16 09:28:48 +10:00
|
|
|
layout(location = 0) out vec4 FragColor;
|
|
|
|
layout(set = 0, binding = 2) uniform sampler2D Source;
|
|
|
|
|
|
|
|
#define FIX(c) max(abs(c), 1e-5)
|
|
|
|
#define PI 3.141592653589
|
|
|
|
|
|
|
|
#define TEX2D(c) dilate(texture(Source, c))
|
|
|
|
|
|
|
|
// Set to 0 to use linear filter and gain speed
|
|
|
|
#define ENABLE_LANCZOS 1
|
|
|
|
|
|
|
|
vec4 dilate(vec4 col)
|
|
|
|
{
|
2016-08-03 15:24:41 +10:00
|
|
|
vec4 x = mix(vec4(1.0), col, param.DILATION);
|
2016-07-16 09:28:48 +10:00
|
|
|
|
|
|
|
return col * x;
|
|
|
|
}
|
|
|
|
|
|
|
|
float curve_distance(float x, float sharp)
|
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
|
|
|
apply half-circle s-curve to distance for sharper (more pixelated) interpolation
|
|
|
|
single line formula for Graph Toy:
|
|
|
|
0.5 - sqrt(0.25 - (x - step(0.5, x)) * (x - step(0.5, x))) * sign(0.5 - x)
|
|
|
|
*/
|
|
|
|
|
|
|
|
float x_step = step(0.5, x);
|
|
|
|
float curve = 0.5 - sqrt(0.25 - (x - x_step) * (x - x_step)) * sign(0.5 - x);
|
|
|
|
|
|
|
|
return mix(x, curve, sharp);
|
|
|
|
}
|
|
|
|
|
2016-07-22 01:10:09 +10:00
|
|
|
mat4x4 get_color_matrix(vec2 co, vec2 dx)
|
2016-07-16 09:28:48 +10:00
|
|
|
{
|
|
|
|
return mat4x4(TEX2D(co - dx), TEX2D(co), TEX2D(co + dx), TEX2D(co + 2.0 * dx));
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3 filter_lanczos(vec4 coeffs, mat4x4 color_matrix)
|
|
|
|
{
|
2016-07-26 03:31:39 +10:00
|
|
|
vec4 col = color_matrix * coeffs;
|
2016-07-16 09:28:48 +10:00
|
|
|
vec4 sample_min = min(color_matrix[1], color_matrix[2]);
|
|
|
|
vec4 sample_max = max(color_matrix[1], color_matrix[2]);
|
|
|
|
|
|
|
|
col = clamp(col, sample_min, sample_max);
|
|
|
|
|
|
|
|
return col.rgb;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* main_fragment */
|
|
|
|
void main()
|
|
|
|
{
|
2016-07-22 01:10:09 +10:00
|
|
|
vec2 dx = vec2(global.SourceSize.z, 0.0);
|
|
|
|
vec2 dy = vec2(0.0, global.SourceSize.w);
|
2016-07-16 09:45:50 +10:00
|
|
|
vec2 pix_co = vTexCoord * global.SourceSize.xy - vec2(0.5, 0.5);
|
2016-07-22 01:10:09 +10:00
|
|
|
vec2 tex_co = (floor(pix_co) + vec2(0.5, 0.5)) * global.SourceSize.zw;
|
2016-07-16 09:28:48 +10:00
|
|
|
vec2 dist = fract(pix_co);
|
|
|
|
float curve_x;
|
|
|
|
vec3 col, col2;
|
|
|
|
|
|
|
|
#if ENABLE_LANCZOS
|
2016-08-03 15:24:41 +10:00
|
|
|
curve_x = curve_distance(dist.x, param.SHARPNESS_H * param.SHARPNESS_H);
|
2016-07-16 09:28:48 +10:00
|
|
|
|
|
|
|
vec4 coeffs = PI * vec4(1.0 + curve_x, curve_x, 1.0 - curve_x, 2.0 - curve_x);
|
|
|
|
|
|
|
|
coeffs = FIX(coeffs);
|
2016-07-22 01:10:09 +10:00
|
|
|
coeffs = 2.0 * sin(coeffs) * sin(coeffs * 0.5) / (coeffs * coeffs);
|
2016-07-16 09:28:48 +10:00
|
|
|
coeffs /= dot(coeffs, vec4(1.0));
|
|
|
|
|
2016-07-22 01:10:09 +10:00
|
|
|
col = filter_lanczos(coeffs, get_color_matrix(tex_co, dx));
|
|
|
|
col2 = filter_lanczos(coeffs, get_color_matrix(tex_co + dy, dx));
|
2016-07-16 09:28:48 +10:00
|
|
|
#else
|
2016-08-03 15:24:41 +10:00
|
|
|
curve_x = curve_distance(dist.x, param.SHARPNESS_H);
|
2016-07-16 09:28:48 +10:00
|
|
|
|
|
|
|
col = mix(TEX2D(tex_co).rgb, TEX2D(tex_co + dx).rgb, curve_x);
|
|
|
|
col2 = mix(TEX2D(tex_co + dy).rgb, TEX2D(tex_co + dx + dy).rgb, curve_x);
|
|
|
|
#endif
|
|
|
|
|
2016-08-03 15:24:41 +10:00
|
|
|
col = mix(col, col2, curve_distance(dist.y, param.SHARPNESS_V));
|
|
|
|
col = pow(col, vec3(param.GAMMA_INPUT / (param.DILATION + 1.0)));
|
2016-07-16 09:28:48 +10:00
|
|
|
|
|
|
|
float luma = dot(vec3(0.2126, 0.7152, 0.0722), col);
|
2016-07-22 01:10:09 +10:00
|
|
|
float bright = (max(col.r, max(col.g, col.b)) + luma) * 0.5;
|
2016-08-03 15:24:41 +10:00
|
|
|
float scan_bright = clamp(bright, param.SCANLINE_BRIGHT_MIN, param.SCANLINE_BRIGHT_MAX);
|
|
|
|
float scan_beam = clamp(bright * param.SCANLINE_BEAM_WIDTH_MAX, param.SCANLINE_BEAM_WIDTH_MIN, param.SCANLINE_BEAM_WIDTH_MAX);
|
|
|
|
float scan_weight = 1.0 - pow(cos(vTexCoord.y * 2.0 * PI * global.SourceSize.y) * 0.5 + 0.5, scan_beam) * param.SCANLINE_STRENGTH;
|
2016-07-16 09:28:48 +10:00
|
|
|
|
2016-08-03 15:24:41 +10:00
|
|
|
float mask = 1.0 - param.MASK_STRENGTH;
|
|
|
|
vec2 mod_fac = floor(vTexCoord * global.OutputSize.xy * global.SourceSize.xy / (global.SourceSize.xy * vec2(param.MASK_SIZE, param.MASK_DOT_HEIGHT * param.MASK_SIZE)));
|
|
|
|
int dot_no = int(mod((mod_fac.x + mod(mod_fac.y, 2.0) * param.MASK_STAGGER) / param.MASK_DOT_WIDTH, 3.0));
|
2016-07-16 09:28:48 +10:00
|
|
|
vec3 mask_weight;
|
|
|
|
|
2016-07-22 01:10:09 +10:00
|
|
|
if (dot_no == 0) mask_weight = vec3(1.0, mask, mask);
|
|
|
|
else if (dot_no == 1) mask_weight = vec3(mask, 1.0, mask);
|
2016-07-16 09:28:48 +10:00
|
|
|
else mask_weight = vec3(mask, mask, 1.0);
|
|
|
|
|
2016-08-03 15:24:41 +10:00
|
|
|
if (global.SourceSize.y >= param.SCANLINE_CUTOFF)
|
2016-07-22 01:10:09 +10:00
|
|
|
scan_weight = 1.0;
|
2016-07-16 09:28:48 +10:00
|
|
|
|
|
|
|
col2 = col.rgb;
|
|
|
|
col *= vec3(scan_weight);
|
|
|
|
col = mix(col, col2, scan_bright);
|
|
|
|
col *= mask_weight;
|
2016-08-03 15:24:41 +10:00
|
|
|
col = pow(col, vec3(1.0 / param.GAMMA_OUTPUT));
|
2016-07-16 09:28:48 +10:00
|
|
|
|
2016-08-03 15:24:41 +10:00
|
|
|
FragColor = vec4(col * param.BRIGHT_BOOST, 1.0);
|
2016-07-16 09:28:48 +10:00
|
|
|
}
|