fix NTSC shader

This commit is contained in:
hunterk 2016-07-13 13:59:27 -05:00
parent 08433c4564
commit 97106f2185
15 changed files with 153 additions and 52 deletions

View file

@ -16,21 +16,25 @@ layout(std140, set = 0, binding = 0) uniform UBO
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
layout(location = 1) out vec2 one;
layout(location = 2) out vec2 pix_no;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
vec2 pix_no = TexCoord * global.SourceSize.xy;
vec2 one = 1.0 / global.SourceSize.xy;
pix_no = TexCoord * global.SourceSize.xy;
one = 1.0 / global.SourceSize.xy;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in vec2 one;
layout(location = 2) in vec2 pix_no;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
#define TEX(off) pow(texture(Source, vTexCoord + vec2(0.0, (off) * vertex.one.y)).rgb, vec3(NTSC_CRT_GAMMA))
#define TEX(off) pow(texture(Source, vTexCoord + vec2(0.0, (off) * one.y)).rgb, vec3(NTSC_CRT_GAMMA))
void main()
@ -41,7 +45,7 @@ void main()
vec3 frame3 = TEX(1.0);
vec3 frame4 = TEX(2.0);
float offset_dist = fract(vertex.pix_no.y) - 0.5;
float offset_dist = fract(pix_no.y) - 0.5;
float dist0 = 2.0 + offset_dist;
float dist1 = 1.0 + offset_dist;
float dist2 = 0.0 + offset_dist;
@ -54,5 +58,5 @@ void main()
scanline += frame3 * exp(-5.0 * dist3 * dist3);
scanline += frame4 * exp(-5.0 * dist4 * dist4);
FragCoord = vec4(pow(1.15 * scanline, vec3(1.0 / NTSC_DISPLAY_GAMMA)), 1.0);
FragColor = vec4(pow(1.15 * scanline, vec3(1.0 / NTSC_DISPLAY_GAMMA)), 1.0);
}

View file

@ -1,11 +1,24 @@
#include "ntsc-pass1-vertex.inc"
#version 450
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
uint FrameCount;
} global;
#define TWO_PHASE
#define COMPOSITE
#include "ntsc-param.inc"
#include "ntsc-rgbyuv.inc"
#include "ntsc-pass1-vertex.inc"
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in vec2 pix_no;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;

View file

@ -1,11 +1,23 @@
#include "ntsc-pass1-vertex.inc"
#version 450
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
uint FrameCount;
} global;
#define THREE_PHASE
#define COMPOSITE
#include "ntsc-param.inc"
#include "ntsc-rgbyuv.inc"
#include "ntsc-pass1-vertex.inc"
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in vec2 pix_no;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;

View file

@ -2,7 +2,7 @@ vec3 col = texture(Source, vTexCoord).rgb;
vec3 yiq = rgb2yiq(col);
#if defined(TWO_PHASE)
float chroma_phase = PI * (mod(vertex.pix_no.y, 2.0) + global.FrameCount);
float chroma_phase = PI * (mod(pix_no.y, 2.0) + global.FrameCount);
#elif defined(THREE_PHASE)
float chroma_phase = 0.6667 * PI * (mod(pix_no.y, 3.0) + global.FrameCount);
#endif
@ -15,5 +15,5 @@ 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.
FragCoord = vec4(yiq, 1.0);
FragColor = vec4(yiq, 1.0);

View file

@ -1,11 +1,23 @@
#include "ntsc-pass1-vertex.inc"
#version 450
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
uint FrameCount;
} global;
#define TWO_PHASE
#define SVIDEO
#include "ntsc-param.inc"
#include "ntsc-rgbyuv.inc"
#include "ntsc-pass1-vertex.inc"
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in vec2 pix_no;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;

View file

@ -1,11 +1,23 @@
#include "ntsc-pass1-vertex.inc"
#version 450
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
uint FrameCount;
} global;
#define THREE_PHASE
#define SVIDEO
#include "ntsc-param.inc"
#include "ntsc-rgbyuv.inc"
#include "ntsc-pass1-vertex.inc"
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in vec2 pix_no;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;

View file

@ -1,21 +1,12 @@
#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;
layout(location = 1) out vec2 pix_no;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
vec2 pix_no = TexCoord * global.SourceSize.xy * (global.OutputSize / global.SourceSize.zw);
pix_no = TexCoord * global.SourceSize.xy * (global.OutputSize.xy / global.SourceSize.xy);
}

View file

@ -1,6 +1,15 @@
#include "ntsc-pass2-vertex.inc"
#include "ntsc-decode-filter-2phase.inc"
#version 450
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global;
#include "ntsc-rgbyuv.inc"
#include "ntsc-decode-filter-2phase.inc"
#define fetch_offset(offset, one_x) \
texture(Source, vTexCoord + vec2((offset) * (one_x), 0.0)).xyz
@ -8,6 +17,8 @@
#define NTSC_CRT_GAMMA 2.5
#define NTSC_MONITOR_GAMMA 2.0
#include "ntsc-pass2-vertex.inc"
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
@ -17,5 +28,5 @@ void main()
{
#include "ntsc-pass2-decode.inc"
vec3 rgb = yiq2rgb(signal);
return vec4(pow(rgb, NTSC_CRT_GAMMA / NTSC_MONITOR_GAMMA), 1.0);
FragColor = vec4(pow(rgb, vec3(NTSC_CRT_GAMMA / NTSC_MONITOR_GAMMA)), 1.0);
}

View file

@ -1,12 +1,23 @@
#include "ntsc-pass2-vertex.inc"
#include "ntsc-decode-filter-2phase.inc"
#version 450
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global;
#include "ntsc-rgbyuv.inc"
#include "ntsc-decode-filter-2phase.inc"
#define fetch_offset(offset, one_x) \
texture(Source, vTexCoord + vec2((offset) * (one_x), 0.0)).xyz
#define NTSC_CRT_GAMMA 2.4
#include "ntsc-pass2-vertex.inc"
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
@ -16,5 +27,5 @@ void main()
{
#include "ntsc-pass2-decode.inc"
vec3 rgb = yiq2rgb(signal);
return vec4(pow(rgb, NTSC_CRT_GAMMA), 1.0);
FragColor = vec4(pow(rgb, vec3(NTSC_CRT_GAMMA)), 1.0);
}

View file

@ -1,10 +1,21 @@
#include "ntsc-pass2-vertex.inc"
#include "ntsc-decode-filter-2phase.inc"
#version 450
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global;
#include "ntsc-rgbyuv.inc"
#include "ntsc-decode-filter-2phase.inc"
#define fetch_offset(offset, one_x) \
texture(Source, vTexCoord + vec2((offset) * (one_x), 0.0)).xyz
#include "ntsc-pass2-vertex.inc"
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
@ -14,5 +25,5 @@ void main()
{
#include "ntsc-pass2-decode.inc"
vec3 rgb = yiq2rgb(signal);
return vec4(rgb, 1.0);
FragColor = vec4(rgb, 1.0);
}

View file

@ -1,6 +1,15 @@
#include "ntsc-pass2-vertex.inc"
#include "ntsc-decode-filter-3phase.inc"
#version 450
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global;
#include "ntsc-rgbyuv.inc"
#include "ntsc-decode-filter-3phase.inc"
#define fetch_offset(offset, one_x) \
texture(Source, vTexCoord + vec2((offset) * (one_x), 0.0)).xyz
@ -8,6 +17,8 @@
#define NTSC_CRT_GAMMA 2.5
#define NTSC_MONITOR_GAMMA 2.0
#include "ntsc-pass2-vertex.inc"
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
@ -17,5 +28,5 @@ void main()
{
#include "ntsc-pass2-decode.inc"
vec3 rgb = yiq2rgb(signal);
return vec4(pow(rgb, NTSC_CRT_GAMMA / NTSC_MONITOR_GAMMA), 1.0);
FragColor = vec4(pow(rgb, vec3(NTSC_CRT_GAMMA / NTSC_MONITOR_GAMMA)), 1.0);
}

View file

@ -1,12 +1,23 @@
#include "ntsc-pass2-vertex.inc"
#include "ntsc-decode-filter-3phase.inc"
#version 450
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global;
#include "ntsc-rgbyuv.inc"
#include "ntsc-decode-filter-3phase.inc"
#define fetch_offset(offset, one_x) \
texture(Source, vTexCoord + vec2((offset) * (one_x), 0.0)).xyz
#define NTSC_CRT_GAMMA 2.4
#include "ntsc-pass2-vertex.inc"
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
@ -16,5 +27,5 @@ void main()
{
#include "ntsc-pass2-decode.inc"
vec3 rgb = yiq2rgb(signal);
return vec4(pow(rgb, NTSC_CRT_GAMMA), 1.0);
FragColor = vec4(pow(rgb, vec3(NTSC_CRT_GAMMA)), 1.0);
}

View file

@ -1,10 +1,21 @@
#include "ntsc-pass2-vertex.inc"
#include "ntsc-decode-filter-3phase.inc"
#version 450
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global;
#include "ntsc-rgbyuv.inc"
#include "ntsc-decode-filter-3phase.inc"
#define fetch_offset(offset, one_x) \
texture(Source, vTexCoord + vec2((offset) * (one_x), 0.0)).xyz
#include "ntsc-pass2-vertex.inc"
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
@ -14,5 +25,5 @@ void main()
{
#include "ntsc-pass2-decode.inc"
vec3 rgb = yiq2rgb(signal);
return vec4(rgb, 1.0);
FragColor = vec4(rgb, 1.0);
}

View file

@ -1,13 +1,3 @@
#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;

View file

@ -27,4 +27,5 @@ layout(set = 0, binding = 2) uniform sampler2D Source;
void main()
{
FragCoord = texture(Source, vTexCoord).rgba;
FragColor = texture(Source, vTexCoord).rgba;
}