From dde36d91ce6a5d9b0b2fca0f93afde8422b1a66e Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Wed, 15 Jan 2014 23:53:00 -0600 Subject: [PATCH] Fix OpenGL2 non-HDR map surface over brighting Vertex lit map surfaces were saturating to white when r_mapOverBrightBits was increased and r_hdr was disabled. Now the color is normalized like lightmaps and lightgrid when r_hdr is disabled. Which is the same as OpenGL1. Noticeable on misc_model trisoup. --- code/renderergl2/tr_bsp.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/code/renderergl2/tr_bsp.c b/code/renderergl2/tr_bsp.c index c796e625..3413ff2d 100644 --- a/code/renderergl2/tr_bsp.c +++ b/code/renderergl2/tr_bsp.c @@ -128,17 +128,34 @@ static void R_ColorShiftLightingBytes( byte in[4], byte out[4] ) { /* =============== -R_ColorShiftLightingBytes +R_ColorShiftLightingFloats =============== */ static void R_ColorShiftLightingFloats(float in[4], float out[4], float scale ) { + float r, g, b; + scale *= pow(2.0f, r_mapOverBrightBits->integer - tr.overbrightBits); - out[0] = in[0] * scale; - out[1] = in[1] * scale; - out[2] = in[2] * scale; + r = in[0] * scale; + g = in[1] * scale; + b = in[2] * scale; + + // normalize by color instead of saturating to white + if ( !r_hdr->integer && ( r > 1 || g > 1 || b > 1 ) ) { + float max; + + max = r > g ? r : g; + max = max > b ? max : b; + r = r / max; + g = g / max; + b = b / max; + } + + out[0] = r; + out[1] = g; + out[2] = b; out[3] = in[3]; }