summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSmileTheory <SmileTheory@gmail.com>2013-09-16 05:57:14 -0700
committerTim Angus <tim@ngus.net>2014-06-17 17:43:34 +0100
commitfc232c31d075091fea63c6dffa9ec69677b7068b (patch)
tree0cb4c91901ca6a287ab9a4adb44b382ff3656945
parent75fe4796280cc95fe6b96cc9c9df5d74fc478ffa (diff)
OpenGL2: Use RGBM instead of RGBE encoding for lightmaps.
-rw-r--r--src/renderergl2/glsl/generic_fp.glsl4
-rw-r--r--src/renderergl2/glsl/lightall_fp.glsl4
-rw-r--r--src/renderergl2/tr_bsp.c52
-rw-r--r--src/renderergl2/tr_glsl.c4
4 files changed, 26 insertions, 38 deletions
diff --git a/src/renderergl2/glsl/generic_fp.glsl b/src/renderergl2/glsl/generic_fp.glsl
index dea52e06..997d4daa 100644
--- a/src/renderergl2/glsl/generic_fp.glsl
+++ b/src/renderergl2/glsl/generic_fp.glsl
@@ -20,8 +20,8 @@ void main()
vec4 color = texture2D(u_DiffuseMap, var_DiffuseTex);
#if defined(USE_LIGHTMAP)
vec4 color2 = texture2D(u_LightMap, var_LightTex);
- #if defined(RGBE_LIGHTMAP)
- color2.rgb *= exp2(color2.a * 255.0 - 128.0);
+ #if defined(RGBM_LIGHTMAP)
+ color2.rgb *= 32.0 * color2.a;
color2.a = 1.0;
#endif
diff --git a/src/renderergl2/glsl/lightall_fp.glsl b/src/renderergl2/glsl/lightall_fp.glsl
index efd01399..6aec2b4a 100644
--- a/src/renderergl2/glsl/lightall_fp.glsl
+++ b/src/renderergl2/glsl/lightall_fp.glsl
@@ -285,8 +285,8 @@ void main()
#if defined(USE_LIGHTMAP)
vec4 lightSample = texture2D(u_LightMap, var_LightTex).rgba;
- #if defined(RGBE_LIGHTMAP)
- lightSample.rgb *= exp2(lightSample.a * 255.0 - 128.0);
+ #if defined(RGBM_LIGHTMAP)
+ lightSample.rgb *= 32.0 * lightSample.a;
#endif
vec3 lightColor = lightSample.rgb;
#elif defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT)
diff --git a/src/renderergl2/tr_bsp.c b/src/renderergl2/tr_bsp.c
index f1eb51e3..1fcf817f 100644
--- a/src/renderergl2/tr_bsp.c
+++ b/src/renderergl2/tr_bsp.c
@@ -143,49 +143,32 @@ static void R_ColorShiftLightingFloats(float in[4], float out[4], float scale )
out[3] = in[3];
}
-
-void ColorToRGBE(const vec3_t color, unsigned char rgbe[4])
+// Modified from http://graphicrants.blogspot.jp/2009/04/rgbm-color-encoding.html
+void ColorToRGBM(const vec3_t color, unsigned char rgbm[4])
{
vec3_t sample;
float maxComponent;
- int e;
- VectorCopy(color, sample);
+ 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;
- if(maxComponent < 1e-32)
- {
- rgbe[0] = 0;
- rgbe[1] = 0;
- rgbe[2] = 0;
- rgbe[3] = 0;
- }
- else
- {
-#if 0
- maxComponent = frexp(maxComponent, &e) * 255.0 / maxComponent;
- rgbe[0] = (unsigned char) (sample[0] * maxComponent);
- rgbe[1] = (unsigned char) (sample[1] * maxComponent);
- rgbe[2] = (unsigned char) (sample[2] * maxComponent);
- rgbe[3] = (unsigned char) (e + 128);
-#else
- e = ceil(log(maxComponent) / log(2.0f));//ceil(log2(maxComponent));
- VectorScale(sample, 1.0 / pow(2.0f, e)/*exp2(e)*/, sample);
+ VectorScale(sample, 1.0f / maxComponent, sample);
- rgbe[0] = (unsigned char) (sample[0] * 255);
- rgbe[1] = (unsigned char) (sample[1] * 255);
- rgbe[2] = (unsigned char) (sample[2] * 255);
- rgbe[3] = (unsigned char) (e + 128);
-#endif
- }
+ 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])
{
rgba16f[0] = FloatToHalf(color[0]);
@@ -291,8 +274,13 @@ static void R_LoadLightmaps( lump_t *l, lump_t *surfs ) {
tr.deluxemaps = ri.Hunk_Alloc( tr.numLightmaps * sizeof(image_t *), h_low );
}
- if (r_hdr->integer && glRefConfig.textureFloat && glRefConfig.halfFloatPixel)
- textureInternalFormat = GL_RGBA16F_ARB;
+ if (r_hdr->integer)
+ {
+ if (glRefConfig.textureFloat && glRefConfig.halfFloatPixel)
+ textureInternalFormat = GL_RGBA16F_ARB;
+ else
+ textureInternalFormat = GL_RGBA8;
+ }
if (r_mergeLightmaps->integer)
{
@@ -430,7 +418,7 @@ static void R_LoadLightmaps( lump_t *l, lump_t *surfs ) {
if (glRefConfig.textureFloat && glRefConfig.halfFloatPixel)
ColorToRGBA16F(color, (unsigned short *)(&image[j*8]));
else
- ColorToRGBE(color, &image[j*4]);
+ ColorToRGBM(color, &image[j*4]);
}
else
{
diff --git a/src/renderergl2/tr_glsl.c b/src/renderergl2/tr_glsl.c
index 38eb7f6d..a2707cd0 100644
--- a/src/renderergl2/tr_glsl.c
+++ b/src/renderergl2/tr_glsl.c
@@ -908,7 +908,7 @@ void GLSL_InitGPUShaders(void)
Q_strcat(extradefines, 1024, "#define USE_LIGHTMAP\n");
if (r_hdr->integer && !(glRefConfig.textureFloat && glRefConfig.halfFloatPixel))
- Q_strcat(extradefines, 1024, "#define RGBE_LIGHTMAP\n");
+ Q_strcat(extradefines, 1024, "#define RGBM_LIGHTMAP\n");
if (!GLSL_InitGPUShader(&tr.genericShader[i], "generic", attribs, qtrue, extradefines, qtrue, fallbackShader_generic_vp, fallbackShader_generic_fp))
{
@@ -1037,7 +1037,7 @@ void GLSL_InitGPUShaders(void)
}
if (r_hdr->integer && !(glRefConfig.textureFloat && glRefConfig.halfFloatPixel))
- Q_strcat(extradefines, 1024, "#define RGBE_LIGHTMAP\n");
+ Q_strcat(extradefines, 1024, "#define RGBM_LIGHTMAP\n");
if (i & LIGHTDEF_LIGHTTYPE_MASK)
{