]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/light_ydnar.c
remove not-normalized deluxemap support again - it did not look any better, still...
[xonotic/netradiant.git] / tools / quake3 / q3map2 / light_ydnar.c
index 54a4ca761b0ea125176b43b7abf23ac03a236f07..a206a0397c9032bc1b2ed19e2656c6027a67093a 100644 (file)
@@ -44,14 +44,12 @@ ColorToBytes()
 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 */
@@ -66,7 +64,7 @@ void ColorToBytesDeluxe( const float *color, byte *colorBytes, float scale, cons
        for( i = 0; i < 3; i++ )
        {
                /* handle negative light */
-               if( sample[ i ] <= 0.0f )
+               if( sample[ i ] < 0.0f )
                {
                        sample[ i ] = 0.0f;
                        continue;
@@ -76,8 +74,6 @@ void ColorToBytesDeluxe( const float *color, byte *colorBytes, float scale, cons
                sample[ i ] = pow( sample[ i ] / 255.0f, gamma ) * 255.0f;
        }
 
-       colorMultiplier = 1;
-
        if (lightmapExposure == 1)
        {
                /* clamp with color normalization */
@@ -86,15 +82,16 @@ void ColorToBytesDeluxe( const float *color, byte *colorBytes, float scale, cons
                        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 ];
@@ -102,7 +99,6 @@ void ColorToBytesDeluxe( const float *color, byte *colorBytes, float scale, cons
                        max = sample[ 1 ];
                if( sample[ 2 ] > max )
                        max = sample[ 2 ];
-               max *= colorMultiplier;
 
                dif = (1-  exp(-max * inv) )  *  255;
 
@@ -115,64 +111,20 @@ void ColorToBytesDeluxe( const float *color, byte *colorBytes, float scale, cons
                        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);
 }
 
 
@@ -1911,8 +1863,7 @@ void IlluminateRawLightmap( int rawLightmapNum )
        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 ];
@@ -2056,10 +2007,7 @@ void IlluminateRawLightmap( int rawLightmapNum )
                                {
                                        VectorCopy( ambientColor, luxel );
                                        if( deluxemap )
-                                       {
                                                VectorScale( normal, 0.00390625f, deluxel );
-                                               deluxel[3] = 0.00390625f;
-                                       }
                                        luxel[ 3 ] = 1.0f;
                                }
                        }
@@ -2152,12 +2100,8 @@ void IlluminateRawLightmap( int rawLightmapNum )
                                                /* 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 );
                                        }
                                }
                        }
@@ -2539,7 +2483,6 @@ void IlluminateRawLightmap( int rawLightmapNum )
                                /* choose seed amount */
                                VectorClear( averageColor );
                                VectorClear( averageDir );
-                               averageDir[3] = 0.0f;
                                samples = 0.0f;
                                
                                /* walk 3x3 matrix */
@@ -2567,10 +2510,7 @@ void IlluminateRawLightmap( int rawLightmapNum )
                                                VectorAdd( averageColor, luxel2, averageColor );
                                                samples += luxel2[ 3 ];
                                                if( filterDir )
-                                               {
                                                        VectorAdd( averageDir, deluxel2, averageDir );
-                                                       averageDir[3] += deluxel2[3];
-                                               }
                                        }
                                }
                                
@@ -2593,10 +2533,7 @@ void IlluminateRawLightmap( int rawLightmapNum )
                                        luxel[ 3 ] = 1.0f;
                                }
                                if( filterDir )
-                               {
                                        VectorDivide( averageDir, samples, deluxel );
-                                       deluxel[3] = averageDir[3] / samples;
-                               }
                                
                                /* set cluster to -3 */
                                if( *cluster < 0 )