From 0902b5b835d417904acbeb2e649ced31654e66c9 Mon Sep 17 00:00:00 2001 From: Valerie Date: Fri, 3 May 2024 23:58:07 -0400 Subject: [PATCH] created signal effect with NTSC emulation --- shaders/lang/en_US.lang | 4 ++++ shaders/module/signal.frag | 31 +++++++++++++++++++++++++++++++ shaders/shaders.properties | 2 +- shaders/var/scanline.glsl | 6 +++--- shaders/var/signal.glsl | 4 ++++ 5 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 shaders/module/signal.frag create mode 100644 shaders/var/signal.glsl diff --git a/shaders/lang/en_US.lang b/shaders/lang/en_US.lang index 5afec9b..2b4dfae 100644 --- a/shaders/lang/en_US.lang +++ b/shaders/lang/en_US.lang @@ -52,6 +52,10 @@ suffix.valBits=-bit screen.SCREEN=Screen +option.signal=Signal +value.signal.0=RGB (Off) +value.signal.1=NTSC + option.interlacing=Interlacing option.scanline=Scanlines diff --git a/shaders/module/signal.frag b/shaders/module/signal.frag new file mode 100644 index 0000000..4c69ef5 --- /dev/null +++ b/shaders/module/signal.frag @@ -0,0 +1,31 @@ + +#include "/var/signal.glsl" + +#define signal 0 // [0 1] + +vec3 ntsc(vec3 color) { + // convert to YIQ + float y = dot(color, vec3(0.299, 0.587, 0.114)); + float i = dot(color, vec3(0.596, -.274, -.322)); + float q = dot(color, vec3(0.211, -.523, 0.312)); + + // faux ntsc signal + float carrier = 6.283 * 3.570 * gl_FragCoord.x; + float phase = sin(carrier) * i + cos(carrier) * q; + float quad = cos(carrier) * i - sin(carrier) * q; + + // decode faux signal + i = quad * cos(carrier); + q = phase * sin(carrier); + + // convert back to RGB + vec3 yiqColor = vec3(y, i, q); + + vec3 outColor = vec3(0); + outColor.r = dot(yiqColor, vec3(1, 0.956, 0.619)); + outColor.g = dot(yiqColor, vec3(1, -.272, -.674)); + outColor.b = dot(yiqColor, vec3(1, -1.106, 1.703)); + + return outColor; +} + diff --git a/shaders/shaders.properties b/shaders/shaders.properties index eef852d..a18aeb7 100644 --- a/shaders/shaders.properties +++ b/shaders/shaders.properties @@ -20,7 +20,7 @@ screen.COLOR.columns=3 screen.COLOR=colorMode dithering colorDepth monoPalette hueBits satBits valBits # screen effects -screen.SCREEN=interlacing scanline aberration +screen.SCREEN=signal interlacing scanline aberration # console effects screen.CONSOLE.columns=1 diff --git a/shaders/var/scanline.glsl b/shaders/var/scanline.glsl index 9861367..4d87a7c 100644 --- a/shaders/var/scanline.glsl +++ b/shaders/var/scanline.glsl @@ -1,5 +1,5 @@ -#define SCANLINE_SOFT 1 -#define SCANLINE_HARD 2 -#define SCANLINE_STRETCH 3 +#define SCANLINE_SOFT 1 +#define SCANLINE_HARD 2 +#define SCANLINE_STRETCH 3 diff --git a/shaders/var/signal.glsl b/shaders/var/signal.glsl new file mode 100644 index 0000000..866ec50 --- /dev/null +++ b/shaders/var/signal.glsl @@ -0,0 +1,4 @@ + +#define SIGNAL_RGB 0 +#define SIGNAL_NTSC 1 +