bInfo = &surfaceInfos[ *((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 */
VectorClear( entityOrigin );
/* basic setup */
- info->model = model;
+ info->modelindex = i;
info->lm = NULL;
info->plane = NULL;
info->firstSurfaceCluster = numSurfaceClusters;
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 );
}
else
VectorCopy( luxel, color );
-
+
/* styles are not affected by minlight */
if( lightmapNum == 0 )
{
/* store color */
pixel = olm->bspLightBytes + (((oy * olm->customWidth) + ox) * 3);
-
- if(deluxemap)
- ColorToBytesDeluxe( color, pixel, lm->brightness, deluxel, olm->bspDirBytes + (((oy * olm->customWidth) + ox) * 3));
- else
- ColorToBytes( color, pixel, lm->brightness );
+ ColorToBytes( color, pixel, lm->brightness );
+
+ /* store direction */
+ 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;
+ }
+ }
+ }
}
}
}
int i, j, k, x, y, lx, ly, sx, sy, *cluster, mappedSamples;
int style, size, lightmapNum, lightmapNum2;
float *normal, *luxel, *bspLuxel, *bspLuxel2, *radLuxel, samples, occludedSamples;
- vec3_t sample, occludedSample, colorMins, colorMaxs;
- vec_t dirSample[4];
+ vec3_t sample, occludedSample, dirSample, colorMins, colorMaxs;
float *deluxel, *bspDeluxel, *bspDeluxel2;
byte *lb;
int numUsed, numTwins, numTwinLuxels, numStored;
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 ) );
----------------------------------------------------------------- */
/* note it */
- Sys_FPrintf( SYS_VRB, "Subsampling..." );
+ Sys_Printf( "Subsampling..." );
/* walk the list of raw lightmaps */
numUsed = 0;
/* sample deluxemap */
if( deluxemap && lightmapNum == 0 )
- {
VectorAdd( dirSample, deluxel, dirSample );
- dirSample[3] += deluxel[3];
- }
/* keep track of used/occluded samples */
if( *cluster != CLUSTER_UNMAPPED )
/* store light direction */
if( deluxemap && lightmapNum == 0 )
- {
VectorCopy( dirSample, deluxel );
- dirSample[3] = deluxel[3];
- }
/* store the sample back in super luxels */
if( samples > 0.01f )
/* get luxels */
luxel = SUPER_LUXEL( lightmapNum, x, y );
deluxel = SUPER_DELUXEL( x, y );
-
+
/* copy light direction */
if( deluxemap && lightmapNum == 0 )
- {
VectorCopy( deluxel, dirSample );
- dirSample[3] = deluxel[3];
- }
/* is this a valid sample? */
if( luxel[ 3 ] > 0.0f )
}
}
}
-
+
/* scale the sample */
VectorScale( sample, (1.0f / samples), sample );
VectorAdd( bspLuxel, sample, bspLuxel );
if( deluxemap && lightmapNum == 0 )
- {
VectorAdd( bspDeluxel, dirSample, bspDeluxel );
- bspDeluxel[3] += dirSample[3];
- }
/* add color to bounds for solid checking */
if( samples > 0.0f )
VectorAdd( bspDeluxel, bspDeluxel2, bspDeluxel );
VectorScale( bspDeluxel, 0.5f, bspDeluxel );
VectorCopy( bspDeluxel, bspDeluxel2 );
- bspDeluxel2[3] = bspDeluxel[3] = (bspDeluxel[3] + bspDeluxel2[3]) * 0.5f;
}
}
}
VectorAdd( bspDeluxel, bspDeluxel2, bspDeluxel );
VectorScale( bspDeluxel, 0.5f, bspDeluxel );
VectorCopy( bspDeluxel, bspDeluxel2 );
- bspDeluxel2[3] = bspDeluxel[3] = (bspDeluxel[3] + bspDeluxel2[3]) * 0.5f;
}
}
}
}
}
+ /* -----------------------------------------------------------------
+ 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
----------------------------------------------------------------- */
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++ )
----------------------------------------------------------------- */
/* note it */
- Sys_FPrintf( SYS_VRB, "sorting..." );
+ Sys_Printf( "sorting..." );
/* allocate a new sorted list */
if( sortLightmaps == NULL )
----------------------------------------------------------------- */
/* note it */
- Sys_FPrintf( SYS_VRB, "allocating..." );
+ Sys_Printf( "allocating..." );
/* kill all existing output lightmaps */
if( outLightmaps != NULL )
----------------------------------------------------------------- */
/* note it */
- Sys_FPrintf( SYS_VRB, "storing..." );
+ Sys_Printf( "storing..." );
/* count the bsp lightmaps and allocate space */
if( bspLightBytes != NULL )
}
if( numExtLightmaps > 0 )
- Sys_FPrintf( SYS_VRB, "\n" );
+ Sys_Printf( "\n" );
/* delete unused external lightmaps */
for( i = numExtLightmaps; i; i++ )
----------------------------------------------------------------- */
/* note it */
- Sys_FPrintf( SYS_VRB, "projecting..." );
+ Sys_Printf( "projecting..." );
/* walk the list of surfaces */
for( i = 0; i < numBSPDrawSurfaces; i++ )
}
/* finish */
- Sys_FPrintf( SYS_VRB, "done.\n" );
+ Sys_Printf( "done.\n" );
/* calc num stored */
numStored = numBSPLightBytes / 3;