]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/lightmaps_ydnar.c
no, we do NOT want to ignore caulk
[xonotic/netradiant.git] / tools / quake3 / q3map2 / lightmaps_ydnar.c
index e067114793d4611483c50215a9da98d7e7a8c5c3..5c5340534e14f60a87c6557327a097f67ca2e375 100644 (file)
@@ -291,8 +291,8 @@ static int CompareLightSurface( const void *a, const void *b )
        
        
        /* get shaders */
-       asi = surfaceInfos[ *((int*) a) ].si;
-       bsi = surfaceInfos[ *((int*) b) ].si;
+       asi = surfaceInfos[ *((const int*) a) ].si;
+       bsi = surfaceInfos[ *((const int*) b) ].si;
        
        /* dummy check */
        if( asi == NULL )
@@ -593,10 +593,10 @@ based on AllocateLightmapForSurface()
 qboolean AddSurfaceToRawLightmap( int num, rawLightmap_t *lm )
 {
        bspDrawSurface_t        *ds, *ds2;
-       surfaceInfo_t           *info, *info2;
+       surfaceInfo_t           *info;
        int                                     num2, n, i, axisNum;
        float                           s, t, d, len, sampleSize;
-       vec3_t                          mins, maxs, origin, faxis, size, exactSize, delta, normalized, vecs[ 2 ];
+       vec3_t                          mins, maxs, origin, faxis, size, delta, normalized, vecs[ 2 ];
        vec4_t                          plane;
        bspDrawVert_t           *verts;
        
@@ -672,18 +672,30 @@ qboolean AddSurfaceToRawLightmap( int num, rawLightmap_t *lm )
        /* round to the lightmap resolution */
        for( i = 0; i < 3; i++ )
        {
-               exactSize[ i ] = lm->maxs[ i ] - lm->mins[ i ];
                mins[ i ] = sampleSize * floor( lm->mins[ i ] / sampleSize );
                maxs[ i ] = sampleSize * ceil( lm->maxs[ i ] / sampleSize );
                size[ i ] = (maxs[ i ] - mins[ i ]) / sampleSize + 1.0f;
                
                /* hack (god this sucks) */
-               if( size[ i ] > lm->customWidth || size[ i ] > lm->customHeight )
+               if( size[ i ] > lm->customWidth || size[ i ] > lm->customHeight  || (lmLimitSize && size[i] > lmLimitSize))
                {
                        i = -1;
                        sampleSize += 1.0f;
                }
        }
+
+       if(sampleSize != lm->sampleSize && lmLimitSize == 0)
+       {
+               Sys_FPrintf(SYS_VRB,"WARNING: surface at (%6.0f %6.0f %6.0f) (%6.0f %6.0f %6.0f) too large for desired samplesize/lightmapsize/lightmapscale combination, increased samplesize from %d to %d\n",
+                       info->mins[0],
+                       info->mins[1],
+                       info->mins[2],
+                       info->maxs[0],
+                       info->maxs[1],
+                       info->maxs[2],
+                       lm->sampleSize,
+                       (int) sampleSize);
+       }
        
        /* set actual sample size */
        lm->actualSampleSize = sampleSize;
@@ -750,7 +762,6 @@ qboolean AddSurfaceToRawLightmap( int num, rawLightmap_t *lm )
                /* get surface */
                num2 = lightSurfaces[ lm->firstLightSurface + n ];
                ds2 = &bspDrawSurfaces[ num2 ];
-               info2 = &surfaceInfos[ num2 ];
                verts = &yDrawVerts[ ds2->firstVert ];
                
                /* set the lightmap texture coordinates in yDrawVerts in [0, superSample * lm->customWidth] space */
@@ -773,7 +784,6 @@ qboolean AddSurfaceToRawLightmap( int num, rawLightmap_t *lm )
        /* get first drawsurface */
        num2 = lightSurfaces[ lm->firstLightSurface ];
        ds2 = &bspDrawSurfaces[ num2 ];
-       info2 = &surfaceInfos[ num2 ];
        verts = &yDrawVerts[ ds2->firstVert ];
        
        /* calculate lightmap origin */
@@ -848,13 +858,13 @@ static int CompareSurfaceInfo( const void *a, const void *b )
        
 
        /* get surface info */
-       aInfo = &surfaceInfos[ *((int*) a) ];
-       bInfo = &surfaceInfos[ *((int*) b) ];
+       aInfo = &surfaceInfos[ *((const int*) a) ];
+       bInfo = &surfaceInfos[ *((const int*) b) ];
        
        /* model first */
-       if( aInfo->model < bInfo->model )
+       if( aInfo->modelindex < bInfo->modelindex )
                return 1;
-       else if( aInfo->model > bInfo->model )
+       else if( aInfo->modelindex > bInfo->modelindex )
                return -1;
        
        /* then lightmap status */
@@ -862,6 +872,13 @@ static int CompareSurfaceInfo( const void *a, const void *b )
                return 1;
        else if( aInfo->hasLightmap > bInfo->hasLightmap )
                return -1;
+
+   /* 27: then shader! */
+   if (aInfo->si < bInfo->si)
+       return 1;
+   else if (aInfo->si > bInfo->si)
+      return -1;
+       
        
        /* then lightmap sample size */
        if( aInfo->sampleSize < bInfo->sampleSize )
@@ -920,7 +937,7 @@ void SetupSurfaceLightmaps( void )
        int                                     i, j, k, s,num, num2;
        bspModel_t                      *model;
        bspLeaf_t                       *leaf;
-       bspDrawSurface_t        *ds, *ds2;
+       bspDrawSurface_t        *ds;
        surfaceInfo_t           *info, *info2;
        rawLightmap_t           *lm;
        qboolean                        added;
@@ -984,7 +1001,7 @@ void SetupSurfaceLightmaps( void )
                                VectorClear( entityOrigin );
                        
                        /* basic setup */
-                       info->model = model;
+                       info->modelindex = i;
                        info->lm = NULL;
                        info->plane = NULL;
                        info->firstSurfaceCluster = numSurfaceClusters;
@@ -1098,12 +1115,20 @@ void SetupSurfaceLightmaps( void )
                lm->splotchFix = info->si->splotchFix;
                lm->firstLightSurface = numLightSurfaces;
                lm->numLightSurfaces = 0;
-               lm->sampleSize = info->sampleSize;
-               lm->actualSampleSize = info->sampleSize;
+               /* vortex: multiply lightmap sample size by -samplescale */
+               if (sampleScale > 0)
+                       lm->sampleSize = info->sampleSize*sampleScale;
+               else
+                       lm->sampleSize = info->sampleSize;
+               lm->actualSampleSize = lm->sampleSize;
                lm->entityNum = info->entityNum;
                lm->recvShadows = info->recvShadows;
                lm->brightness = info->si->lmBrightness;
                lm->filterRadius = info->si->lmFilterRadius;
+               VectorCopy(info->si->floodlightRGB, lm->floodlightRGB);
+               lm->floodlightDistance = info->si->floodlightDistance;
+               lm->floodlightIntensity = info->si->floodlightIntensity;
+               lm->floodlightDirectionScale = info->si->floodlightDirectionScale;
                VectorCopy( info->axis, lm->axis );
                lm->plane = info->plane;        
                VectorCopy( info->mins, lm->mins );
@@ -1126,7 +1151,6 @@ void SetupSurfaceLightmaps( void )
                        {
                                /* get info and attempt early out */
                                num2 = sortSurfaces[ j ];
-                               ds2 = &bspDrawSurfaces[ num2 ];
                                info2 = &surfaceInfos[ num2 ];
                                if( info2->hasLightmap == qfalse || info2->lm != NULL )
                                        continue;
@@ -1187,7 +1211,7 @@ void StitchSurfaceLightmaps( void )
                                        numStitched, numCandidates, numLuxels, f, fOld, start;
        rawLightmap_t   *lm, *a, *b, *c[ MAX_STITCH_CANDIDATES ];
        float                   *luxel, *luxel2, *origin, *origin2, *normal, *normal2, 
-                                       sampleSize, average[ 3 ], totalColor, ootc, *luxels[ MAX_STITCH_LUXELS ];
+                                       sampleSize, average[ 3 ], totalColor, ootc;
        
        
        /* disabled for now */
@@ -1302,7 +1326,6 @@ void StitchSurfaceLightmaps( void )
                                                        
                                                        /* add luxel */
                                                        //%     VectorSet( luxel2, 255, 0, 255 );
-                                                       luxels[ numLuxels++ ] = luxel2;
                                                        VectorAdd( average, luxel2, average );
                                                        totalColor += luxel2[ 3 ];
                                                }
@@ -1890,9 +1913,10 @@ FindOutLightmaps()
 for a given surface lightmap, find output lightmap pages and positions for it
 */
 
+#define LIGHTMAP_RESERVE_COUNT 1
 static void FindOutLightmaps( rawLightmap_t *lm )
 {
-       int                                     i, j, lightmapNum, xMax, yMax, x, y, sx, sy, ox, oy, offset, temp;
+       int                                     i, j, k, lightmapNum, xMax, yMax, x = -1, y = -1, sx, sy, ox, oy, offset;
        outLightmap_t           *olm;
        surfaceInfo_t           *info;
        float                           *luxel, *deluxel;
@@ -1987,7 +2011,11 @@ static void FindOutLightmaps( rawLightmap_t *lm )
                        y = 0;
                        
                        /* walk the list of lightmap pages */
-                       for( i = 0; i < numOutLightmaps; i++ )
+                       if(lightmapSearchBlockSize <= 0 || numOutLightmaps < LIGHTMAP_RESERVE_COUNT)
+                               i = 0;
+                       else
+                               i = ((numOutLightmaps - LIGHTMAP_RESERVE_COUNT) / lightmapSearchBlockSize) * lightmapSearchBlockSize;
+                       for( ; i < numOutLightmaps; i++ )
                        {
                                /* get the output lightmap */
                                olm = &outLightmaps[ i ];
@@ -2041,22 +2069,22 @@ static void FindOutLightmaps( rawLightmap_t *lm )
                /* no match? */
                if( ok == qfalse )
                {
-                       /* allocate two new output lightmaps */
-                       numOutLightmaps += 2;
+                       /* allocate LIGHTMAP_RESERVE_COUNT new output lightmaps */
+                       numOutLightmaps += LIGHTMAP_RESERVE_COUNT;
                        olm = safe_malloc( numOutLightmaps * sizeof( outLightmap_t ) );
-                       if( outLightmaps != NULL && numOutLightmaps > 2 )
+                       if( outLightmaps != NULL && numOutLightmaps > LIGHTMAP_RESERVE_COUNT )
                        {
-                               memcpy( olm, outLightmaps, (numOutLightmaps - 2) * sizeof( outLightmap_t ) );
+                               memcpy( olm, outLightmaps, (numOutLightmaps - LIGHTMAP_RESERVE_COUNT) * sizeof( outLightmap_t ) );
                                free( outLightmaps );
                        }
                        outLightmaps = olm;
                        
                        /* initialize both out lightmaps */
-                       SetupOutLightmap( lm, &outLightmaps[ numOutLightmaps - 2 ] );
-                       SetupOutLightmap( lm, &outLightmaps[ numOutLightmaps - 1 ] );
+                       for(k = numOutLightmaps - LIGHTMAP_RESERVE_COUNT; k < numOutLightmaps; ++k)
+                               SetupOutLightmap( lm, &outLightmaps[ k ] );
                        
                        /* set out lightmap */
-                       i = numOutLightmaps - 2;
+                       i = numOutLightmaps - LIGHTMAP_RESERVE_COUNT;
                        olm = &outLightmaps[ i ];
                        
                        /* set stamp xy origin to the first surface lightmap */
@@ -2160,21 +2188,12 @@ static void FindOutLightmaps( rawLightmap_t *lm )
                                if( deluxemap )
                                {
                                        /* normalize average light direction */
-                                       if( VectorNormalize( deluxel, direction ) )
-                                       {
-                                               /* 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;
-                                               }
-                                       }
+                                       pixel = olm->bspDirBytes + (((oy * olm->customWidth) + ox) * 3);
+                                       VectorScale( deluxel, 1000.0f, direction );
+                                       VectorNormalize( direction, direction );
+                                       VectorScale( direction, 127.5f, direction );
+                                       for( i = 0; i < 3; i++ )
+                                               pixel[ i ] = (byte)( 127.5f + direction[ i ] );
                                }
                        }
                }
@@ -2196,8 +2215,8 @@ static int CompareRawLightmap( const void *a, const void *b )
        
        
        /* get lightmaps */
-       alm = &rawLightmaps[ *((int*) a) ];
-       blm = &rawLightmaps[ *((int*) b) ];
+       alm = &rawLightmaps[ *((const int*) a) ];
+       blm = &rawLightmaps[ *((const int*) b) ];
        
        /* get min number of surfaces */
        min = (alm->numLightSurfaces < blm->numLightSurfaces ? alm->numLightSurfaces : blm->numLightSurfaces);
@@ -2231,7 +2250,112 @@ static int CompareRawLightmap( const void *a, const void *b )
        return 0;
 }
 
+void FillOutLightmap(outLightmap_t *olm)
+{
+       int x, y;
+       int ofs;
+       vec3_t dir_sum, light_sum;
+       int cnt, filled;
+       byte *lightBitsNew = NULL;
+       byte *lightBytesNew = NULL;
+       byte *dirBytesNew = NULL;
+
+       lightBitsNew = safe_malloc((olm->customWidth * olm->customHeight + 8) / 8);
+       lightBytesNew = safe_malloc(olm->customWidth * olm->customHeight * 3);
+       if(deluxemap)
+               dirBytesNew = safe_malloc(olm->customWidth * olm->customHeight * 3);
+
+       /*
+       memset(olm->lightBits, 0, (olm->customWidth * olm->customHeight + 8) / 8);
+               olm->lightBits[0] |= 1;
+               olm->lightBits[(10 * olm->customWidth + 30) >> 3] |= 1 << ((10 * olm->customWidth + 30) & 7);
+       memset(olm->bspLightBytes, 0, olm->customWidth * olm->customHeight * 3);
+               olm->bspLightBytes[0] = 255;
+               olm->bspLightBytes[(10 * olm->customWidth + 30) * 3 + 2] = 255;
+       */
+
+       memcpy(lightBitsNew, olm->lightBits, (olm->customWidth * olm->customHeight + 8) / 8);
+       memcpy(lightBytesNew, olm->bspLightBytes, olm->customWidth * olm->customHeight * 3);
+       if(deluxemap)
+               memcpy(dirBytesNew, olm->bspDirBytes, olm->customWidth * olm->customHeight * 3);
+
+       for(;;)
+       {
+               filled = 0;
+               for(y = 0; y < olm->customHeight; ++y)
+               {
+                       for(x = 0; x < olm->customWidth; ++x)
+                       {
+                               ofs = y * olm->customWidth + x;
+                               if(olm->lightBits[ofs >> 3] & (1 << (ofs & 7))) /* already filled */
+                                       continue;
+                               cnt = 0;
+                               VectorClear(dir_sum);
+                               VectorClear(light_sum);
+
+                               /* try all four neighbors */
+                               ofs = ((y + olm->customHeight - 1) % olm->customHeight) * olm->customWidth + x;
+                               if(olm->lightBits[ofs >> 3] & (1 << (ofs & 7))) /* already filled */
+                               {
+                                       ++cnt;
+                                       VectorAdd(light_sum, olm->bspLightBytes + ofs * 3, light_sum);
+                                       if(deluxemap)
+                                               VectorAdd(dir_sum, olm->bspDirBytes + ofs * 3, dir_sum);
+                               }
+
+                               ofs = ((y + 1) % olm->customHeight) * olm->customWidth + x;
+                               if(olm->lightBits[ofs >> 3] & (1 << (ofs & 7))) /* already filled */
+                               {
+                                       ++cnt;
+                                       VectorAdd(light_sum, olm->bspLightBytes + ofs * 3, light_sum);
+                                       if(deluxemap)
+                                               VectorAdd(dir_sum, olm->bspDirBytes + ofs * 3, dir_sum);
+                               }
+
+                               ofs = y * olm->customWidth + (x + olm->customWidth - 1) % olm->customWidth;
+                               if(olm->lightBits[ofs >> 3] & (1 << (ofs & 7))) /* already filled */
+                               {
+                                       ++cnt;
+                                       VectorAdd(light_sum, olm->bspLightBytes + ofs * 3, light_sum);
+                                       if(deluxemap)
+                                               VectorAdd(dir_sum, olm->bspDirBytes + ofs * 3, dir_sum);
+                               }
+
+                               ofs = y * olm->customWidth + (x + 1) % olm->customWidth;
+                               if(olm->lightBits[ofs >> 3] & (1 << (ofs & 7))) /* already filled */
+                               {
+                                       ++cnt;
+                                       VectorAdd(light_sum, olm->bspLightBytes + ofs * 3, light_sum);
+                                       if(deluxemap)
+                                               VectorAdd(dir_sum, olm->bspDirBytes + ofs * 3, dir_sum);
+                               }
+
+                               if(cnt)
+                               {
+                                       ++filled;
+                                       ofs = y * olm->customWidth + x;
+                                       lightBitsNew[ofs >> 3] |= (1 << (ofs & 7));
+                                       VectorScale(light_sum, 1.0/cnt, lightBytesNew + ofs * 3);
+                                       if(deluxemap)
+                                               VectorScale(dir_sum, 1.0/cnt, dirBytesNew + ofs * 3);
+                               }
+                       }
+               }
 
+               if(!filled)
+                       break;
+
+               memcpy(olm->lightBits, lightBitsNew, (olm->customWidth * olm->customHeight + 8) / 8);
+               memcpy(olm->bspLightBytes, lightBytesNew, olm->customWidth * olm->customHeight * 3);
+               if(deluxemap)
+                       memcpy(olm->bspDirBytes, dirBytesNew, olm->customWidth * olm->customHeight * 3);
+       }
+
+       free(lightBitsNew);
+       free(lightBytesNew);
+       if(deluxemap)
+               free(dirBytesNew);
+}
 
 /*
 StoreSurfaceLightmaps()
@@ -2257,16 +2381,23 @@ void StoreSurfaceLightmaps( void )
        char                            dirname[ 1024 ], filename[ 1024 ];
        shaderInfo_t            *csi;
        char                            lightmapName[ 128 ];
-       char                            *rgbGenValues[ 256 ];
-       char                            *alphaGenValues[ 256 ];
+       const char                              *rgbGenValues[ 256 ];
+       const char                              *alphaGenValues[ 256 ];
        
        
        /* note it */
        Sys_Printf( "--- StoreSurfaceLightmaps ---\n");
        
        /* setup */
-       strcpy( dirname, source );
-       StripExtension( dirname );
+       if(lmCustomDir)
+       {
+               strcpy( dirname, lmCustomDir );
+       }
+       else
+       {
+               strcpy( dirname, source );
+               StripExtension( dirname );
+       }
        memset( rgbGenValues, 0, sizeof( rgbGenValues ) );
        memset( alphaGenValues, 0, sizeof( alphaGenValues ) );
        
@@ -2275,7 +2406,7 @@ void StoreSurfaceLightmaps( void )
           ----------------------------------------------------------------- */
        
        /* note it */
-       Sys_FPrintf( SYS_VRB, "Subsampling..." );
+       Sys_Printf( "Subsampling..." );
        
        /* walk the list of raw lightmaps */
        numUsed = 0;
@@ -2611,6 +2742,135 @@ void StoreSurfaceLightmaps( void )
                }
        }
        
+       /* -----------------------------------------------------------------
+          convert modelspace deluxemaps to tangentspace
+          ----------------------------------------------------------------- */
+       /* note it */
+       if( !bouncing )
+       {
+               if( deluxemap && deluxemode == 1)
+               {
+                       vec3_t  worldUp, myNormal, myTangent, myBinormal;
+                       float dist;
+
+                       Sys_Printf( "converting..." );
+
+                       for( i = 0; i < numRawLightmaps; i++ )
+                       {
+                               /* get lightmap */
+                               lm = &rawLightmaps[ i ];
+
+                               /* walk lightmap samples */
+                               for( y = 0; y < lm->sh; y++ )
+                               {
+                                       for( x = 0; x < lm->sw; x++ )
+                                       {
+                                               /* get normal and deluxel */
+                                               normal = SUPER_NORMAL(x, y);
+                                               cluster = SUPER_CLUSTER(x, y);
+                                               bspDeluxel = BSP_DELUXEL( x, y );
+                                               deluxel = SUPER_DELUXEL( x, y ); 
+
+                                               /* get normal */
+                                               VectorSet( myNormal, normal[0], normal[1], normal[2] );
+               
+                                               /* get tangent vectors */
+                                               if( myNormal[ 0 ] == 0.0f && myNormal[ 1 ] == 0.0f )
+                                               {
+                                                       if( myNormal[ 2 ] == 1.0f )             
+                                                       {
+                                                               VectorSet( myTangent, 1.0f, 0.0f, 0.0f );
+                                                               VectorSet( myBinormal, 0.0f, 1.0f, 0.0f );
+                                                       }
+                                                       else if( myNormal[ 2 ] == -1.0f )
+                                                       {
+                                                               VectorSet( myTangent, -1.0f, 0.0f, 0.0f );
+                                                               VectorSet( myBinormal,  0.0f, 1.0f, 0.0f );
+                                                       }
+                                               }
+                                               else
+                                               {
+                                                       VectorSet( worldUp, 0.0f, 0.0f, 1.0f );
+                                                       CrossProduct( myNormal, worldUp, myTangent );
+                                                       VectorNormalize( myTangent, myTangent );
+                                                       CrossProduct( myTangent, myNormal, myBinormal );
+                                                       VectorNormalize( myBinormal, myBinormal );
+                                               }
+
+                                               /* project onto plane */
+                                               dist = -DotProduct(myTangent, myNormal); 
+                                               VectorMA(myTangent, dist, myNormal, myTangent);
+                                               dist = -DotProduct(myBinormal, myNormal); 
+                                               VectorMA(myBinormal, dist, myNormal, myBinormal);
+
+                                               /* renormalize */
+                                               VectorNormalize( myTangent, myTangent );
+                                               VectorNormalize( myBinormal, myBinormal );
+
+                                               /* convert modelspace deluxel to tangentspace */
+                                               dirSample[0] = bspDeluxel[0];
+                                               dirSample[1] = bspDeluxel[1];
+                                               dirSample[2] = bspDeluxel[2];
+                                               VectorNormalize(dirSample, dirSample);
+
+                                               /* fix tangents to world matrix */
+                                               if (myNormal[0] > 0 || myNormal[1] < 0 || myNormal[2] < 0)
+                                                       VectorNegate(myTangent, myTangent);
+
+                                               /* build tangentspace vectors */
+                                               bspDeluxel[0] = DotProduct(dirSample, myTangent);
+                                               bspDeluxel[1] = DotProduct(dirSample, myBinormal);
+                                               bspDeluxel[2] = DotProduct(dirSample, myNormal);
+                                       }
+                               }
+                       }
+               }
+       }
+
+       /* -----------------------------------------------------------------
+          blend lightmaps
+          ----------------------------------------------------------------- */
+
+#ifdef sdfsdfwq312323
+       /* note it */
+       Sys_Printf( "blending..." );
+
+       for( i = 0; i < numRawLightmaps; i++ )
+       {
+               vec3_t  myColor;
+               float myBrightness;
+
+               /* get lightmap */
+               lm = &rawLightmaps[ i ];
+
+               /* walk individual lightmaps */
+               for( lightmapNum = 0; lightmapNum < MAX_LIGHTMAPS; lightmapNum++ )
+               {
+                       /* early outs */
+                       if( lm->superLuxels[ lightmapNum ] == NULL )
+                               continue;
+
+                       /* walk lightmap samples */
+                       for( y = 0; y < lm->sh; y++ )
+                       {
+                               for( x = 0; x < lm->sw; x++ )
+                               {
+                                       /* get luxel */
+                                       bspLuxel = BSP_LUXEL( lightmapNum, x, y );
+
+                                       /* get color */
+                                       VectorNormalize(bspLuxel, myColor);
+                                       myBrightness = VectorLength(bspLuxel);
+                                       myBrightness *= (1 / 127.0f);
+                                       myBrightness = myBrightness*myBrightness;
+                                       myBrightness *= 127.0f;
+                                       VectorScale(myColor, myBrightness, bspLuxel);
+                               }
+                       }
+               }
+       }
+#endif
+
        /* -----------------------------------------------------------------
           collapse non-unique lightmaps
           ----------------------------------------------------------------- */
@@ -2618,7 +2878,7 @@ void StoreSurfaceLightmaps( void )
        if( noCollapse == qfalse && deluxemap == qfalse )
        {
                /* note it */
-               Sys_FPrintf( SYS_VRB, "collapsing..." );
+               Sys_Printf( "collapsing..." );
                
                /* set all twin refs to null */
                for( i = 0; i < numRawLightmaps; i++ )
@@ -2686,7 +2946,7 @@ void StoreSurfaceLightmaps( void )
           ----------------------------------------------------------------- */
        
        /* note it */
-       Sys_FPrintf( SYS_VRB, "sorting..." );
+       Sys_Printf( "sorting..." );
        
        /* allocate a new sorted list */
        if( sortLightmaps == NULL )
@@ -2702,7 +2962,7 @@ void StoreSurfaceLightmaps( void )
           ----------------------------------------------------------------- */
        
        /* note it */
-       Sys_FPrintf( SYS_VRB, "allocating..." );
+       Sys_Printf( "allocating..." );
        
        /* kill all existing output lightmaps */
        if( outLightmaps != NULL )
@@ -2755,7 +3015,7 @@ void StoreSurfaceLightmaps( void )
           ----------------------------------------------------------------- */
        
        /* note it */
-       Sys_FPrintf( SYS_VRB, "storing..." );
+       Sys_Printf( "storing..." );
        
        /* count the bsp lightmaps and allocate space */
        if( bspLightBytes != NULL )
@@ -2777,6 +3037,10 @@ void StoreSurfaceLightmaps( void )
        {
                /* get output lightmap */
                olm = &outLightmaps[ i ];
+
+               /* fill output lightmap */
+               if(lightmapFill)
+                       FillOutLightmap(olm);
                
                /* is this a valid bsp lightmap? */
                if( olm->lightmapNum >= 0 && !externalLightmaps )
@@ -2823,7 +3087,7 @@ void StoreSurfaceLightmaps( void )
        }
        
        if( numExtLightmaps > 0 )
-               Sys_FPrintf( SYS_VRB, "\n" );
+               Sys_Printf( "\n" );
        
        /* delete unused external lightmaps */
        for( i = numExtLightmaps; i; i++ )
@@ -2842,7 +3106,7 @@ void StoreSurfaceLightmaps( void )
           ----------------------------------------------------------------- */
        
        /* note it */
-       Sys_FPrintf( SYS_VRB, "projecting..." );
+       Sys_Printf( "projecting..." );
        
        /* walk the list of surfaces */
        for( i = 0; i < numBSPDrawSurfaces; i++ )
@@ -3010,7 +3274,7 @@ void StoreSurfaceLightmaps( void )
                                if( rgbGenValues[ style ] == NULL )
                                {
                                        sprintf( key, "_style%drgbgen", style );
-                                       rgbGenValues[ style ] = (char*) ValueForKey( &entities[ 0 ], key );
+                                       rgbGenValues[ style ] = ValueForKey( &entities[ 0 ], key );
                                        if( rgbGenValues[ style ][ 0 ] == '\0' )
                                                rgbGenValues[ style ] = "wave noise 0.5 1 0 5.37";
                                }
@@ -3024,7 +3288,7 @@ void StoreSurfaceLightmaps( void )
                                if( alphaGenValues[ style ] == NULL )
                                {
                                        sprintf( key, "_style%dalphagen", style );
-                                       alphaGenValues[ style ] = (char*) ValueForKey( &entities[ 0 ], key );
+                                       alphaGenValues[ style ] = ValueForKey( &entities[ 0 ], key );
                                }
                                if( alphaGenValues[ style ][ 0 ] != '\0' )
                                        sprintf( alphaGen, "\t\talphaGen %s // style %d\n", alphaGenValues[ style ], style );
@@ -3114,7 +3378,7 @@ void StoreSurfaceLightmaps( void )
        }
        
        /* finish */
-       Sys_FPrintf( SYS_VRB, "done.\n" );
+       Sys_Printf( "done.\n" );
        
        /* calc num stored */
        numStored = numBSPLightBytes / 3;