From 97106f21859fa1da843fb7f8ce7b5fad81689ab3 Mon Sep 17 00:00:00 2001 From: hunterk Date: Wed, 13 Jul 2016 13:59:27 -0500 Subject: [PATCH] fix NTSC shader --- ntsc/shaders/ntsc-gauss-pass.slang | 14 +++++++++----- ntsc/shaders/ntsc-pass1-composite-2phase.slang | 15 ++++++++++++++- ntsc/shaders/ntsc-pass1-composite-3phase.slang | 14 +++++++++++++- ntsc/shaders/ntsc-pass1-encode-demodulate.inc | 4 ++-- ntsc/shaders/ntsc-pass1-svideo-2phase.slang | 14 +++++++++++++- ntsc/shaders/ntsc-pass1-svideo-3phase.slang | 14 +++++++++++++- ntsc/shaders/ntsc-pass1-vertex.inc | 13 ++----------- ntsc/shaders/ntsc-pass2-2phase-gamma.slang | 17 ++++++++++++++--- ntsc/shaders/ntsc-pass2-2phase-linear.slang | 17 ++++++++++++++--- ntsc/shaders/ntsc-pass2-2phase.slang | 17 ++++++++++++++--- ntsc/shaders/ntsc-pass2-3phase-gamma.slang | 17 ++++++++++++++--- ntsc/shaders/ntsc-pass2-3phase-linear.slang | 17 ++++++++++++++--- ntsc/shaders/ntsc-pass2-3phase.slang | 17 ++++++++++++++--- ntsc/shaders/ntsc-pass2-vertex.inc | 12 +----------- ntsc/shaders/ntsc-stock.slang | 3 ++- 15 files changed, 153 insertions(+), 52 deletions(-) diff --git a/ntsc/shaders/ntsc-gauss-pass.slang b/ntsc/shaders/ntsc-gauss-pass.slang index c3953a0..42ed7fb 100644 --- a/ntsc/shaders/ntsc-gauss-pass.slang +++ b/ntsc/shaders/ntsc-gauss-pass.slang @@ -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); } diff --git a/ntsc/shaders/ntsc-pass1-composite-2phase.slang b/ntsc/shaders/ntsc-pass1-composite-2phase.slang index b0ac7fe..523725a 100644 --- a/ntsc/shaders/ntsc-pass1-composite-2phase.slang +++ b/ntsc/shaders/ntsc-pass1-composite-2phase.slang @@ -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; diff --git a/ntsc/shaders/ntsc-pass1-composite-3phase.slang b/ntsc/shaders/ntsc-pass1-composite-3phase.slang index 8104614..b0826d0 100644 --- a/ntsc/shaders/ntsc-pass1-composite-3phase.slang +++ b/ntsc/shaders/ntsc-pass1-composite-3phase.slang @@ -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; diff --git a/ntsc/shaders/ntsc-pass1-encode-demodulate.inc b/ntsc/shaders/ntsc-pass1-encode-demodulate.inc index 145a0a7..fabc7b7 100644 --- a/ntsc/shaders/ntsc-pass1-encode-demodulate.inc +++ b/ntsc/shaders/ntsc-pass1-encode-demodulate.inc @@ -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); diff --git a/ntsc/shaders/ntsc-pass1-svideo-2phase.slang b/ntsc/shaders/ntsc-pass1-svideo-2phase.slang index a0ffcce..9f12940 100644 --- a/ntsc/shaders/ntsc-pass1-svideo-2phase.slang +++ b/ntsc/shaders/ntsc-pass1-svideo-2phase.slang @@ -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; diff --git a/ntsc/shaders/ntsc-pass1-svideo-3phase.slang b/ntsc/shaders/ntsc-pass1-svideo-3phase.slang index 34c06d4..39b6f6e 100644 --- a/ntsc/shaders/ntsc-pass1-svideo-3phase.slang +++ b/ntsc/shaders/ntsc-pass1-svideo-3phase.slang @@ -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; diff --git a/ntsc/shaders/ntsc-pass1-vertex.inc b/ntsc/shaders/ntsc-pass1-vertex.inc index 32532dc..0262e9f 100644 --- a/ntsc/shaders/ntsc-pass1-vertex.inc +++ b/ntsc/shaders/ntsc-pass1-vertex.inc @@ -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); } diff --git a/ntsc/shaders/ntsc-pass2-2phase-gamma.slang b/ntsc/shaders/ntsc-pass2-2phase-gamma.slang index fd25379..5bef5c8 100644 --- a/ntsc/shaders/ntsc-pass2-2phase-gamma.slang +++ b/ntsc/shaders/ntsc-pass2-2phase-gamma.slang @@ -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); } diff --git a/ntsc/shaders/ntsc-pass2-2phase-linear.slang b/ntsc/shaders/ntsc-pass2-2phase-linear.slang index 1da05ef..506fac2 100644 --- a/ntsc/shaders/ntsc-pass2-2phase-linear.slang +++ b/ntsc/shaders/ntsc-pass2-2phase-linear.slang @@ -1,11 +1,22 @@ -#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; @@ -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); } diff --git a/ntsc/shaders/ntsc-pass2-2phase.slang b/ntsc/shaders/ntsc-pass2-2phase.slang index ab2f31e..edf981e 100644 --- a/ntsc/shaders/ntsc-pass2-2phase.slang +++ b/ntsc/shaders/ntsc-pass2-2phase.slang @@ -1,9 +1,20 @@ -#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; @@ -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); } diff --git a/ntsc/shaders/ntsc-pass2-3phase-gamma.slang b/ntsc/shaders/ntsc-pass2-3phase-gamma.slang index 3aec88c..9e5872c 100644 --- a/ntsc/shaders/ntsc-pass2-3phase-gamma.slang +++ b/ntsc/shaders/ntsc-pass2-3phase-gamma.slang @@ -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); } diff --git a/ntsc/shaders/ntsc-pass2-3phase-linear.slang b/ntsc/shaders/ntsc-pass2-3phase-linear.slang index 3a68607..e277c05 100644 --- a/ntsc/shaders/ntsc-pass2-3phase-linear.slang +++ b/ntsc/shaders/ntsc-pass2-3phase-linear.slang @@ -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); } diff --git a/ntsc/shaders/ntsc-pass2-3phase.slang b/ntsc/shaders/ntsc-pass2-3phase.slang index 0116246..afbe993 100644 --- a/ntsc/shaders/ntsc-pass2-3phase.slang +++ b/ntsc/shaders/ntsc-pass2-3phase.slang @@ -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); } diff --git a/ntsc/shaders/ntsc-pass2-vertex.inc b/ntsc/shaders/ntsc-pass2-vertex.inc index f45dba2..738a495 100644 --- a/ntsc/shaders/ntsc-pass2-vertex.inc +++ b/ntsc/shaders/ntsc-pass2-vertex.inc @@ -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; @@ -17,4 +7,4 @@ void main() { gl_Position = global.MVP * Position; vTexCoord = TexCoord - vec2(0.5 / global.SourceSize.x, 0.0); // Compensate for decimate-by-2. -} +} \ No newline at end of file diff --git a/ntsc/shaders/ntsc-stock.slang b/ntsc/shaders/ntsc-stock.slang index bd26cc9..86730dc 100644 --- a/ntsc/shaders/ntsc-stock.slang +++ b/ntsc/shaders/ntsc-stock.slang @@ -27,4 +27,5 @@ layout(set = 0, binding = 2) uniform sampler2D Source; void main() { -FragCoord = texture(Source, vTexCoord).rgba; +FragColor = texture(Source, vTexCoord).rgba; +} \ No newline at end of file