fix -nodeluxenormalize

git-svn-id: svn://svn.icculus.org/netradiant/trunk@106 61c419a2-8eb2-4b30-bcec-8cead039b335
This commit is contained in:
rpolzer 2008-09-26 08:44:14 +00:00
parent aa4914be0f
commit d356f3d8d3
3 changed files with 99 additions and 56 deletions

View File

@ -44,12 +44,14 @@ ColorToBytes()
ydnar: moved to here 2001-02-04 ydnar: moved to here 2001-02-04
*/ */
void ColorToBytes( const float *color, byte *colorBytes, float scale ) void ColorToBytesDeluxe( const float *color, byte *colorBytes, float scale, const float *deluxel, byte *deluxeBytes)
{ {
int i; int i;
float max, gamma; float max, gamma;
vec3_t sample; vec3_t sample, direction;
float inv, dif; float inv, dif;
float colorMultiplier;
float temp;
/* ydnar: scaling necessary for simulating r_overbrightBits on external lightmaps */ /* ydnar: scaling necessary for simulating r_overbrightBits on external lightmaps */
@ -64,7 +66,7 @@ void ColorToBytes( const float *color, byte *colorBytes, float scale )
for( i = 0; i < 3; i++ ) for( i = 0; i < 3; i++ )
{ {
/* handle negative light */ /* handle negative light */
if( sample[ i ] < 0.0f ) if( sample[ i ] <= 0.0f )
{ {
sample[ i ] = 0.0f; sample[ i ] = 0.0f;
continue; continue;
@ -74,6 +76,8 @@ void ColorToBytes( const float *color, byte *colorBytes, float scale )
sample[ i ] = pow( sample[ i ] / 255.0f, gamma ) * 255.0f; sample[ i ] = pow( sample[ i ] / 255.0f, gamma ) * 255.0f;
} }
colorMultiplier = 1;
if (lightmapExposure == 1) if (lightmapExposure == 1)
{ {
/* clamp with color normalization */ /* clamp with color normalization */
@ -82,16 +86,15 @@ void ColorToBytes( const float *color, byte *colorBytes, float scale )
max = sample[ 1 ]; max = sample[ 1 ];
if( sample[ 2 ] > max ) if( sample[ 2 ] > max )
max = sample[ 2 ]; max = sample[ 2 ];
if( max > 255.0f ) if(max * colorMultiplier > 255.0f)
VectorScale( sample, (255.0f / max), sample ); colorMultiplier *= 255.0 / max;
} }
else else
{ {
if (lightmapExposure==0) if (lightmapExposure==0)
{ inv = 1.f;
lightmapExposure=1.0f; else
} inv = 1.f/lightmapExposure;
inv=1.f/lightmapExposure;
//Exposure //Exposure
max = sample[ 0 ]; max = sample[ 0 ];
@ -99,6 +102,7 @@ void ColorToBytes( const float *color, byte *colorBytes, float scale )
max = sample[ 1 ]; max = sample[ 1 ];
if( sample[ 2 ] > max ) if( sample[ 2 ] > max )
max = sample[ 2 ]; max = sample[ 2 ];
max *= colorMultiplier;
dif = (1- exp(-max * inv) ) * 255; dif = (1- exp(-max * inv) ) * 255;
@ -111,20 +115,64 @@ void ColorToBytes( const float *color, byte *colorBytes, float scale )
dif = 0; dif = 0;
} }
for (i=0;i<3;i++) colorMultiplier *= dif;
{
sample[i]*=dif;
}
} }
/* compensate for ingame overbrighting/bitshifting */ /* compensate for ingame overbrighting/bitshifting */
VectorScale( sample, (1.0f / lightmapCompensate), sample ); VectorScale( sample, (colorMultiplier / lightmapCompensate), sample );
/* store it off */ /* store it off */
colorBytes[ 0 ] = sample[ 0 ]; colorBytes[ 0 ] = sample[ 0 ];
colorBytes[ 1 ] = sample[ 1 ]; colorBytes[ 1 ] = sample[ 1 ];
colorBytes[ 2 ] = sample[ 2 ]; colorBytes[ 2 ] = sample[ 2 ];
/* store direction */
if( deluxel )
{
if(normalizeDeluxemap)
{
if(!VectorNormalize(deluxel, direction))
VectorClear(direction);
}
else
{
if(deluxel[3])
{
VectorScale(deluxel, 1 / deluxel[3], direction);
// NOTE:
// if the light was scaled down due to it being too bright...
// we need to reduce the directionality so ADDING light can't
// make stuff DARKER!
if(colorMultiplier < 1)
VectorScale(direction, colorMultiplier, direction);
// TODO find out the best renderer equation for this
}
else
VectorClear(direction);
}
/* normalize average light direction */
//if(direction[0] != 0 || direction[1] != 0 || direction[2] != 0)
{
/* encode [-1,1] in [0,255] */
for( i = 0; i < 3; i++ )
{
temp = (direction[ i ] + 1.0f) * 127.5f;
if( temp < 0 )
deluxeBytes[ i ] = 0;
else if( temp > 255 )
deluxeBytes[ i ] = 255;
else
deluxeBytes[ i ] = temp;
}
}
}
}
void ColorToBytes( const float *color, byte *colorBytes, float scale )
{
ColorToBytesDeluxe(color, colorBytes, scale, NULL, NULL);
} }
@ -1863,7 +1911,8 @@ void IlluminateRawLightmap( int rawLightmapNum )
float brightness; float brightness;
float *origin, *normal, *dirt, *luxel, *luxel2, *deluxel, *deluxel2; float *origin, *normal, *dirt, *luxel, *luxel2, *deluxel, *deluxel2;
float *lightLuxels, *lightLuxel, samples, filterRadius, weight; float *lightLuxels, *lightLuxel, samples, filterRadius, weight;
vec3_t color, averageColor, averageDir, total, temp, temp2; vec3_t color, averageColor, total, temp, temp2;
float averageDir[4];
float tests[ 4 ][ 2 ] = { { 0.0f, 0 }, { 1, 0 }, { 0, 1 }, { 1, 1 } }; float tests[ 4 ][ 2 ] = { { 0.0f, 0 }, { 1, 0 }, { 0, 1 }, { 1, 1 } };
trace_t trace; trace_t trace;
float stackLightLuxels[ STACK_LL_SIZE ]; float stackLightLuxels[ STACK_LL_SIZE ];
@ -2103,9 +2152,12 @@ void IlluminateRawLightmap( int rawLightmapNum )
/* color to grayscale (photoshop rgb weighting) */ /* color to grayscale (photoshop rgb weighting) */
brightness = trace.color[ 0 ] * 0.3f + trace.color[ 1 ] * 0.59f + trace.color[ 2 ] * 0.11f; brightness = trace.color[ 0 ] * 0.3f + trace.color[ 1 ] * 0.59f + trace.color[ 2 ] * 0.11f;
brightness *= (1.0 / 255.0); brightness *= (1.0 / 255.0);
VectorScale( trace.direction, brightness, temp ); if(brightness != 0)
VectorAdd( deluxel, temp, deluxel ); {
deluxel[3] += brightness; VectorScale( trace.direction, brightness, temp );
VectorAdd( deluxel, temp, deluxel );
deluxel[3] += brightness;
}
} }
} }
} }
@ -2487,6 +2539,7 @@ void IlluminateRawLightmap( int rawLightmapNum )
/* choose seed amount */ /* choose seed amount */
VectorClear( averageColor ); VectorClear( averageColor );
VectorClear( averageDir ); VectorClear( averageDir );
averageDir[3] = 0.0f;
samples = 0.0f; samples = 0.0f;
/* walk 3x3 matrix */ /* walk 3x3 matrix */
@ -2514,7 +2567,10 @@ void IlluminateRawLightmap( int rawLightmapNum )
VectorAdd( averageColor, luxel2, averageColor ); VectorAdd( averageColor, luxel2, averageColor );
samples += luxel2[ 3 ]; samples += luxel2[ 3 ];
if( filterDir ) if( filterDir )
{
VectorAdd( averageDir, deluxel2, averageDir ); VectorAdd( averageDir, deluxel2, averageDir );
averageDir[3] += deluxel2[3];
}
} }
} }
@ -2537,7 +2593,10 @@ void IlluminateRawLightmap( int rawLightmapNum )
luxel[ 3 ] = 1.0f; luxel[ 3 ] = 1.0f;
} }
if( filterDir ) if( filterDir )
{
VectorDivide( averageDir, samples, deluxel ); VectorDivide( averageDir, samples, deluxel );
deluxel[3] = averageDir[3] / samples;
}
/* set cluster to -3 */ /* set cluster to -3 */
if( *cluster < 0 ) if( *cluster < 0 )

View File

@ -2167,41 +2167,10 @@ static void FindOutLightmaps( rawLightmap_t *lm )
/* store color */ /* store color */
pixel = olm->bspLightBytes + (((oy * olm->customWidth) + ox) * 3); pixel = olm->bspLightBytes + (((oy * olm->customWidth) + ox) * 3);
ColorToBytes( color, pixel, lm->brightness ); if(deluxemap)
ColorToBytesDeluxe( color, pixel, lm->brightness, deluxel, olm->bspDirBytes + (((oy * olm->customWidth) + ox) * 3));
/* store direction */ else
if( deluxemap ) ColorToBytes( color, pixel, lm->brightness );
{
if(normalizeDeluxemap)
{
if(!VectorNormalize(deluxel, direction))
VectorClear(direction);
}
else
{
if(deluxel[3])
VectorScale(deluxel, 1 / deluxel[3], direction);
else
VectorClear(direction);
}
/* normalize average light direction */
if(direction[0] != 0 || direction[1] != 0 || direction[2] != 0)
{
/* encode [-1,1] in [0,255] */
pixel = olm->bspDirBytes + (((oy * olm->customWidth) + ox) * 3);
for( i = 0; i < 3; i++ )
{
temp = (direction[ i ] + 1.0f) * 127.5f;
if( temp < 0 )
pixel[ i ] = 0;
else if( temp > 255 )
pixel[ i ] = 255;
else
pixel[ i ] = temp;
}
}
}
} }
} }
} }
@ -2363,7 +2332,10 @@ void StoreSurfaceLightmaps( void )
/* sample deluxemap */ /* sample deluxemap */
if( deluxemap && lightmapNum == 0 ) if( deluxemap && lightmapNum == 0 )
{
VectorAdd( dirSample, deluxel, dirSample ); VectorAdd( dirSample, deluxel, dirSample );
dirSample[3] += deluxel[3];
}
/* keep track of used/occluded samples */ /* keep track of used/occluded samples */
if( *cluster != CLUSTER_UNMAPPED ) if( *cluster != CLUSTER_UNMAPPED )
@ -2429,7 +2401,10 @@ void StoreSurfaceLightmaps( void )
/* store light direction */ /* store light direction */
if( deluxemap && lightmapNum == 0 ) if( deluxemap && lightmapNum == 0 )
{
VectorCopy( dirSample, deluxel ); VectorCopy( dirSample, deluxel );
dirSample[3] = deluxel[3];
}
/* store the sample back in super luxels */ /* store the sample back in super luxels */
if( samples > 0.01f ) if( samples > 0.01f )
@ -2472,7 +2447,10 @@ void StoreSurfaceLightmaps( void )
/* copy light direction */ /* copy light direction */
if( deluxemap && lightmapNum == 0 ) if( deluxemap && lightmapNum == 0 )
{
VectorCopy( deluxel, dirSample ); VectorCopy( deluxel, dirSample );
dirSample[3] = deluxel[3];
}
/* is this a valid sample? */ /* is this a valid sample? */
if( luxel[ 3 ] > 0.0f ) if( luxel[ 3 ] > 0.0f )
@ -2556,7 +2534,10 @@ void StoreSurfaceLightmaps( void )
VectorAdd( bspLuxel, sample, bspLuxel ); VectorAdd( bspLuxel, sample, bspLuxel );
if( deluxemap && lightmapNum == 0 ) if( deluxemap && lightmapNum == 0 )
{
VectorAdd( bspDeluxel, dirSample, bspDeluxel ); VectorAdd( bspDeluxel, dirSample, bspDeluxel );
bspDeluxel[3] += dirSample[3];
}
/* add color to bounds for solid checking */ /* add color to bounds for solid checking */
if( samples > 0.0f ) if( samples > 0.0f )
@ -2612,6 +2593,7 @@ void StoreSurfaceLightmaps( void )
VectorAdd( bspDeluxel, bspDeluxel2, bspDeluxel ); VectorAdd( bspDeluxel, bspDeluxel2, bspDeluxel );
VectorScale( bspDeluxel, 0.5f, bspDeluxel ); VectorScale( bspDeluxel, 0.5f, bspDeluxel );
VectorCopy( bspDeluxel, bspDeluxel2 ); VectorCopy( bspDeluxel, bspDeluxel2 );
bspDeluxel2[3] = bspDeluxel[3] = (bspDeluxel[3] + bspDeluxel2[3]) * 0.5f;
} }
} }
} }
@ -2631,6 +2613,7 @@ void StoreSurfaceLightmaps( void )
VectorAdd( bspDeluxel, bspDeluxel2, bspDeluxel ); VectorAdd( bspDeluxel, bspDeluxel2, bspDeluxel );
VectorScale( bspDeluxel, 0.5f, bspDeluxel ); VectorScale( bspDeluxel, 0.5f, bspDeluxel );
VectorCopy( bspDeluxel, bspDeluxel2 ); VectorCopy( bspDeluxel, bspDeluxel2 );
bspDeluxel2[3] = bspDeluxel[3] = (bspDeluxel[3] + bspDeluxel2[3]) * 0.5f;
} }
} }
} }

View File

@ -266,7 +266,7 @@ constants
#define SUPER_ORIGIN_SIZE 3 #define SUPER_ORIGIN_SIZE 3
#define SUPER_NORMAL_SIZE 4 #define SUPER_NORMAL_SIZE 4
#define SUPER_DELUXEL_SIZE 4 #define SUPER_DELUXEL_SIZE 4
#define BSP_DELUXEL_SIZE 3 #define BSP_DELUXEL_SIZE 4
#define SUPER_FLOODLIGHT_SIZE 1 #define SUPER_FLOODLIGHT_SIZE 1
#define VERTEX_LUXEL( s, v ) (vertexLuxels[ s ] + ((v) * VERTEX_LUXEL_SIZE)) #define VERTEX_LUXEL( s, v ) (vertexLuxels[ s ] + ((v) * VERTEX_LUXEL_SIZE))
@ -1714,6 +1714,7 @@ void RadFreeLights();
/* light_ydnar.c */ /* light_ydnar.c */
void ColorToBytes( const float *color, byte *colorBytes, float scale ); void ColorToBytes( const float *color, byte *colorBytes, float scale );
void ColorToBytesDeluxe( const float *color, byte *colorBytes, float scale, const float *deluxel, byte *deluxeBytes );
void SmoothNormals( void ); void SmoothNormals( void );
void MapRawLightmap( int num ); void MapRawLightmap( int num );