From a408a2bdae402a373106dc33e14a27a63d78d175 Mon Sep 17 00:00:00 2001 From: SmileTheory Date: Mon, 16 Sep 2013 14:26:42 -0700 Subject: [PATCH] OpenGL2: Fix inaccurate RGBM calculation. --- code/renderergl2/tr_bsp.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/code/renderergl2/tr_bsp.c b/code/renderergl2/tr_bsp.c index bbe3f228..64d54805 100644 --- a/code/renderergl2/tr_bsp.c +++ b/code/renderergl2/tr_bsp.c @@ -150,22 +150,18 @@ void ColorToRGBM(const vec3_t color, unsigned char rgbm[4]) VectorScale(color, 1.0f / 32.0f, sample); - maxComponent = sample[0]; - if(sample[1] > maxComponent) - maxComponent = sample[1]; - if(sample[2] > maxComponent) - maxComponent = sample[2]; - if(0.000001f > maxComponent) - maxComponent = 0.000001f; - if(maxComponent > 1.0f) - maxComponent = 1.0f; + maxComponent = MAX(sample[0], sample[1]); + maxComponent = MAX(maxComponent, sample[2]); + maxComponent = CLAMP(maxComponent, 1.0f/255.0f, 1.0f); - VectorScale(sample, 1.0f / maxComponent, sample); + rgbm[3] = (unsigned char) ceil(maxComponent * 255.0f); + maxComponent = 255.0f / rgbm[3]; + + VectorScale(sample, maxComponent, sample); rgbm[0] = (unsigned char) (sample[0] * 255); rgbm[1] = (unsigned char) (sample[1] * 255); rgbm[2] = (unsigned char) (sample[2] * 255); - rgbm[3] = (unsigned char) (maxComponent * 255); } void ColorToRGBA16F(const vec3_t color, unsigned short rgba16f[4])