summaryrefslogtreecommitdiff
path: root/src/renderergl2
diff options
context:
space:
mode:
authorSmileTheory <SmileTheory@gmail.com>2013-09-16 14:26:42 -0700
committerTim Angus <tim@ngus.net>2014-06-17 17:43:34 +0100
commitc97e014cfe5cad85cedfdf89efcb25d8defbb0c8 (patch)
treeef2116121b6591515c485e04afa04ac389c77e23 /src/renderergl2
parentfc232c31d075091fea63c6dffa9ec69677b7068b (diff)
OpenGL2: Fix inaccurate RGBM calculation.
Diffstat (limited to 'src/renderergl2')
-rw-r--r--src/renderergl2/tr_bsp.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/src/renderergl2/tr_bsp.c b/src/renderergl2/tr_bsp.c
index 1fcf817f..4aac6de0 100644
--- a/src/renderergl2/tr_bsp.c
+++ b/src/renderergl2/tr_bsp.c
@@ -151,22 +151,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;
-
- VectorScale(sample, 1.0f / maxComponent, sample);
+ maxComponent = MAX(sample[0], sample[1]);
+ maxComponent = MAX(maxComponent, sample[2]);
+ maxComponent = CLAMP(maxComponent, 1.0f/255.0f, 1.0f);
+
+ 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])