Compare commits

..

2 commits

7 changed files with 75 additions and 11 deletions

View file

@ -13,23 +13,34 @@ uniform float viewWidth;
#include "/module/aberration.frag"
#include "/module/horizontal_blur.frag"
#include "/module/scanline.frag"
#include "/module/signal.frag"
void main() {
vec3 color;
// software post-processing effects
#ifdef hBlur
color = hblur();
#else
color = texture2D(gcolor, texcoord).rgb;
#endif
#ifdef aberration
color.rb = aberrate().rb;
#endif
#if scanline > 0
color = scanlines(color);
#endif
// hardware post-processing effects
#if signal == SIGNAL_NTSC
color = ntsc(color);
#endif
// physical post-processing effects
#ifdef aberration
color.rb = aberrate(color).rb;
#endif
gl_FragData[0] = vec4(color, 1);
}

View file

@ -52,6 +52,14 @@ suffix.valBits=-bit
screen.SCREEN=Screen
option.signal=Signal
value.signal.0=RGB (Off)
value.signal.1=NTSC
option.wire=Connector
value.wire.0=Composite
value.wire.1=S-Video
option.interlacing=Interlacing
option.scanline=Scanlines

View file

@ -1,10 +1,10 @@
vec2 caOffset = vec2(2 * pixelSize / viewWidth, 0);
vec3 aberrate() {
vec3 aberrate(vec3 color) {
vec2 offset = caOffset * abs(cos(texcoord * 3.14));
float red = texture2D(gcolor, texcoord - offset).r;
float blue = texture2D(gcolor, texcoord + offset).b;
float red = color.r;
float blue = color.b;
return vec3(red, 0, blue);
}

View file

@ -0,0 +1,38 @@
#include "/var/signal.glsl"
#define signal 0 // [0 1]
#define wire 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; // 2π * 3.57MHz * x
float phase = sin(carrier) * i + cos(carrier) * q;
float quad = cos(carrier) * i - sin(carrier) * q;
// decode faux signal
#if wire == WIRE_COMPOSITE
float composite = phase + quad + (y * 5.500); // p + q + (y * 5.5MHz)
y = round(composite * 5.500) / 30.250;
phase = composite - quad - (y * 5.500);
quad = composite - phase - (y * 5.500);
#endif
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;
}

View file

@ -20,7 +20,7 @@ screen.COLOR.columns=3
screen.COLOR=colorMode dithering <empty> colorDepth <empty> monoPalette hueBits satBits valBits
# screen effects
screen.SCREEN=interlacing scanline aberration
screen.SCREEN=signal wire interlacing scanline aberration
# console effects
screen.CONSOLE.columns=1

View file

@ -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

7
shaders/var/signal.glsl Normal file
View file

@ -0,0 +1,7 @@
#define SIGNAL_RGB 0
#define SIGNAL_NTSC 1
#define WIRE_COMPOSITE 0
#define WIRE_SVIDEO 1