changeset 2343:49bd818ec9d8

Updated NTSC shader from Sik
author Michael Pavone <pavone@retrodev.com>
date Sun, 01 Oct 2023 23:41:19 -0700
parents 9f0c67e5c50a
children ae073c2167e2
files shaders/ntsc.f.glsl
diffstat 1 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/shaders/ntsc.f.glsl	Sun Oct 01 23:39:48 2023 -0700
+++ b/shaders/ntsc.f.glsl	Sun Oct 01 23:41:19 2023 -0700
@@ -2,6 +2,8 @@
 // NTSC composite simulator for BlastEm
 // Shader by Sik, based on BlastEm's default shader
 //
+// Now with gamma correction (NTSC = 2.5 gamma, sRGB = 2.2 gamma)
+//
 // It works by converting from RGB to YIQ and then encoding it into NTSC, then
 // trying to decode it back. The lossy nature of the encoding process results in
 // the rainbow effect. It also accounts for the differences between H40 and H32
@@ -63,6 +65,10 @@
 	// Horizontal distance of half a colorburst cycle
 	mediump float factorX = (1.0 / texsize.x) / 170.667 * 0.5 * (width - 27.0);
 	
+	// sRGB has a gamma of 2.2 while NTSC has a gamma of 2.5
+	// Use this value to do gamma correction of every RGB value
+	mediump float gamma = 2.5 / 2.2;
+	
 	// Where we store the sampled pixels.
 	// [0] = current pixel
 	// [1] = 1/4 colorburst cycles earlier
@@ -142,7 +148,8 @@
 		0.125 * raw[6] * cos(phase[6]);
 	
 	// Convert YIQ back to RGB and output it
-	gl_FragColor = yiq2rgba(vec3(y_mix, i_mix, q_mix));
+	gl_FragColor = pow(yiq2rgba(vec3(y_mix, i_mix, q_mix)),
+	                   vec4(gamma, gamma, gamma, 1.0));
 	
 	// If you're curious to see what the raw composite signal looks like,
 	// comment out the above and uncomment the line below instead