diff --git a/src/r_data.c b/src/r_data.c
index 75ec0556d46f1edff4d2c473b595a40e835426ac..f3e59b559c37ab50e8c9762470ebb68b6b732eb3 100644
--- a/src/r_data.c
+++ b/src/r_data.c
@@ -31,6 +31,8 @@
 #include "byteptr.h"
 #include "dehacked.h"
 
+#include "k_brightmap.h" // rr
+
 #ifdef HWRENDER
 #include "hardware/hw_glob.h" // HWR_ClearLightTables
 #endif
@@ -695,6 +697,7 @@ extracolormap_t *R_ColormapForName(char *name)
 // data and not the colormap data.
 //
 static double deltas[256][3], map[256][3];
+static double brightChange[256], map[256][3]; // rr
 
 static colorlookup_t lighttable_lut;
 
@@ -719,6 +722,9 @@ void R_GenerateLightTable(extracolormap_t *extra_colormap, boolean uselookup)
 {
 	double cmaskr, cmaskg, cmaskb, cdestr, cdestg, cdestb;
 	double maskamt = 0, othermask = 0;
+	
+	// rr - colormap changes
+	double cdestbright, fmaskamt = 0, fothermask = 0;
 
 	UINT8 cr = R_GetRgbaR(extra_colormap->rgba),
 		cg = R_GetRgbaG(extra_colormap->rgba),
@@ -726,8 +732,8 @@ void R_GenerateLightTable(extracolormap_t *extra_colormap, boolean uselookup)
 		ca = R_GetRgbaA(extra_colormap->rgba),
 		cfr = R_GetRgbaR(extra_colormap->fadergba),
 		cfg = R_GetRgbaG(extra_colormap->fadergba),
-		cfb = R_GetRgbaB(extra_colormap->fadergba);
-//		cfa = R_GetRgbaA(extra_colormap->fadergba); // unused in software
+		cfb = R_GetRgbaB(extra_colormap->fadergba),
+		cfa = R_GetRgbaA(extra_colormap->fadergba); // rr
 
 	UINT8 fadestart = extra_colormap->fadestart,
 		fadedist = extra_colormap->fadeend - extra_colormap->fadestart;
@@ -764,6 +770,13 @@ void R_GenerateLightTable(extracolormap_t *extra_colormap, boolean uselookup)
 	// cdestr *= maskamt;
 	// cdestg *= maskamt;
 	// cdestb *= maskamt;
+	
+	// rr
+	cdestbright = sqrt((cfr*cfr) + (cfg*cfg) + (cfb*cfb));
+	//fmaskamt = (double)(cfa/24.0l);
+	fmaskamt = (double)(cfa/255.0l);
+	//fothermask = 1 - fmaskamt;
+	//(void)fothermask; // unused, but don't feel like commenting it out
 
 	/////////////////////
 	// This code creates the colormap array used by software renderer
@@ -772,6 +785,7 @@ void R_GenerateLightTable(extracolormap_t *extra_colormap, boolean uselookup)
 		double r, g, b, cbrightness;
 		int p;
 		char *colormap_p;
+		double cbest, cdist; // rr
 
 		UINT8 (*NearestColorFunc)(UINT8, UINT8, UINT8);
 
@@ -809,6 +823,24 @@ void R_GenerateLightTable(extracolormap_t *extra_colormap, boolean uselookup)
 			if (map[i][2] > 255.0l)
 				map[i][2] = 255.0l;
 			deltas[i][2] = (map[i][2] - cdestb) / (double)fadedist;
+			
+			// rr
+			// Get the "best" color.
+			// Our brightest color's value, if we're fading to a darker color,
+			// or our (inverted) darkest color's value, if we're fading to a brighter color.
+			if (cbrightness < cdestbright)
+			{
+				cbest = 255.0l - min(r, min(g, b));
+				cdist = 255.0l - max(cdestr, max(cdestg, cdestb));
+			}
+			else
+			{
+				cbest = max(r, max(g, b));
+				cdist = min(cdestr, min(cdestg, cdestb));
+			}
+
+			// Add/subtract this value during fading.
+			brightChange[i] = (fabs(cbest - cdist) / (double)fadedist) * fmaskamt;
 		}
 
 		// Now allocate memory for the actual colormap array itself!
@@ -828,7 +860,7 @@ void R_GenerateLightTable(extracolormap_t *extra_colormap, boolean uselookup)
 
 				if ((UINT32)p < fadestart)
 					continue;
-#define ABS2(x) ((x) < 0 ? -(x) : (x))
+/*#define ABS2(x) ((x) < 0 ? -(x) : (x))
 				if (ABS2(map[i][0] - cdestr) > ABS2(deltas[i][0]))
 					map[i][0] -= deltas[i][0];
 				else
@@ -843,7 +875,29 @@ void R_GenerateLightTable(extracolormap_t *extra_colormap, boolean uselookup)
 					map[i][2] -= deltas[i][2];
 				else
 					map[i][2] = cdestb;
-#undef ABS2
+#undef ABS2*/
+				// rr
+				// Add/subtract towards the destination color.
+				if (fabs(map[i][0] - cdestr) <= brightChange[i])
+					map[i][0] = cdestr;
+				else if (map[i][0] > cdestr)
+					map[i][0] -= brightChange[i];
+				else
+					map[i][0] += brightChange[i];
+
+				if (fabs(map[i][1] - cdestg) <= brightChange[i])
+					map[i][1] = cdestg;
+				else if (map[i][1] > cdestg)
+					map[i][1] -= brightChange[i];
+				else
+					map[i][1] += brightChange[i];
+
+				if (fabs(map[i][2] - cdestb) <= brightChange[i])
+					map[i][2] = cdestb;
+				else if (map[i][2] > cdestb)
+					map[i][2] -= brightChange[i];
+				else
+					map[i][2] += brightChange[i];
 			}
 		}
 	}
@@ -1189,6 +1243,10 @@ void R_InitData(void)
 
 	CONS_Printf("P_InitPicAnims()...\n");
 	P_InitPicAnims();
+	
+	// rr
+	CONS_Printf("K_InitBrightmaps()...\n");
+	K_InitBrightmaps();
 
 	CONS_Printf("R_InitSprites()...\n");
 	R_InitSpriteLumps();