2020-02-17 16:11:31 +11:00
|
|
|
#version 450
|
|
|
|
|
|
|
|
// NTSC-Adaptive
|
|
|
|
// based on Themaister's NTSC shader
|
|
|
|
|
2021-07-30 23:24:20 +10:00
|
|
|
|
2020-02-17 16:11:31 +11:00
|
|
|
layout(std140, set = 0, binding = 0) uniform UBO
|
|
|
|
{
|
|
|
|
mat4 MVP;
|
|
|
|
vec4 OutputSize;
|
|
|
|
vec4 OriginalSize;
|
|
|
|
vec4 SourceSize;
|
|
|
|
uint FrameCount;
|
2021-07-30 23:24:20 +10:00
|
|
|
float quality, ntsc_sat, cust_fringing, cust_artifacting, ntsc_bright, ntsc_scale, ntsc_fields, ntsc_phase;
|
2020-02-17 16:11:31 +11:00
|
|
|
} global;
|
|
|
|
|
2021-07-30 23:24:20 +10:00
|
|
|
#pragma parameter quality "NTSC Preset (Svideo=0 Composite=1 RF=2 Custom=-1)" 1.0 -1.0 2.0 1.0
|
|
|
|
#pragma parameter ntsc_fields "NTSC Merge Fields" 0.0 0.0 1.0 1.0
|
|
|
|
#pragma parameter ntsc_phase "NTSC Phase: Auto | 2 phase | 3 phase" 1.0 1.0 3.0 1.0
|
|
|
|
#pragma parameter ntsc_scale "NTSC Resolution Scaling" 1.0 0.20 3.0 0.05
|
|
|
|
#pragma parameter ntsc_sat "NTSC Color Saturation" 1.0 0.0 2.0 0.01
|
|
|
|
#pragma parameter ntsc_bright "NTSC Brightness" 1.0 0.0 1.5 0.01
|
|
|
|
#pragma parameter cust_fringing "NTSC Custom Fringing Value" 0.0 0.0 5.0 0.1
|
|
|
|
#pragma parameter cust_artifacting "NTSC Custom Artifacting Value" 0.0 0.0 5.0 0.1
|
2021-06-05 08:51:24 +10:00
|
|
|
|
|
|
|
#define PI 3.14159265
|
2020-02-17 16:11:31 +11:00
|
|
|
|
|
|
|
#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 vec2 pix_no;
|
2021-06-05 08:51:24 +10:00
|
|
|
layout(location = 2) out float phase;
|
|
|
|
layout(location = 3) out float BRIGHTNESS;
|
|
|
|
layout(location = 4) out float SATURATION;
|
|
|
|
layout(location = 5) out float FRINGING;
|
|
|
|
layout(location = 6) out float ARTIFACTING;
|
|
|
|
layout(location = 7) out float CHROMA_MOD_FREQ;
|
2021-07-30 23:24:20 +10:00
|
|
|
layout(location = 8) out float MERGE;
|
2020-02-17 16:11:31 +11:00
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2021-07-30 23:24:20 +10:00
|
|
|
float res = global.ntsc_scale;
|
|
|
|
float OriginalSize = global.OriginalSize.x;
|
2021-06-05 08:51:24 +10:00
|
|
|
gl_Position = global.MVP * Position;
|
|
|
|
vTexCoord = TexCoord;
|
2021-07-30 23:24:20 +10:00
|
|
|
if (res < 1.0) pix_no = TexCoord * global.SourceSize.xy * (res * global.OutputSize.xy / global.SourceSize.xy); else
|
|
|
|
pix_no = TexCoord * global.SourceSize.xy * ( global.OutputSize.xy / global.SourceSize.xy);
|
|
|
|
phase = (global.ntsc_phase < 1.5) ? ((OriginalSize > 300.0) ? 2.0 : 3.0) : ((global.ntsc_phase > 2.5) ? 3.0 : 2.0);
|
|
|
|
|
|
|
|
res = max(res, 1.0);
|
2021-06-05 08:51:24 +10:00
|
|
|
CHROMA_MOD_FREQ = (phase < 2.5) ? (4.0 * PI / 15.0) : (PI / 3.0);
|
2021-07-30 23:24:20 +10:00
|
|
|
ARTIFACTING = (global.quality > -0.5) ? global.quality * 0.5*(res+1.0) : global.cust_artifacting;
|
2021-06-05 08:51:24 +10:00
|
|
|
FRINGING = (global.quality > -0.5) ? global.quality : global.cust_fringing;
|
|
|
|
SATURATION = global.ntsc_sat;
|
2021-07-30 23:24:20 +10:00
|
|
|
BRIGHTNESS = global.ntsc_bright;
|
|
|
|
pix_no.x = pix_no.x * res;
|
|
|
|
|
|
|
|
MERGE = (int(global.quality) == 2 || phase < 2.5) ? 0.0 : 1.0;
|
|
|
|
MERGE = (int(global.quality) == -1) ? global.ntsc_fields : MERGE;
|
|
|
|
|
2020-02-17 16:11:31 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma stage fragment
|
|
|
|
layout(location = 0) in vec2 vTexCoord;
|
|
|
|
layout(location = 1) in vec2 pix_no;
|
2021-06-05 08:51:24 +10:00
|
|
|
layout(location = 2) in float phase;
|
|
|
|
layout(location = 3) in float BRIGHTNESS;
|
|
|
|
layout(location = 4) in float SATURATION;
|
|
|
|
layout(location = 5) in float FRINGING;
|
|
|
|
layout(location = 6) in float ARTIFACTING;
|
|
|
|
layout(location = 7) in float CHROMA_MOD_FREQ;
|
2021-07-30 23:24:20 +10:00
|
|
|
layout(location = 8) in float MERGE;
|
2020-02-17 16:11:31 +11:00
|
|
|
layout(location = 0) out vec4 FragColor;
|
|
|
|
layout(set = 0, binding = 2) uniform sampler2D Source;
|
|
|
|
|
2020-02-18 04:44:18 +11:00
|
|
|
#define mix_mat mat3(BRIGHTNESS, FRINGING, FRINGING, ARTIFACTING, 2.0 * SATURATION, 0.0, ARTIFACTING, 0.0, 2.0 * SATURATION)
|
2020-02-17 16:11:31 +11:00
|
|
|
|
|
|
|
const mat3 yiq2rgb_mat = mat3(
|
|
|
|
1.0, 0.956, 0.6210,
|
|
|
|
1.0, -0.2720, -0.6474,
|
|
|
|
1.0, -1.1060, 1.7046);
|
|
|
|
|
|
|
|
vec3 yiq2rgb(vec3 yiq)
|
|
|
|
{
|
|
|
|
return yiq * yiq2rgb_mat;
|
|
|
|
}
|
|
|
|
|
|
|
|
const mat3 yiq_mat = mat3(
|
|
|
|
0.2989, 0.5870, 0.1140,
|
|
|
|
0.5959, -0.2744, -0.3216,
|
|
|
|
0.2115, -0.5229, 0.3114
|
|
|
|
);
|
|
|
|
|
|
|
|
vec3 rgb2yiq(vec3 col)
|
|
|
|
{
|
|
|
|
return col * yiq_mat;
|
|
|
|
}
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
vec3 col = texture(Source, vTexCoord).rgb;
|
|
|
|
vec3 yiq = rgb2yiq(col);
|
2021-07-30 23:24:20 +10:00
|
|
|
vec3 yiq2 = yiq;
|
2020-02-17 16:11:31 +11:00
|
|
|
|
2021-07-30 23:24:20 +10:00
|
|
|
float mod1 = 2.0;
|
|
|
|
float mod2 = 3.0;
|
2020-02-17 16:11:31 +11:00
|
|
|
|
2021-07-30 23:24:20 +10:00
|
|
|
if (MERGE > 0.5)
|
|
|
|
{
|
|
|
|
float chroma_phase2 = (phase < 2.5) ? PI * (mod(pix_no.y, mod1) + mod(global.FrameCount+1, 2.)) : 0.6667 * PI * (mod(pix_no.y, mod2) + mod(global.FrameCount+1, 2.));
|
|
|
|
float mod_phase2 = chroma_phase2 + pix_no.x * CHROMA_MOD_FREQ;
|
|
|
|
float i_mod2 = cos(mod_phase2);
|
|
|
|
float q_mod2 = sin(mod_phase2);
|
|
|
|
yiq2.yz *= vec2(i_mod2, q_mod2); // Modulate.
|
|
|
|
yiq2 *= mix_mat; // Cross-talk.
|
|
|
|
yiq2.yz *= vec2(i_mod2, q_mod2); // Demodulate.
|
|
|
|
}
|
|
|
|
|
|
|
|
float chroma_phase = (phase < 2.5) ? PI * (mod(pix_no.y, mod1) + mod(global.FrameCount, 2.)) : 0.6667 * PI * (mod(pix_no.y, mod2) + mod(global.FrameCount, 2.));
|
2020-02-17 16:11:31 +11:00
|
|
|
float mod_phase = chroma_phase + pix_no.x * CHROMA_MOD_FREQ;
|
|
|
|
|
|
|
|
float i_mod = cos(mod_phase);
|
|
|
|
float q_mod = sin(mod_phase);
|
|
|
|
|
|
|
|
yiq.yz *= vec2(i_mod, q_mod); // Modulate.
|
|
|
|
yiq *= mix_mat; // Cross-talk.
|
|
|
|
yiq.yz *= vec2(i_mod, q_mod); // Demodulate.
|
2021-07-30 23:24:20 +10:00
|
|
|
|
|
|
|
yiq = (MERGE < 0.5) ? yiq : 0.5*(yiq+yiq2);
|
|
|
|
|
2020-02-17 16:11:31 +11:00
|
|
|
FragColor = vec4(yiq, 1.0);
|
2020-02-18 04:44:18 +11:00
|
|
|
}
|