From aa4914be0f3977adc266d368b6727626f24f5abd Mon Sep 17 00:00:00 2001 From: rpolzer Date: Fri, 26 Sep 2008 06:48:14 +0000 Subject: [PATCH] Turn some UT stuff into options, as it is broken for Nexuiz. Also add -nodeluxenormalize as an experimental second deluxemapping option. + else if( !strcmp( argv[ i ], "-nodeluxenormalize" ) ) + else if( !strcmp( argv[ i ], "-trianglecheck" ) ) + else if( !strcmp( argv[ i ], "-extravisnudge" ) ) git-svn-id: svn://svn.icculus.org/netradiant/trunk@105 61c419a2-8eb2-4b30-bcec-8cead039b335 --- tools/quake3/q3map2/light.c | 15 +++++- tools/quake3/q3map2/light_ydnar.c | 71 ++++++++++++++++++++++----- tools/quake3/q3map2/lightmaps_ydnar.c | 15 +++++- tools/quake3/q3map2/q3map2.h | 6 ++- 4 files changed, 90 insertions(+), 17 deletions(-) diff --git a/tools/quake3/q3map2/light.c b/tools/quake3/q3map2/light.c index 5130b2a..29472a1 100644 --- a/tools/quake3/q3map2/light.c +++ b/tools/quake3/q3map2/light.c @@ -1999,6 +1999,12 @@ int LightMain( int argc, char **argv ) Sys_Printf( "Generating deluxemaps for average light direction\n" ); } + else if( !strcmp( argv[ i ], "-nodeluxenormalize" ) ) + { + normalizeDeluxemap = qfalse; + Sys_Printf( "Not normalizing deluxemaps\n" ); + } + else if( !strcmp( argv[ i ], "-external" ) ) { externalLightmaps = qtrue; @@ -2322,7 +2328,14 @@ int LightMain( int argc, char **argv ) dirtGain = 1.0f; Sys_Printf( "Dirtmapping gain set to %.1f\n", dirtGain ); } - + else if( !strcmp( argv[ i ], "-trianglecheck" ) ) + { + lightmapTriangleCheck = qtrue; + } + else if( !strcmp( argv[ i ], "-extravisnudge" ) ) + { + lightmapExtraVisClusterNudge = qtrue; + } /* unhandled args */ else { diff --git a/tools/quake3/q3map2/light_ydnar.c b/tools/quake3/q3map2/light_ydnar.c index d8f0c73..fa2a4d7 100644 --- a/tools/quake3/q3map2/light_ydnar.c +++ b/tools/quake3/q3map2/light_ydnar.c @@ -533,7 +533,7 @@ static int MapSingleLuxel( rawLightmap_t *lm, surfaceInfo_t *info, bspDrawVert_t //1) Test the sample origin to see if it lays on the wrong side of any edge (x/y) //2) if it does, nudge it onto the correct side. - if (worldverts!=NULL) + if (worldverts!=NULL && lightmapTriangleCheck) { for (j=0;j<3;j++) { @@ -604,9 +604,12 @@ static int MapSingleLuxel( rawLightmap_t *lm, surfaceInfo_t *info, bspDrawVert_t origin[ lm->axisNum ] += lightmapSampleOffset; VectorCopy(origin,origintwo); - origintwo[0]+=vecs[2][0]; - origintwo[1]+=vecs[2][1]; - origintwo[2]+=vecs[2][2]; + if(lightmapExtraVisClusterNudge) + { + origintwo[0]+=vecs[2][0]; + origintwo[1]+=vecs[2][1]; + origintwo[2]+=vecs[2][2]; + } /* get cluster */ pointCluster = ClusterForPointExtFilter( origintwo, LUXEL_EPSILON, numClusters, clusters ); @@ -631,8 +634,8 @@ static int MapSingleLuxel( rawLightmap_t *lm, surfaceInfo_t *info, bspDrawVert_t /* get pvs cluster */ pointCluster = ClusterForPointExtFilter( nudged, LUXEL_EPSILON, numClusters, clusters ); //% + 0.625 ); - //if( pointCluster >= 0 ) - // VectorCopy( nudged, origin ); + if( pointCluster >= 0 ) + VectorCopy( nudged, origin ); luxel[ 1 ] += 1.0f; } } @@ -642,8 +645,8 @@ static int MapSingleLuxel( rawLightmap_t *lm, surfaceInfo_t *info, bspDrawVert_t { VectorMA( dv->xyz, lightmapSampleOffset, dv->normal, nudged ); pointCluster = ClusterForPointExtFilter( nudged, LUXEL_EPSILON, numClusters, clusters ); - //if( pointCluster >= 0 ) - // VectorCopy( nudged, origin ); + if( pointCluster >= 0 ) + VectorCopy( nudged, origin ); luxel[ 1 ] += 1.0f; } @@ -2004,7 +2007,10 @@ void IlluminateRawLightmap( int rawLightmapNum ) { VectorCopy( ambientColor, luxel ); if( deluxemap ) + { VectorScale( normal, 0.00390625f, deluxel ); + deluxel[3] = 0.00390625f; + } luxel[ 3 ] = 1.0f; } } @@ -2097,8 +2103,9 @@ 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); - VectorScale( trace.direction, brightness, trace.direction ); - VectorAdd( deluxel, trace.direction, deluxel ); + VectorScale( trace.direction, brightness, temp ); + VectorAdd( deluxel, temp, deluxel ); + deluxel[3] += brightness; } } } @@ -2353,8 +2360,8 @@ void IlluminateRawLightmap( int rawLightmapNum ) { /* get cluster */ cluster = SUPER_CLUSTER( x, y ); - //% if( *cluster < 0 ) - //% continue; + if( *cluster < 0 ) + continue; /* get particulars */ luxel = SUPER_LUXEL( lightmapNum, x, y ); @@ -2425,7 +2432,7 @@ void IlluminateRawLightmap( int rawLightmapNum ) { /* get cluster */ cluster = SUPER_CLUSTER( x, y ); - //% if( *cluster < 0 ) + //% if( *cluster < 0 ) // TODO why not do this check? These pixels should be zero anyway //% continue; /* get particulars */ @@ -2538,6 +2545,44 @@ void IlluminateRawLightmap( int rawLightmapNum ) } } } + + +#if 0 + // audit pass + for( lightmapNum = 0; lightmapNum < MAX_LIGHTMAPS; lightmapNum++ ) + { + /* early out */ + if( lm->superLuxels[ lightmapNum ] == NULL ) + continue; + for( y = 0; y < lm->sh; y++ ) + for( x = 0; x < lm->sw; x++ ) + { + /* get cluster */ + cluster = SUPER_CLUSTER( x, y ); + luxel = SUPER_LUXEL( lightmapNum, x, y ); + deluxel = SUPER_DELUXEL( x, y ); + if(!luxel || !deluxel || !cluster) + { + Sys_FPrintf(SYS_VRB, "WARNING: I got NULL'd.\n"); + continue; + } + else if(*cluster < 0) + { + // unmapped pixel + // should have neither deluxemap nor lightmap + if(deluxel[3]) + Sys_FPrintf(SYS_VRB, "WARNING: I have written deluxe to an unmapped luxel. Sorry.\n"); + } + else + { + // mapped pixel + // should have both deluxemap and lightmap + if(deluxel[3]) + Sys_FPrintf(SYS_VRB, "WARNING: I forgot to write deluxe to a mapped luxel. Sorry.\n"); + } + } + } +#endif } diff --git a/tools/quake3/q3map2/lightmaps_ydnar.c b/tools/quake3/q3map2/lightmaps_ydnar.c index b4b6349..d3054b1 100644 --- a/tools/quake3/q3map2/lightmaps_ydnar.c +++ b/tools/quake3/q3map2/lightmaps_ydnar.c @@ -2172,8 +2172,21 @@ static void FindOutLightmaps( rawLightmap_t *lm ) /* store direction */ if( deluxemap ) { + 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( VectorNormalize( deluxel, 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); diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index a454593..af2e3a3 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -265,7 +265,7 @@ constants #define SUPER_LUXEL_SIZE 4 #define SUPER_ORIGIN_SIZE 3 #define SUPER_NORMAL_SIZE 4 -#define SUPER_DELUXEL_SIZE 3 +#define SUPER_DELUXEL_SIZE 4 #define BSP_DELUXEL_SIZE 3 #define SUPER_FLOODLIGHT_SIZE 1 @@ -1935,7 +1935,8 @@ Q_EXTERN qboolean emitFlares Q_ASSIGN( qfalse ); Q_EXTERN qboolean debugSurfaces Q_ASSIGN( qfalse ); Q_EXTERN qboolean debugInset Q_ASSIGN( qfalse ); Q_EXTERN qboolean debugPortals Q_ASSIGN( qfalse ); - +Q_EXTERN qboolean lightmapTriangleCheck Q_ASSIGN(qfalse); +Q_EXTERN qboolean lightmapExtraVisClusterNudge Q_ASSIGN(qfalse); Q_EXTERN double normalEpsilon Q_ASSIGN( 0.00001 ); Q_EXTERN double distanceEpsilon Q_ASSIGN( 0.01 ); @@ -2093,6 +2094,7 @@ Q_EXTERN qboolean cpmaHack Q_ASSIGN( qfalse ); Q_EXTERN qboolean deluxemap Q_ASSIGN( qfalse ); Q_EXTERN qboolean debugDeluxemap Q_ASSIGN( qfalse ); +Q_EXTERN qboolean normalizeDeluxemap Q_ASSIGN( qtrue ); Q_EXTERN qboolean fast Q_ASSIGN( qfalse ); Q_EXTERN qboolean faster Q_ASSIGN( qfalse ); -- 2.39.2