shithub: qk1

Download patch

ref: 3f06ec4dfff813a552325d52392abb20d450692d
parent: 1a81744f88e857627f74971e8709333cc9917a78
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Sun Dec 17 19:25:19 EST 2023

fog: correctly apply fog to all blended surfaces

--- a/d_local.h
+++ b/d_local.h
@@ -72,7 +72,7 @@
 extern float d_scalemip[3];
 
 static inline pixel_t
-blendalpha(pixel_t ca, pixel_t cb, int alpha)
+blendalpha(pixel_t ca, pixel_t cb, int alpha, uzint izi)
 {
 	int a, b, c;
 
@@ -80,14 +80,16 @@
 		a = (alpha*((ca>> 0)&0xff) + 255*((cb>> 0)&0xff))>> 8;
 		b = (alpha*((ca>> 8)&0xff) + 255*((cb>> 8)&0xff))>> 8;
 		c = (alpha*((ca>>16)&0xff) + 255*((cb>>16)&0xff))>> 8;
-		return (cb & 0xff000000) | min(a, 255) | min(b, 255)<<8 | min(c, 255)<<16;
+		return R_BlendFog((cb & 0xff000000) | min(a, 255) | min(b, 255)<<8 | min(c, 255)<<16, izi);
 	}
 
-	return
+	return R_BlendFog(
 		(cb & 0xff000000) |
 		((alpha*((ca>> 0)&0xff) + (255-alpha)*((cb>> 0)&0xff))>> 8) << 0 |
 		((alpha*((ca>> 8)&0xff) + (255-alpha)*((cb>> 8)&0xff))>> 8) << 8 |
-		((alpha*((ca>>16)&0xff) + (255-alpha)*((cb>>16)&0xff))>> 8) << 16;
+		((alpha*((ca>>16)&0xff) + (255-alpha)*((cb>>16)&0xff))>> 8) << 16,
+		izi
+	);
 }
 
 float alphafor(int flags);
--- a/d_polyse.c
+++ b/d_polyse.c
@@ -123,7 +123,7 @@
 				pixel_t p = addlight(skintable[fv->t >> 16][fv->s >> 16], fv->l[0], fv->l[1], fv->l[2]);
 				int n = d_scantable[fv->v] + fv->u;
 				if(r_drawflags & DRAW_BLEND){
-					d_viewbuffer[n] = blendalpha(p, d_viewbuffer[n], alpha);
+					d_viewbuffer[n] = blendalpha(p, d_viewbuffer[n], alpha, z);
 				}else{
 					d_viewbuffer[n] = p;
 					*zbuf = z;
@@ -311,7 +311,7 @@
 		pixel_t p = addlight(skintable[new.t >> 16][new.s >> 16], l[0], l[1], l[2]);
 		int n = d_scantable[new.v] + new.u;
 		if(r_drawflags & DRAW_BLEND){
-			d_viewbuffer[n] = blendalpha(p, d_viewbuffer[n], alpha);
+			d_viewbuffer[n] = blendalpha(p, d_viewbuffer[n], alpha, z);
 		}else{
 			d_viewbuffer[n] = p;
 			*zbuf = z;
@@ -555,7 +555,8 @@
 						*lpdest = blendalpha(
 							p,
 							*lpdest,
-							alpha
+							alpha,
+							lzi
 						);
 					}else{
 						*lpdest = p;
--- a/d_scan.c
+++ b/d_scan.c
@@ -64,7 +64,7 @@
 		sturb = ((r_turb_s + r_turb_turb[(r_turb_t>>16)&(CYCLE-1)])>>16)&63;
 		tturb = ((r_turb_t + r_turb_turb[(r_turb_s>>16)&(CYCLE-1)])>>16)&63;
 		if(*r_turb_z <= izi || (r_drawflags & DRAW_BLEND) == 0)
-			*r_turb_pdest = blendalpha(*(r_turb_pbase + (tturb<<6) + sturb), *r_turb_pdest, alpha);
+			*r_turb_pdest = blendalpha(*(r_turb_pbase + (tturb<<6) + sturb), *r_turb_pdest, alpha, izi);
 		r_turb_s += r_turb_sstep;
 		r_turb_t += r_turb_tstep;
 		r_turb_pdest++;
--- a/d_sprite.c
+++ b/d_sprite.c
@@ -139,7 +139,7 @@
 				{
 					if (*pz <= izi){
 						if(r_drawflags & DRAW_BLEND){
-							*pdest = blendalpha(btemp, *pdest, alpha);
+							*pdest = blendalpha(btemp, *pdest, alpha, izi);
 						}else{
 							*pz = izi;
 							*pdest = btemp;
--- a/span_alpha.c
+++ b/span_alpha.c
@@ -9,7 +9,7 @@
 		do{
 			pix = pbase[(s >> 16) + (t >> 16) * cachewidth];
 			if(opaque(pix) && *pz <= izi)
-				*pdest = blendalpha(pix, *pdest, alpha);
+				*pdest = blendalpha(pix, *pdest, alpha, izi);
 			pdest++;
 			pz++;
 			izi += izistep;