summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/renderergl2/glsl/generic_fp.glsl2
-rw-r--r--src/renderergl2/glsl/lightall_fp.glsl2
-rw-r--r--src/renderergl2/tr_bsp.c87
3 files changed, 44 insertions, 47 deletions
diff --git a/src/renderergl2/glsl/generic_fp.glsl b/src/renderergl2/glsl/generic_fp.glsl
index f485797f..aefa33c3 100644
--- a/src/renderergl2/glsl/generic_fp.glsl
+++ b/src/renderergl2/glsl/generic_fp.glsl
@@ -21,7 +21,7 @@ void main()
#if defined(USE_LIGHTMAP)
vec4 color2 = texture2D(u_LightMap, var_LightTex);
#if defined(RGBM_LIGHTMAP)
- color2.rgb *= 32.0 * color2.a;
+ color2.rgb *= color2.a;
color2.a = 1.0;
#endif
diff --git a/src/renderergl2/glsl/lightall_fp.glsl b/src/renderergl2/glsl/lightall_fp.glsl
index d134e409..b983d6fe 100644
--- a/src/renderergl2/glsl/lightall_fp.glsl
+++ b/src/renderergl2/glsl/lightall_fp.glsl
@@ -346,7 +346,7 @@ void main()
vec4 lightSample = texture2D(u_LightMap, var_TexCoords.zw);
vec3 lightColor = lightSample.rgb;
#if defined(RGBM_LIGHTMAP)
- lightColor *= 32.0 * lightSample.a;
+ lightColor *= lightSample.a;
#endif
#elif defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT)
vec3 lightColor = u_DirectedLight * CalcLightAttenuation(float(var_LightDir.w > 0.0), var_LightDir.w / sqrLightDist);
diff --git a/src/renderergl2/tr_bsp.c b/src/renderergl2/tr_bsp.c
index 42478035..0e018ca2 100644
--- a/src/renderergl2/tr_bsp.c
+++ b/src/renderergl2/tr_bsp.c
@@ -166,8 +166,6 @@ void ColorToRGBM(const vec3_t color, unsigned char rgbm[4])
vec3_t sample;
float maxComponent;
- VectorScale(color, 1.0f / 32.0f, sample);
-
maxComponent = MAX(sample[0], sample[1]);
maxComponent = MAX(maxComponent, sample[2]);
maxComponent = CLAMP(maxComponent, 1.0f/255.0f, 1.0f);
@@ -327,7 +325,6 @@ static void R_LoadLightmaps( lump_t *l, lump_t *surfs ) {
{
char filename[MAX_QPATH];
byte *hdrLightmap = NULL;
- float lightScale = 1.0f;
int size = 0;
// look for hdr lightmaps
@@ -384,55 +381,55 @@ static void R_LoadLightmaps( lump_t *l, lump_t *surfs ) {
buf_p = buf + i * tr.lightmapSize * tr.lightmapSize * 3;
}
- lightScale = pow(2, r_mapOverBrightBits->integer - tr.overbrightBits - 8); //exp2(r_mapOverBrightBits->integer - tr.overbrightBits - 8);
-
for ( j = 0 ; j < tr.lightmapSize * tr.lightmapSize; j++ )
{
- if (r_hdr->integer)
+ if (hdrLightmap)
{
float color[3];
- if (hdrLightmap)
- {
#if 0 // HDRFILE_RGBE
- float exponent = exp2(buf_p[j*4+3] - 128);
+ float exponent = exp2(buf_p[j*4+3] - 128);
- color[0] = buf_p[j*4+0] * exponent;
- color[1] = buf_p[j*4+1] * exponent;
- color[2] = buf_p[j*4+2] * exponent;
+ color[0] = buf_p[j*4+0] * exponent;
+ color[1] = buf_p[j*4+1] * exponent;
+ color[2] = buf_p[j*4+2] * exponent;
#else // HDRFILE_FLOAT
- memcpy(color, &buf_p[j*12], 12);
+ memcpy(color, &buf_p[j*12], 12);
- color[0] = LittleFloat(color[0]);
- color[1] = LittleFloat(color[1]);
- color[2] = LittleFloat(color[2]);
+ color[0] = LittleFloat(color[0]);
+ color[1] = LittleFloat(color[1]);
+ color[2] = LittleFloat(color[2]);
#endif
- }
- else
- {
- //hack: convert LDR lightmap to HDR one
- color[0] = (buf_p[j*3+0] + 1.0f);
- color[1] = (buf_p[j*3+1] + 1.0f);
- color[2] = (buf_p[j*3+2] + 1.0f);
-
- // if under an arbitrary value (say 12) grey it out
- // this prevents weird splotches in dimly lit areas
- if (color[0] + color[1] + color[2] < 12.0f)
- {
- float avg = (color[0] + color[1] + color[2]) * 0.3333f;
- color[0] = avg;
- color[1] = avg;
- color[2] = avg;
- }
- }
-
- VectorScale(color, lightScale, color);
+ R_ColorShiftLightingFloats(color, color, 1.0f/255.0f);
if (glRefConfig.textureFloat && glRefConfig.halfFloatPixel && r_floatLightmap->integer)
ColorToRGBA16F(color, (unsigned short *)(&image[j*8]));
else
ColorToRGBM(color, &image[j*4]);
}
+ else if (glRefConfig.textureFloat && glRefConfig.halfFloatPixel && r_floatLightmap->integer)
+ {
+ float color[3];
+
+ //hack: convert LDR lightmap to HDR one
+ color[0] = MAX(buf_p[j*3+0], 0.499f);
+ color[1] = MAX(buf_p[j*3+1], 0.499f);
+ color[2] = MAX(buf_p[j*3+2], 0.499f);
+
+ // if under an arbitrary value (say 12) grey it out
+ // this prevents weird splotches in dimly lit areas
+ if (color[0] + color[1] + color[2] < 12.0f)
+ {
+ float avg = (color[0] + color[1] + color[2]) * 0.3333f;
+ color[0] = avg;
+ color[1] = avg;
+ color[2] = avg;
+ }
+
+ R_ColorShiftLightingFloats(color, color, 1.0f/255.0f);
+
+ ColorToRGBA16F(color, (unsigned short *)(&image[j*8]));
+ }
else
{
if ( r_lightmap->integer == 2 )
@@ -738,9 +735,9 @@ static void ParseFace( dsurface_t *ds, drawVert_t *verts, float *hdrVertColors,
//hack: convert LDR vertex colors to HDR
if (r_hdr->integer)
{
- color[0] = verts[i].color[0] + 1.0f;
- color[1] = verts[i].color[1] + 1.0f;
- color[2] = verts[i].color[2] + 1.0f;
+ color[0] = MAX(verts[i].color[0], 0.499f);
+ color[1] = MAX(verts[i].color[1], 0.499f);
+ color[2] = MAX(verts[i].color[2], 0.499f);
}
else
{
@@ -882,9 +879,9 @@ static void ParseMesh ( dsurface_t *ds, drawVert_t *verts, float *hdrVertColors,
//hack: convert LDR vertex colors to HDR
if (r_hdr->integer)
{
- color[0] = verts[i].color[0] + 1.0f;
- color[1] = verts[i].color[1] + 1.0f;
- color[2] = verts[i].color[2] + 1.0f;
+ color[0] = MAX(verts[i].color[0], 0.499f);
+ color[1] = MAX(verts[i].color[1], 0.499f);
+ color[2] = MAX(verts[i].color[2], 0.499f);
}
else
{
@@ -983,9 +980,9 @@ static void ParseTriSurf( dsurface_t *ds, drawVert_t *verts, float *hdrVertColor
//hack: convert LDR vertex colors to HDR
if (r_hdr->integer)
{
- color[0] = verts[i].color[0] + 1.0f;
- color[1] = verts[i].color[1] + 1.0f;
- color[2] = verts[i].color[2] + 1.0f;
+ color[0] = MAX(verts[i].color[0], 0.499f);
+ color[1] = MAX(verts[i].color[1], 0.499f);
+ color[2] = MAX(verts[i].color[2], 0.499f);
}
else
{