shithub: qk1

Download patch

ref: e95c6802a0f5a3aef0ea963a31122a7c6bc37468
parent: d1d313fc2b61a28454d3f72715afdb965c294604
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Sun Dec 17 13:29:15 EST 2023

fog: don't recalculate the same thing; no possible additive blending so inline it

--- a/r_fog.c
+++ b/r_fog.c
@@ -43,7 +43,7 @@
 void
 R_DrawFog(void)
 {
-	byte skyfogalpha, a;
+	byte ca0, ca1, ca2, skyfogalpha, a;
 	pixel_t *pix;
 	int i, x, y;
 	uzint *z;
@@ -52,6 +52,10 @@
 	if(r_fog.density <= 0.0)
 		return;
 
+	ca0 = r_fog.color>> 0;
+	ca1 = r_fog.color>> 8;
+	ca2 = r_fog.color>>16;
+
 	skyfogalpha = 255 * clamp(r_skyfog.value, 0, 1.0);
 	/* FIXME(sigrid): this is super slow */
 	for(y = r_refdef.vrect.y; y < r_refdef.vrectbottom; y++){
@@ -59,17 +63,21 @@
 		pix = vid.buffer + i;
 		z = d_pzbuffer + i;
 		for(x = r_refdef.vrect.x; x < r_refdef.vrectright; x++, i++, pix++, z++){
-			if(*z >= 65536){
+			if(*z > 65536){
 				d = 65536.0 / (float)(*z >> 16);
 				d = 1.0 - exp2(-r_fog.density * d*d);
-				a = 255 * clamp(d, 0.0, 1.0);
+				a = 255*clamp(d, 0.0, 1.0);
 			}else if(*z < 0){
 				a = skyfogalpha;
 			}else
 				continue;
 
-			if(a > 0)
-				*pix = blendalpha(r_fog.color, *pix, a);
+			if(a > 0){
+				*pix =
+					((a*ca0 + (255-a)*((*pix>> 0)&0xff)) >> 8) << 0 |
+					((a*ca1 + (255-a)*((*pix>> 8)&0xff)) >> 8) << 8 |
+					((a*ca2 + (255-a)*((*pix>>16)&0xff)) >> 8) << 16;
+			}
 		}
 	}
 }