mirror of
https://github.com/ioquake/ioq3.git
synced 2024-11-10 07:11:46 +00:00
OpenGL2: Set RGBM to use a multiplier of 1, and only use it with HDR lightmaps.
This commit is contained in:
parent
6beab9cf58
commit
79e9baedf8
3 changed files with 44 additions and 47 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -165,8 +165,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);
|
||||
|
@ -326,7 +324,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
|
||||
|
@ -383,55 +380,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 )
|
||||
|
@ -737,9 +734,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
|
||||
{
|
||||
|
@ -881,9 +878,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
|
||||
{
|
||||
|
@ -982,9 +979,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
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue