From 532f5c5df13d8765fcbd8c8b048f088b1627a297 Mon Sep 17 00:00:00 2001 From: Valerie Date: Sun, 5 May 2024 13:44:23 -0400 Subject: [PATCH] initial PAL simulation implementation --- shaders/final.fsh | 2 ++ shaders/lang/en_US.lang | 5 ++-- shaders/module/signal.frag | 47 +++++++++++++++++++++++++++++++------- shaders/shaders.properties | 6 ++--- shaders/var/signal.glsl | 1 + 5 files changed, 48 insertions(+), 13 deletions(-) diff --git a/shaders/final.fsh b/shaders/final.fsh index 21331c6..da7dc28 100644 --- a/shaders/final.fsh +++ b/shaders/final.fsh @@ -33,6 +33,8 @@ void main() { // hardware post-processing effects #if signal == SIGNAL_NTSC color = ntsc(color); + #elif signal == SIGNAL_PAL + color = pal(color); #endif // physical post-processing effects diff --git a/shaders/lang/en_US.lang b/shaders/lang/en_US.lang index 79718fc..dc31a9f 100644 --- a/shaders/lang/en_US.lang +++ b/shaders/lang/en_US.lang @@ -52,9 +52,10 @@ suffix.valBits=-bit screen.SCREEN=Screen -option.signal=Signal -value.signal.0=RGB (Off) +option.signal=Encoding +value.signal.0=None value.signal.1=NTSC +value.signal.2=PAL option.wire=Connector value.wire.0=Composite diff --git a/shaders/module/signal.frag b/shaders/module/signal.frag index 7d3db79..1054e15 100644 --- a/shaders/module/signal.frag +++ b/shaders/module/signal.frag @@ -1,12 +1,16 @@ #include "/var/signal.glsl" -#define signal 0 // [0 1] +#define signal 0 // [0 1 2] #define wire 0 // [0 1] +float luminance(vec3 color) { + return dot(color, vec3(0.299, 0.587, 0.114)); +} + vec3 ntsc(vec3 color) { // convert to YIQ - float y = dot(color, vec3(0.299, 0.587, 0.114)); + float y = luminance(color); float i = dot(color, vec3(0.596, -.274, -.322)); float q = dot(color, vec3(0.211, -.523, 0.312)); @@ -17,7 +21,7 @@ vec3 ntsc(vec3 color) { // decode faux signal #if wire == WIRE_COMPOSITE - float composite = phase + quad + (y * 5.500); // p + q + (y * 5.5MHz) + float composite = phase + (y * 5.500); // p + (y * 5.5MHz) y = round(composite * 5.500) / 30.250; phase = composite - quad - (y * 5.500); quad = composite - phase - (y * 5.500); @@ -28,11 +32,38 @@ vec3 ntsc(vec3 color) { // 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)); + float r = dot(yiqColor, vec3(1, 0.956, 0.619)); + float g = dot(yiqColor, vec3(1, -.272, -.674)); + float b = dot(yiqColor, vec3(1, -1.106, 1.703)); - return outColor; + return vec3(r, g, b).rgb; +} + +vec3 pal(vec3 color) { + // convert to YUV + float y = luminance(color); + float u = 0.492 * (color.b - y); + float v = 0.877 * (color.r - y); + + // faux pal signal + float carrier = 6.283 * 4.434; + float phase = sin(carrier) * u - cos(carrier) * v; + float quad = cos(carrier) * u - sin(carrier) * v; + + // decode faux signal + #if wire == WIRE_COMPOSITE + float composite = y + phase; + #endif + u = quad * cos(carrier); + v = phase * sin(carrier); + + // convert back to RGB + vec3 yuvColor = vec3(y, u, v); + + float r = y + (1.140 * v); + float g = y - (0.395 * u) - (0.581 * v); + float b = y + (2.033 * u); + + return vec3(r, g, b).rgb; } diff --git a/shaders/shaders.properties b/shaders/shaders.properties index c85bc7f..a6d22fc 100644 --- a/shaders/shaders.properties +++ b/shaders/shaders.properties @@ -13,14 +13,14 @@ profile.VR32=pixelSize=8 colorMode=1 !dithering colorDepth=1 monoPalette=2 vWarp # -- SCREENS -- # default -screen= pixelSize [COLOR] [SCREEN] [CONSOLE] [FX] +screen= pixelSize [COLOR] [SCREEN] [CONSOLE] [FX] # colors screen.COLOR.columns=3 screen.COLOR=colorMode dithering colorDepth monoPalette hueBits satBits valBits # screen effects -screen.SCREEN=signal wire interlacing scanline aberration +screen.SCREEN=signal wire interlacing scanline aberration # console effects screen.CONSOLE.columns=1 @@ -29,7 +29,7 @@ screen.PSX=vWarp tWarp # playstation screen.REALITY=hBlur # nintendo 64 # custom effects -screen.FX=dof dofRes worldCurvature worldRadius +screen.FX=dof dofRes worldCurvature worldRadius # -- CONDITIONALS -- gbuffers_hand.enabled=tWarp diff --git a/shaders/var/signal.glsl b/shaders/var/signal.glsl index a2c0e46..929c715 100644 --- a/shaders/var/signal.glsl +++ b/shaders/var/signal.glsl @@ -1,6 +1,7 @@ #define SIGNAL_RGB 0 #define SIGNAL_NTSC 1 +#define SIGNAL_PAL 2 #define WIRE_COMPOSITE 0 #define WIRE_SVIDEO 1