Skip to content

Commit

Permalink
Q3map2:
Browse files Browse the repository at this point in the history
	* 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
  • Loading branch information
Garux committed Aug 2, 2017
1 parent ed4c8c2 commit 93ca259
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 21 deletions.
3 changes: 2 additions & 1 deletion tools/quake3/q3map2/help.c
Expand Up @@ -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"},
Expand Down
18 changes: 14 additions & 4 deletions tools/quake3/q3map2/light.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -2113,6 +2113,7 @@ int LightMain( int argc, char **argv ){
const char *value;
int lightmapMergeSize = 0;
qboolean lightSamplesInsist = qfalse;
qboolean fastAllocate = qtrue;


/* note it */
Expand Down Expand Up @@ -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" );
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions tools/quake3/q3map2/light_trace.c
Expand Up @@ -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 )
Expand Down
72 changes: 64 additions & 8 deletions tools/quake3/q3map2/lightmaps_ydnar.c
Expand Up @@ -1998,14 +1998,15 @@ 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;
float *luxel, *deluxel;
vec3_t color, direction;
byte *pixel;
qboolean ok;
int xIncrement, yIncrement;


/* set default lightmap number (-3 = LIGHTMAP_BY_VERTEX) */
Expand Down Expand Up @@ -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 ) {
Expand All @@ -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 );
Expand Down Expand Up @@ -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++ )
{
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2845,6 +2875,8 @@ void StoreSurfaceLightmaps( void ){
}
}

Sys_Printf( "%d.", (int) ( I_FloatTime() - timer_start ) );

/* -----------------------------------------------------------------
convert modelspace deluxemaps to tangentspace
----------------------------------------------------------------- */
Expand All @@ -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++ )
Expand Down Expand Up @@ -2923,6 +2957,8 @@ void StoreSurfaceLightmaps( void ){
}
}
}

Sys_Printf( "%d.", (int) ( I_FloatTime() - timer_start ) );
}
}

Expand Down Expand Up @@ -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++ )
{
Expand Down Expand Up @@ -3039,6 +3077,8 @@ void StoreSurfaceLightmaps( void ){
}
}
}

Sys_Printf( "%d.", (int) ( I_FloatTime() - timer_start ) );
}

/* -----------------------------------------------------------------
Expand All @@ -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 ) );
Expand All @@ -3058,13 +3100,17 @@ void StoreSurfaceLightmaps( void ){
sortLightmaps[ i ] = i;
qsort( sortLightmaps, numRawLightmaps, sizeof( int ), CompareRawLightmap );

Sys_Printf( "%d.", (int) ( I_FloatTime() - timer_start ) );

/* -----------------------------------------------------------------
allocate output lightmaps
----------------------------------------------------------------- */

/* note it */
Sys_Printf( "allocating..." );

timer_start = I_FloatTime();

/* kill all existing output lightmaps */
if ( outLightmaps != NULL ) {
for ( i = 0; i < numOutLightmaps; i++ )
Expand All @@ -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 */
Expand All @@ -3111,13 +3157,17 @@ void StoreSurfaceLightmaps( void ){
}
}

Sys_Printf( "%d.", (int) ( I_FloatTime() - timer_start ) );

/* -----------------------------------------------------------------
store output lightmaps
----------------------------------------------------------------- */

/* note it */
Sys_Printf( "storing..." );

timer_start = I_FloatTime();

/* count the bsp lightmaps and allocate space */
if ( bspLightBytes != NULL ) {
free( bspLightBytes );
Expand Down Expand Up @@ -3202,13 +3252,17 @@ void StoreSurfaceLightmaps( void ){
remove( filename );
}

Sys_Printf( "%d.", (int) ( I_FloatTime() - timer_start ) );

/* -----------------------------------------------------------------
project the lightmaps onto the bsp surfaces
----------------------------------------------------------------- */

/* note it */
Sys_Printf( "projecting..." );

timer_start = I_FloatTime();

/* walk the list of surfaces */
for ( i = 0; i < numBSPDrawSurfaces; i++ )
{
Expand Down Expand Up @@ -3485,6 +3539,8 @@ void StoreSurfaceLightmaps( void ){
}
}

Sys_Printf( "%d.", (int) ( I_FloatTime() - timer_start ) );

/* finish */
Sys_Printf( "done.\n" );

Expand Down
5 changes: 3 additions & 2 deletions tools/quake3/q3map2/model.c
Expand Up @@ -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;


Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tools/quake3/q3map2/q3map2.h
Expand Up @@ -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 */
Expand Down
9 changes: 6 additions & 3 deletions tools/quake3/q3map2/surface.c
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 93ca259

Please sign in to comment.