From: Garux Date: Wed, 2 Aug 2017 06:16:57 +0000 (+0300) Subject: Q3map2: X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=93ca259313e7902e89974877f4110fc818e9208b;p=xonotic%2Fnetradiant.git Q3map2: * new slightly less careful, but much faster lightmaps packing algorithm (allocating... process) * -slowallocate switch to enable old lightmaps packing algorithm * Subsampling...collapsing...sorting...allocating...storing...projecting... timers --- diff --git a/tools/quake3/q3map2/help.c b/tools/quake3/q3map2/help.c index 5cc81ab9..ea3304d5 100644 --- a/tools/quake3/q3map2/help.c +++ b/tools/quake3/q3map2/help.c @@ -194,7 +194,8 @@ void HelpLight() {"-extravisnudge", "Broken feature to nudge the luxel origin to a better vis cluster"}, {"-extrawide", "Deprecated alias for `-super 2 -filter`"}, {"-extra", "Deprecated alias for `-super 2`"}, - {"-fastallocate", "Use `-fastallocate` to trade lightmap size against allocation time (useful with hi res lightmaps on large maps: reduce allocation time from days to minutes for only some extra bytes)"}, +// {"-fastallocate", "Use `-fastallocate` to trade lightmap size against allocation time (useful with hi res lightmaps on large maps: reduce allocation time from days to minutes for only some extra bytes)"}, + {"-slowallocate", "Use old (a bit more careful, but much slower) lightmaps packing algorithm"}, {"-fastbounce", "Use `-fast` style lighting for radiosity"}, {"-faster", "Use a faster falloff curve for lighting; also implies `-fast`"}, {"-fastgrid", "Use `-fast` style lighting for the light grid"}, diff --git a/tools/quake3/q3map2/light.c b/tools/quake3/q3map2/light.c index 9b3926e5..d6916367 100644 --- a/tools/quake3/q3map2/light.c +++ b/tools/quake3/q3map2/light.c @@ -1890,7 +1890,7 @@ void SetupGrid( void ){ does what it says... */ -void LightWorld( void ){ +void LightWorld( qboolean fastAllocate ){ vec3_t color; float f; int b, bt; @@ -2033,7 +2033,7 @@ void LightWorld( void ){ while ( bounce > 0 ) { /* store off the bsp between bounces */ - StoreSurfaceLightmaps(); + StoreSurfaceLightmaps( fastAllocate ); UnparseEntities(); Sys_Printf( "Writing %s\n", source ); WriteBSPFile( source ); @@ -2113,6 +2113,7 @@ int LightMain( int argc, char **argv ){ const char *value; int lightmapMergeSize = 0; qboolean lightSamplesInsist = qfalse; + qboolean fastAllocate = qtrue; /* note it */ @@ -2682,6 +2683,15 @@ int LightMain( int argc, char **argv ){ Sys_Printf( "Faster mode enabled\n" ); } +// else if ( !strcmp( argv[ i ], "-fastallocate" ) ) { +// fastAllocate = qtrue; +// Sys_Printf( "Fast allocation mode enabled\n" ); +// } + else if ( !strcmp( argv[ i ], "-slowallocate" ) ) { + fastAllocate = qfalse; + Sys_Printf( "Slow allocation mode enabled\n" ); + } + else if ( !strcmp( argv[ i ], "-fastgrid" ) ) { fastgrid = qtrue; Sys_Printf( "Fast grid lighting enabled\n" ); @@ -3022,10 +3032,10 @@ int LightMain( int argc, char **argv ){ SetupTraceNodes(); /* light the world */ - LightWorld(); + LightWorld( fastAllocate ); /* ydnar: store off lightmaps */ - StoreSurfaceLightmaps(); + StoreSurfaceLightmaps( fastAllocate ); /* write out the bsp */ UnparseEntities(); diff --git a/tools/quake3/q3map2/light_trace.c b/tools/quake3/q3map2/light_trace.c index 08606f7e..29fa928f 100644 --- a/tools/quake3/q3map2/light_trace.c +++ b/tools/quake3/q3map2/light_trace.c @@ -1633,10 +1633,10 @@ static qboolean TraceLine_r( int nodeNum, const vec3_t origin, const vec3_t end, traceNode_t *node; int side; float front, back, frac; - vec3_t origin, mid; - qboolean r; + vec3_t mid; #if TRACELINE_R_HALF_ITERATIVE + vec3_t origin; VectorCopy( start, origin ); while ( 1 ) diff --git a/tools/quake3/q3map2/lightmaps_ydnar.c b/tools/quake3/q3map2/lightmaps_ydnar.c index 82de2474..c1c9ced0 100644 --- a/tools/quake3/q3map2/lightmaps_ydnar.c +++ b/tools/quake3/q3map2/lightmaps_ydnar.c @@ -1998,7 +1998,7 @@ static void SetupOutLightmap( rawLightmap_t *lm, outLightmap_t *olm ){ */ #define LIGHTMAP_RESERVE_COUNT 1 -static void FindOutLightmaps( rawLightmap_t *lm ){ +static void FindOutLightmaps( rawLightmap_t *lm, qboolean fastAllocate ){ int i, j, k, lightmapNum, xMax, yMax, x = -1, y = -1, sx, sy, ox, oy, offset; outLightmap_t *olm; surfaceInfo_t *info; @@ -2006,6 +2006,7 @@ static void FindOutLightmaps( rawLightmap_t *lm ){ vec3_t color, direction; byte *pixel; qboolean ok; + int xIncrement, yIncrement; /* set default lightmap number (-3 = LIGHTMAP_BY_VERTEX) */ @@ -2116,6 +2117,13 @@ static void FindOutLightmaps( rawLightmap_t *lm ){ continue; } + /* if fast allocation, skip lightmap files that are more than 90% complete */ + if ( fastAllocate == qtrue ) { + if (olm->freeLuxels < (olm->customWidth * olm->customHeight) / 10) { + continue; + } + } + /* don't store non-custom raw lightmaps on custom bsp lightmaps */ if ( olm->customWidth != lm->customWidth || olm->customHeight != lm->customHeight ) { @@ -2133,10 +2141,20 @@ static void FindOutLightmaps( rawLightmap_t *lm ){ yMax = ( olm->customHeight - lm->h ) + 1; } + /* if fast allocation, do not test allocation on every pixels, especially for large lightmaps */ + if ( fastAllocate == qtrue ) { + xIncrement = MAX(1, lm->w / 15); + yIncrement = MAX(1, lm->h / 15); + } + else { + xIncrement = 1; + yIncrement = 1; + } + /* walk the origin around the lightmap */ - for ( y = 0; y < yMax; y++ ) + for ( y = 0; y < yMax; y += yIncrement ) { - for ( x = 0; x < xMax; x++ ) + for ( x = 0; x < xMax; x += xIncrement ) { /* find a fine tract of lauhnd */ ok = TestOutLightmapStamp( lm, lightmapNum, olm, x, y ); @@ -2318,6 +2336,16 @@ static int CompareRawLightmap( const void *a, const void *b ){ /* get min number of surfaces */ min = ( alm->numLightSurfaces < blm->numLightSurfaces ? alm->numLightSurfaces : blm->numLightSurfaces ); +//#define allocate_bigger_first +#ifdef allocate_bigger_first + /* compare size, allocate bigger first */ + // fastAllocate commit part: can kick fps by unique lightmap/shader combinations*=~2 + bigger compile time + //return -diff; makes packing faster and rough + diff = ( blm->w * blm->h ) - ( alm->w * alm->h ); + if ( diff != 0 ) { + return diff; + } +#endif /* iterate */ for ( i = 0; i < min; i++ ) { @@ -2339,13 +2367,13 @@ static int CompareRawLightmap( const void *a, const void *b ){ if ( diff ) { return diff; } - +#ifndef allocate_bigger_first /* compare size */ diff = ( blm->w * blm->h ) - ( alm->w * alm->h ); if ( diff != 0 ) { return diff; } - +#endif /* must be equivalent */ return 0; } @@ -2467,8 +2495,8 @@ void FillOutLightmap( outLightmap_t *olm ){ stores the surface lightmaps into the bsp as byte rgb triplets */ -void StoreSurfaceLightmaps( void ){ - int i, j, k, x, y, lx, ly, sx, sy, *cluster, mappedSamples; +void StoreSurfaceLightmaps( qboolean fastAllocate ){ + int i, j, k, x, y, lx, ly, sx, sy, *cluster, mappedSamples, timer_start; int style, size, lightmapNum, lightmapNum2; float *normal, *luxel, *bspLuxel, *bspLuxel2, *radLuxel, samples, occludedSamples; vec3_t sample, occludedSample, dirSample, colorMins, colorMaxs; @@ -2511,6 +2539,8 @@ void StoreSurfaceLightmaps( void ){ /* note it */ Sys_Printf( "Subsampling..." ); + timer_start = I_FloatTime(); + /* walk the list of raw lightmaps */ numUsed = 0; numTwins = 0; @@ -2845,6 +2875,8 @@ void StoreSurfaceLightmaps( void ){ } } + Sys_Printf( "%d.", (int) ( I_FloatTime() - timer_start ) ); + /* ----------------------------------------------------------------- convert modelspace deluxemaps to tangentspace ----------------------------------------------------------------- */ @@ -2854,6 +2886,8 @@ void StoreSurfaceLightmaps( void ){ vec3_t worldUp, myNormal, myTangent, myBinormal; float dist; + timer_start = I_FloatTime(); + Sys_Printf( "converting..." ); for ( i = 0; i < numRawLightmaps; i++ ) @@ -2923,6 +2957,8 @@ void StoreSurfaceLightmaps( void ){ } } } + + Sys_Printf( "%d.", (int) ( I_FloatTime() - timer_start ) ); } } @@ -2979,6 +3015,8 @@ void StoreSurfaceLightmaps( void ){ /* note it */ Sys_Printf( "collapsing..." ); + timer_start = I_FloatTime(); + /* set all twin refs to null */ for ( i = 0; i < numRawLightmaps; i++ ) { @@ -3039,6 +3077,8 @@ void StoreSurfaceLightmaps( void ){ } } } + + Sys_Printf( "%d.", (int) ( I_FloatTime() - timer_start ) ); } /* ----------------------------------------------------------------- @@ -3048,6 +3088,8 @@ void StoreSurfaceLightmaps( void ){ /* note it */ Sys_Printf( "sorting..." ); + timer_start = I_FloatTime(); + /* allocate a new sorted list */ if ( sortLightmaps == NULL ) { sortLightmaps = safe_malloc( numRawLightmaps * sizeof( int ) ); @@ -3058,6 +3100,8 @@ void StoreSurfaceLightmaps( void ){ sortLightmaps[ i ] = i; qsort( sortLightmaps, numRawLightmaps, sizeof( int ), CompareRawLightmap ); + Sys_Printf( "%d.", (int) ( I_FloatTime() - timer_start ) ); + /* ----------------------------------------------------------------- allocate output lightmaps ----------------------------------------------------------------- */ @@ -3065,6 +3109,8 @@ void StoreSurfaceLightmaps( void ){ /* note it */ Sys_Printf( "allocating..." ); + timer_start = I_FloatTime(); + /* kill all existing output lightmaps */ if ( outLightmaps != NULL ) { for ( i = 0; i < numOutLightmaps; i++ ) @@ -3085,7 +3131,7 @@ void StoreSurfaceLightmaps( void ){ for ( i = 0; i < numRawLightmaps; i++ ) { lm = &rawLightmaps[ sortLightmaps[ i ] ]; - FindOutLightmaps( lm ); + FindOutLightmaps( lm, fastAllocate ); } /* set output numbers in twinned lightmaps */ @@ -3111,6 +3157,8 @@ void StoreSurfaceLightmaps( void ){ } } + Sys_Printf( "%d.", (int) ( I_FloatTime() - timer_start ) ); + /* ----------------------------------------------------------------- store output lightmaps ----------------------------------------------------------------- */ @@ -3118,6 +3166,8 @@ void StoreSurfaceLightmaps( void ){ /* note it */ Sys_Printf( "storing..." ); + timer_start = I_FloatTime(); + /* count the bsp lightmaps and allocate space */ if ( bspLightBytes != NULL ) { free( bspLightBytes ); @@ -3202,6 +3252,8 @@ void StoreSurfaceLightmaps( void ){ remove( filename ); } + Sys_Printf( "%d.", (int) ( I_FloatTime() - timer_start ) ); + /* ----------------------------------------------------------------- project the lightmaps onto the bsp surfaces ----------------------------------------------------------------- */ @@ -3209,6 +3261,8 @@ void StoreSurfaceLightmaps( void ){ /* note it */ Sys_Printf( "projecting..." ); + timer_start = I_FloatTime(); + /* walk the list of surfaces */ for ( i = 0; i < numBSPDrawSurfaces; i++ ) { @@ -3485,6 +3539,8 @@ void StoreSurfaceLightmaps( void ){ } } + Sys_Printf( "%d.", (int) ( I_FloatTime() - timer_start ) ); + /* finish */ Sys_Printf( "done.\n" ); diff --git a/tools/quake3/q3map2/model.c b/tools/quake3/q3map2/model.c index c7f0a6b8..a60bcee9 100644 --- a/tools/quake3/q3map2/model.c +++ b/tools/quake3/q3map2/model.c @@ -230,7 +230,8 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap char *skinfilecontent; int skinfilesize; char *skinfileptr, *skinfilenextptr; - int ok=0, notok=0, spf = ( spawnFlags & 8088 ); + //int ok=0, notok=0; + int spf = ( spawnFlags & 8088 ); float limDepth=0; @@ -543,7 +544,7 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap ( spf == 5632 ) || //EXTRUDE_DOWNWARDS+EXTRUDE_UPWARDS+AXIAL_BACKPLANE ( spf == 3072 ) || //EXTRUDE_UPWARDS+MAX_EXTRUDE ( spf == 5120 ) ){ //EXTRUDE_UPWARDS+AXIAL_BACKPLANE - vec3_t points[ 4 ], backs[ 3 ], cnt, bestNormal, nrm, Vnorm[3], Enorm[3]; + vec3_t points[ 4 ], cnt, bestNormal, nrm, Vnorm[3], Enorm[3]; vec4_t plane, reverse, p[3]; double normalEpsilon_save; qboolean snpd; diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index e6d0e1f7..141ddcbd 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -1840,7 +1840,7 @@ int ImportLightmapsMain( int argc, char **argv ); void SetupSurfaceLightmaps( void ); void StitchSurfaceLightmaps( void ); -void StoreSurfaceLightmaps( void ); +void StoreSurfaceLightmaps( qboolean fastAllocate ); /* exportents.c */ diff --git a/tools/quake3/q3map2/surface.c b/tools/quake3/q3map2/surface.c index 18c115ee..6b99ed4f 100644 --- a/tools/quake3/q3map2/surface.c +++ b/tools/quake3/q3map2/surface.c @@ -2108,8 +2108,8 @@ int FilterPointConvexHullIntoTree_r( vec3_t **points, int npoints, mapDrawSurfac int FilterWindingIntoTree_r( winding_t *w, mapDrawSurface_t *ds, node_t *node ){ int i, refs = 0; - plane_t *p1, *p2; - vec4_t plane1, plane2; + plane_t *p1; + vec4_t plane1; winding_t *fat, *front, *back; shaderInfo_t *si; @@ -2163,12 +2163,15 @@ int FilterWindingIntoTree_r( winding_t *w, mapDrawSurface_t *ds, node_t *node ){ /* check if surface is planar */ if ( ds->planeNum >= 0 ) { + #if 0 + plane_t *p2; + vec4_t plane2; + /* get surface plane */ p2 = &mapplanes[ ds->planeNum ]; VectorCopy( p2->normal, plane2 ); plane2[ 3 ] = p2->dist; - #if 0 /* div0: this is the plague (inaccurate) */ vec4_t reverse;