ydnar: moved to here 2001-02-04
*/
-void ColorToBytesDeluxe( const float *color, byte *colorBytes, float scale, const float *deluxel, byte *deluxeBytes)
+void ColorToBytes( const float *color, byte *colorBytes, float scale )
{
int i;
float max, gamma;
- vec3_t sample, direction;
+ vec3_t sample;
float inv, dif;
- float colorMultiplier;
- float temp;
/* ydnar: scaling necessary for simulating r_overbrightBits on external lightmaps */
for( i = 0; i < 3; i++ )
{
/* handle negative light */
- if( sample[ i ] <= 0.0f )
+ if( sample[ i ] < 0.0f )
{
sample[ i ] = 0.0f;
continue;
sample[ i ] = pow( sample[ i ] / 255.0f, gamma ) * 255.0f;
}
- colorMultiplier = 1;
-
if (lightmapExposure == 1)
{
/* clamp with color normalization */
max = sample[ 1 ];
if( sample[ 2 ] > max )
max = sample[ 2 ];
- if(max * colorMultiplier > 255.0f)
- colorMultiplier *= 255.0 / max;
+ if( max > 255.0f )
+ VectorScale( sample, (255.0f / max), sample );
}
else
{
if (lightmapExposure==0)
- inv = 1.f;
- else
- inv = 1.f/lightmapExposure;
+ {
+ lightmapExposure=1.0f;
+ }
+ inv=1.f/lightmapExposure;
//Exposure
max = sample[ 0 ];
max = sample[ 1 ];
if( sample[ 2 ] > max )
max = sample[ 2 ];
- max *= colorMultiplier;
dif = (1- exp(-max * inv) ) * 255;
dif = 0;
}
- colorMultiplier *= dif;
+ for (i=0;i<3;i++)
+ {
+ sample[i]*=dif;
+ }
}
+
/* compensate for ingame overbrighting/bitshifting */
- VectorScale( sample, (colorMultiplier / lightmapCompensate), sample );
-
+ VectorScale( sample, (1.0f / lightmapCompensate), sample );
+
/* store it off */
colorBytes[ 0 ] = sample[ 0 ];
colorBytes[ 1 ] = sample[ 1 ];
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);
}
float brightness;
float *origin, *normal, *dirt, *luxel, *luxel2, *deluxel, *deluxel2;
float *lightLuxels, *lightLuxel, samples, filterRadius, weight;
- vec3_t color, averageColor, total, temp, temp2;
- float averageDir[4];
+ vec3_t color, averageColor, averageDir, total, temp, temp2;
float tests[ 4 ][ 2 ] = { { 0.0f, 0 }, { 1, 0 }, { 0, 1 }, { 1, 1 } };
trace_t trace;
float stackLightLuxels[ STACK_LL_SIZE ];
{
VectorCopy( ambientColor, luxel );
if( deluxemap )
- {
VectorScale( normal, 0.00390625f, deluxel );
- deluxel[3] = 0.00390625f;
- }
luxel[ 3 ] = 1.0f;
}
}
/* color to grayscale (photoshop rgb weighting) */
brightness = trace.color[ 0 ] * 0.3f + trace.color[ 1 ] * 0.59f + trace.color[ 2 ] * 0.11f;
brightness *= (1.0 / 255.0);
- if(brightness != 0)
- {
- VectorScale( trace.direction, brightness, temp );
- VectorAdd( deluxel, temp, deluxel );
- deluxel[3] += brightness;
- }
+ VectorScale( trace.direction, brightness, trace.direction );
+ VectorAdd( deluxel, trace.direction, deluxel );
}
}
}
/* choose seed amount */
VectorClear( averageColor );
VectorClear( averageDir );
- averageDir[3] = 0.0f;
samples = 0.0f;
/* walk 3x3 matrix */
VectorAdd( averageColor, luxel2, averageColor );
samples += luxel2[ 3 ];
if( filterDir )
- {
VectorAdd( averageDir, deluxel2, averageDir );
- averageDir[3] += deluxel2[3];
- }
}
}
luxel[ 3 ] = 1.0f;
}
if( filterDir )
- {
VectorDivide( averageDir, samples, deluxel );
- deluxel[3] = averageDir[3] / samples;
- }
/* set cluster to -3 */
if( *cluster < 0 )