<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">[PATCH] Start separating cshift and gamma concepts

If we're doing hardware gamma, we probably don't want to be making adjustments
everytime an effect goes off (do we?) so it's only really for the "brightness"
slider (gamma cvar).

V_UpdatePalette seems to be wanting to mix together the colour shift effects
from damage, quad, etc. with gamma correction. For now, we'll remove the
colour shifting aspect from the gamma setting code (done with calls to
VID_ShiftPalette) and rely on the gl_polyblend mechanism for that.

diff -urN b/NQ/view.c head/NQ/view.c
--- b/NQ/view.c	2005-12-29 15:45:29.000000000 +1030
+++ head/NQ/view.c	2005-12-29 19:04:44.000000000 +1030
@@ -267,7 +267,7 @@
 byte gammatable[256];		// palette is sent through this
 
 #ifdef	GLQUAKE
-static byte ramps[3][256];
+static unsigned short ramps[3][256];
 float v_blend[4];		// rgba 0.0 - 1.0
 #endif
 
@@ -482,27 +482,20 @@
     float r, g, b, a, a2;
     int j;
 
-    r = 0;
-    g = 0;
-    b = 0;
-    a = 0;
-
-    for (j = 0; j &lt; NUM_CSHIFTS; j++) {
-	if (!gl_cshiftpercent.value)
-	    continue;
-
-	a2 = ((cl.cshifts[j].percent * gl_cshiftpercent.value) / 100.0) /
-	    255.0;
-
-//              a2 = cl.cshifts[j].percent/255.0;
-	if (!a2)
-	    continue;
-	a = a + a2 * (1 - a);
-//Con_Printf ("j:%i a:%f\n", j, a);
-	a2 = a2 / a;
-	r = r * (1 - a2) + cl.cshifts[j].destcolor[0] * a2;
-	g = g * (1 - a2) + cl.cshifts[j].destcolor[1] * a2;
-	b = b * (1 - a2) + cl.cshifts[j].destcolor[2] * a2;
+    r = g = b = a = 0;
+
+    if (gl_cshiftpercent.value) {
+	for (j = 0; j &lt; NUM_CSHIFTS; j++) {
+	    a2 = ((cl.cshifts[j].percent * gl_cshiftpercent.value) / 100.0) /
+		255.0;
+	    if (!a2)
+		continue;
+	    a = a + a2 * (1 - a);
+	    a2 = a2 / a;
+	    r = r * (1 - a2) + cl.cshifts[j].destcolor[0] * a2;
+	    g = g * (1 - a2) + cl.cshifts[j].destcolor[1] * a2;
+	    b = b * (1 - a2) + cl.cshifts[j].destcolor[2] * a2;
+	}
     }
 
     v_blend[0] = r / 255.0;
@@ -526,66 +519,30 @@
 V_UpdatePalette(void)
 {
     int i, j;
-    qboolean new;
-    float r, g, b, a;
-    int ir, ig, ib;
     qboolean force;
 
     V_CalcPowerupCshift();
 
-    new = false;
-
-    for (i = 0; i &lt; NUM_CSHIFTS; i++) {
-	if (cl.cshifts[i].percent != cl.prev_cshifts[i].percent) {
-	    new = true;
-	    cl.prev_cshifts[i].percent = cl.cshifts[i].percent;
-	}
-	for (j = 0; j &lt; 3; j++)
-	    if (cl.cshifts[i].destcolor[j] != cl.prev_cshifts[i].destcolor[j]) {
-		new = true;
-		cl.prev_cshifts[i].destcolor[j] = cl.cshifts[i].destcolor[j];
-	    }
-    }
-
     /* drop the damage value */
     cl.cshifts[CSHIFT_DAMAGE].percent -= host_frametime * 150;
-    if (cl.cshifts[CSHIFT_DAMAGE].percent &lt;= 0)
+    if (cl.cshifts[CSHIFT_DAMAGE].percent &lt; 0)
 	cl.cshifts[CSHIFT_DAMAGE].percent = 0;
 
     /* drop the bonus value */
     cl.cshifts[CSHIFT_BONUS].percent -= host_frametime * 100;
-    if (cl.cshifts[CSHIFT_BONUS].percent &lt;= 0)
+    if (cl.cshifts[CSHIFT_BONUS].percent &lt; 0)
 	cl.cshifts[CSHIFT_BONUS].percent = 0;
 
     force = V_CheckGamma();
-    if (!new &amp;&amp; !force)
-	return;
-
-    V_CalcBlend();
-
-    a = v_blend[3];
-    r = 255 * v_blend[0] * a;
-    g = 255 * v_blend[1] * a;
-    b = 255 * v_blend[2] * a;
 
-    a = 1 - a;
-    for (i = 0; i &lt; 256; i++) {
-	ir = i * a + r;
-	ig = i * a + g;
-	ib = i * a + b;
-	if (ir &gt; 255)
-	    ir = 255;
-	if (ig &gt; 255)
-	    ig = 255;
-	if (ib &gt; 255)
-	    ib = 255;
-
-	ramps[0][i] = gammatable[ir];
-	ramps[1][i] = gammatable[ig];
-	ramps[2][i] = gammatable[ib];
+    if (force) {
+	for (i = 0; i &lt; 256; i++) {
+	    ramps[0][i] = gammatable[i] &lt;&lt; 8;
+	    ramps[1][i] = gammatable[i] &lt;&lt; 8;
+	    ramps[2][i] = gammatable[i] &lt;&lt; 8;
+	}
+	VID_ShiftPalette(NULL);
     }
-
-    VID_ShiftPalette(NULL);
 }
 #else // !GLQUAKE
 void
diff -urN b/QW/client/view.c head/QW/client/view.c
--- b/QW/client/view.c	2005-12-29 15:45:29.000000000 +1030
+++ head/QW/client/view.c	2005-12-29 21:18:42.000000000 +1030
@@ -276,7 +276,7 @@
 
 
 #ifdef	GLQUAKE
-static byte ramps[3][256];
+static unsigned short ramps[3][256];
 float v_blend[4];		// rgba 0.0 - 1.0
 #endif // GLQUAKE
 
@@ -494,27 +494,20 @@
     float r, g, b, a, a2;
     int j;
 
-    r = 0;
-    g = 0;
-    b = 0;
-    a = 0;
-
-    for (j = 0; j &lt; NUM_CSHIFTS; j++) {
-	if (!gl_cshiftpercent.value)
-	    continue;
-
-	a2 = ((cl.cshifts[j].percent * gl_cshiftpercent.value) / 100.0) /
-	    255.0;
-
-//              a2 = (cl.cshifts[j].percent/2)/255.0;
-	if (!a2)
-	    continue;
-	a = a + a2 * (1 - a);
-//Con_Printf ("j:%i a:%f\n", j, a);
-	a2 = a2 / a;
-	r = r * (1 - a2) + cl.cshifts[j].destcolor[0] * a2;
-	g = g * (1 - a2) + cl.cshifts[j].destcolor[1] * a2;
-	b = b * (1 - a2) + cl.cshifts[j].destcolor[2] * a2;
+    r = g = b = a = 0;
+
+    if (gl_cshiftpercent.value) {
+	for (j = 0; j &lt; NUM_CSHIFTS; j++) {
+	    a2 = ((cl.cshifts[j].percent * gl_cshiftpercent.value) / 100.0) /
+		255.0;
+	    if (!a2)
+		continue;
+	    a = a + a2 * (1 - a);
+	    a2 = a2 / a;
+	    r = r * (1 - a2) + cl.cshifts[j].destcolor[0] * a2;
+	    g = g * (1 - a2) + cl.cshifts[j].destcolor[1] * a2;
+	    b = b * (1 - a2) + cl.cshifts[j].destcolor[2] * a2;
+	}
     }
 
     v_blend[0] = r / 255.0;
@@ -538,66 +531,30 @@
 V_UpdatePalette(void)
 {
     int i, j;
-    qboolean new;
-    float r, g, b, a;
-    int ir, ig, ib;
     qboolean force;
 
     V_CalcPowerupCshift();
 
-    new = false;
-
-    for (i = 0; i &lt; NUM_CSHIFTS; i++) {
-	if (cl.cshifts[i].percent != cl.prev_cshifts[i].percent) {
-	    new = true;
-	    cl.prev_cshifts[i].percent = cl.cshifts[i].percent;
-	}
-	for (j = 0; j &lt; 3; j++)
-	    if (cl.cshifts[i].destcolor[j] != cl.prev_cshifts[i].destcolor[j]) {
-		new = true;
-		cl.prev_cshifts[i].destcolor[j] = cl.cshifts[i].destcolor[j];
-	    }
-    }
-
     /* drop the damage value */
     cl.cshifts[CSHIFT_DAMAGE].percent -= host_frametime * 150;
-    if (cl.cshifts[CSHIFT_DAMAGE].percent &lt;= 0)
+    if (cl.cshifts[CSHIFT_DAMAGE].percent &lt; 0)
 	cl.cshifts[CSHIFT_DAMAGE].percent = 0;
 
     /* drop the bonus value */
     cl.cshifts[CSHIFT_BONUS].percent -= host_frametime * 100;
-    if (cl.cshifts[CSHIFT_BONUS].percent &lt;= 0)
+    if (cl.cshifts[CSHIFT_BONUS].percent &lt; 0)
 	cl.cshifts[CSHIFT_BONUS].percent = 0;
 
     force = V_CheckGamma();
-    if (!new &amp;&amp; !force)
-	return;
-
-    V_CalcBlend();
 
-    a = v_blend[3];
-    r = 255 * v_blend[0] * a;
-    g = 255 * v_blend[1] * a;
-    b = 255 * v_blend[2] * a;
-
-    a = 1 - a;
-    for (i = 0; i &lt; 256; i++) {
-	ir = i * a + r;
-	ig = i * a + g;
-	ib = i * a + b;
-	if (ir &gt; 255)
-	    ir = 255;
-	if (ig &gt; 255)
-	    ig = 255;
-	if (ib &gt; 255)
-	    ib = 255;
-
-	ramps[0][i] = gammatable[ir];
-	ramps[1][i] = gammatable[ig];
-	ramps[2][i] = gammatable[ib];
+    if (force) {
+	for (i = 0; i &lt; 256; i++) {
+	    ramps[0][i] = gammatable[i] &lt;&lt; 8;
+	    ramps[1][i] = gammatable[i] &lt;&lt; 8;
+	    ramps[2][i] = gammatable[i] &lt;&lt; 8;
+	}
+	VID_ShiftPalette(NULL);
     }
-
-    VID_ShiftPalette(NULL);
 }
 #else // !GLQUAKE
 /*
</pre></body></html>