X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=tools%2Fquake3%2Fq3map2%2Flight.c;h=38f5ac4537a738493c54f585bac161aa3bf87458;hb=ffb487e45c26dccd20285849979be1cb261c52f6;hp=a09659795a527a326e7628697a36d20c8881d1fc;hpb=a78573e0e9d7a7d13519dc03d5f00f9e87bedaa1;p=xonotic%2Fnetradiant.git diff --git a/tools/quake3/q3map2/light.c b/tools/quake3/q3map2/light.c index a0965979..38f5ac45 100644 --- a/tools/quake3/q3map2/light.c +++ b/tools/quake3/q3map2/light.c @@ -442,7 +442,7 @@ void CreateEntityLights( void ){ /* get target */ e2 = FindTargetEntity( target ); if ( e2 == NULL ) { - Sys_Printf( "WARNING: light at (%i %i %i) has missing target\n", + Sys_FPrintf( SYS_WRN, "WARNING: light at (%i %i %i) has missing target\n", (int) light->origin[ 0 ], (int) light->origin[ 1 ], (int) light->origin[ 2 ] ); light->photons *= pointScale; } @@ -720,7 +720,7 @@ float PointToPolygonFormFactor( const vec3_t point, const vec3_t normal, const w for ( i = 0; i < w->numpoints; i++ ) { VectorSubtract( w->p[ i ], point, dirs[ i ] ); - VectorNormalize( dirs[ i ], dirs[ i ] ); + VectorFastNormalize( dirs[ i ], dirs[ i ] ); } /* duplicate first vertex to avoid mod operation */ @@ -746,7 +746,7 @@ float PointToPolygonFormFactor( const vec3_t point, const vec3_t normal, const w angle = acos( dot ); CrossProduct( dirs[ i ], dirs[ j ], triVector ); - if ( VectorNormalize( triVector, triNormal ) < 0.0001f ) { + if ( VectorFastNormalize( triVector, triNormal ) < 0.0001f ) { continue; } @@ -1159,7 +1159,7 @@ int LightContributionToSample( trace_t *trace ){ /* return to sender */ return 1; } - else{ + else { Error( "Light of undefined type!" ); } @@ -1890,7 +1890,7 @@ void SetupGrid( void ){ does what it says... */ -void LightWorld( void ){ +void LightWorld( const char *BSPFilePath, qboolean fastAllocate ){ vec3_t color; float f; int b, bt; @@ -1910,14 +1910,15 @@ void LightWorld( void ){ /* find the optional minimum lighting values */ GetVectorForKey( &entities[ 0 ], "_color", color ); + if ( VectorLength( color ) == 0.0f ) { + VectorSet( color, 1.0, 1.0, 1.0 ); + } + if ( colorsRGB ) { color[0] = Image_LinearFloatFromsRGBFloat( color[0] ); color[1] = Image_LinearFloatFromsRGBFloat( color[1] ); color[2] = Image_LinearFloatFromsRGBFloat( color[2] ); } - if ( VectorLength( color ) == 0.0f ) { - VectorSet( color, 1.0, 1.0, 1.0 ); - } /* ambient */ f = FloatForKey( &entities[ 0 ], "_ambient" ); @@ -2033,10 +2034,10 @@ void LightWorld( void ){ while ( bounce > 0 ) { /* store off the bsp between bounces */ - StoreSurfaceLightmaps(); + StoreSurfaceLightmaps( fastAllocate ); UnparseEntities(); - Sys_Printf( "Writing %s\n", source ); - WriteBSPFile( source ); + Sys_Printf( "Writing %s\n", BSPFilePath ); + WriteBSPFile( BSPFilePath ); /* note it */ Sys_Printf( "\n--- Radiosity (bounce %d of %d) ---\n", b, bt ); @@ -2054,7 +2055,7 @@ void LightWorld( void ){ SetupEnvelopes( qfalse, fastbounce ); if ( numLights == 0 ) { Sys_Printf( "No diffuse light to calculate, ending radiosity.\n" ); - break; + return; } /* add to lightgrid */ @@ -2097,6 +2098,8 @@ void LightWorld( void ){ bounce--; b++; } + /* ydnar: store off lightmaps */ + StoreSurfaceLightmaps( fastAllocate ); } @@ -2109,11 +2112,14 @@ void LightWorld( void ){ int LightMain( int argc, char **argv ){ int i; float f; - char mapSource[ 1024 ]; + char BSPFilePath[ 1024 ]; + char surfaceFilePath[ 1024 ]; + BSPFilePath[0] = 0; + surfaceFilePath[0] = 0; const char *value; int lightmapMergeSize = 0; qboolean lightSamplesInsist = qfalse; - + qboolean fastAllocate = qfalse; /* note it */ Sys_Printf( "--- Light ---\n" ); @@ -2248,6 +2254,31 @@ int LightMain( int argc, char **argv ){ i++; } + else if ( !strcmp( argv[ i ], "-vertexscale" ) ) { + f = atof( argv[ i + 1 ] ); + vertexglobalscale *= f; + Sys_Printf( "Vertexlight scaled by %f to %f\n", f, vertexglobalscale ); + i++; + } + + else if ( !strcmp( argv[ i ], "-nolm" ) ) { + nolm = qtrue; + Sys_Printf( "No lightmaps yo\n" ); + } + + else if ( !strcmp( argv[ i ], "-bouncecolorratio" ) ) { + f = atof( argv[ i + 1 ] ); + bounceColorRatio *= f; + if ( bounceColorRatio > 1 ) { + bounceColorRatio = 1; + } + if ( bounceColorRatio < 0 ) { + bounceColorRatio = 0; + } + Sys_Printf( "Bounce color ratio set to %f\n", bounceColorRatio ); + i++; + } + else if ( !strcmp( argv[ i ], "-bouncescale" ) ) { f = atof( argv[ i + 1 ] ); bounceScale *= f; @@ -2480,6 +2511,7 @@ int LightMain( int argc, char **argv ){ } i++; } + else if ( !strcmp( argv[ i ], "-deluxe" ) || !strcmp( argv[ i ], "-deluxemap" ) ) { deluxemap = qtrue; Sys_Printf( "Generating deluxemaps for average light direction\n" ); @@ -2509,7 +2541,7 @@ int LightMain( int argc, char **argv ){ /* must be a power of 2 and greater than 2 */ if ( ( ( lmCustomSize - 1 ) & lmCustomSize ) || lmCustomSize < 2 ) { - Sys_Printf( "WARNING: Lightmap size must be a power of 2, greater or equal to 2 pixels.\n" ); + Sys_FPrintf( SYS_WRN, "WARNING: Lightmap size must be a power of 2, greater or equal to 2 pixels.\n" ); lmCustomSize = game->lightmapSize; } i++; @@ -2633,6 +2665,11 @@ 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 ], "-fastgrid" ) ) { fastgrid = qtrue; Sys_Printf( "Fast grid lighting enabled\n" ); @@ -2743,9 +2780,20 @@ int LightMain( int argc, char **argv ){ i++; Sys_Printf( "Lightmaps sample scale set to %d\n", sampleScale ); } + else if ( !strcmp( argv[ i ], "-debugsamplesize" ) ) { + debugSampleSize = 1; + Sys_Printf( "debugging Lightmaps SampleSize\n" ); + } else if ( !strcmp( argv[ i ], "-novertex" ) ) { - noVertexLighting = qtrue; - Sys_Printf( "Disabling vertex lighting\n" ); + noVertexLighting = 1; + if ( ( atof( argv[ i + 1 ] ) != 0 ) && ( atof( argv[ i + 1 ] )) < 1 ) { + noVertexLighting = ( atof( argv[ i + 1 ] ) ); + i++; + Sys_Printf( "Setting vertex lighting globally to %f\n", noVertexLighting ); + } + else{ + Sys_Printf( "Disabling vertex lighting\n" ); + } } else if ( !strcmp( argv[ i ], "-nogrid" ) ) { noGridLighting = qtrue; @@ -2767,6 +2815,14 @@ int LightMain( int argc, char **argv ){ loMem = qtrue; Sys_Printf( "Enabling low-memory (potentially slower) lighting mode\n" ); } + else if ( !strcmp( argv[ i ], "-lightsubdiv" ) ) { + defaultLightSubdivide = atoi( argv[ i + 1 ] ); + if ( defaultLightSubdivide < 1 ) { + defaultLightSubdivide = 1; + } + i++; + Sys_Printf( "Default light subdivision set to %d\n", defaultLightSubdivide ); + } else if ( !strcmp( argv[ i ], "-lightanglehl" ) ) { if ( ( atoi( argv[ i + 1 ] ) != 0 ) != lightAngleHL ) { lightAngleHL = ( atoi( argv[ i + 1 ] ) != 0 ); @@ -2776,6 +2832,7 @@ int LightMain( int argc, char **argv ){ else{ Sys_Printf( "Disabling half lambert light angle attenuation\n" ); } + i++; } } else if ( !strcmp( argv[ i ], "-nostyle" ) || !strcmp( argv[ i ], "-nostyles" ) ) { @@ -2821,7 +2878,7 @@ int LightMain( int argc, char **argv ){ Sys_Printf( "Enabling randomized dirtmapping\n" ); } else{ - Sys_Printf( "Enabling ordered dir mapping\n" ); + Sys_Printf( "Enabling ordered dirtmapping\n" ); } i++; } @@ -2859,10 +2916,22 @@ int LightMain( int argc, char **argv ){ lightmapFill = qtrue; Sys_Printf( "Filling lightmap colors from surrounding pixels to improve JPEG compression\n" ); } + else if ( !strcmp( argv[ i ], "-bspfile" ) ) + { + strcpy( BSPFilePath, argv[i + 1] ); + i++; + Sys_Printf( "Use %s as bsp file\n", BSPFilePath ); + } + else if ( !strcmp( argv[ i ], "-srffile" ) ) + { + strcpy( surfaceFilePath, argv[i + 1] ); + i++; + Sys_Printf( "Use %s as surface file\n", surfaceFilePath ); + } /* unhandled args */ else { - Sys_Printf( "WARNING: Unknown argument \"%s\"\n", argv[ i ] ); + Sys_FPrintf( SYS_WRN, "WARNING: Unknown argument \"%s\"\n", argv[ i ] ); } } @@ -2912,29 +2981,37 @@ int LightMain( int argc, char **argv ){ Sys_Printf( "Restricted lightmap searching enabled - block size adjusted to %d\n", lightmapSearchBlockSize ); } - /* clean up map name */ strcpy( source, ExpandArg( argv[ i ] ) ); StripExtension( source ); - DefaultExtension( source, ".bsp" ); - strcpy( mapSource, ExpandArg( argv[ i ] ) ); - StripExtension( mapSource ); - DefaultExtension( mapSource, ".map" ); + DefaultExtension( source, ".map" ); + + if (!BSPFilePath[0]) { + strcpy( BSPFilePath, ExpandArg( argv[ i ] ) ); + StripExtension( BSPFilePath ); + DefaultExtension( BSPFilePath, ".bsp" ); + } + + if (!surfaceFilePath[0]) { + strcpy( surfaceFilePath, ExpandArg( argv[ i ] ) ); + StripExtension( surfaceFilePath ); + DefaultExtension( surfaceFilePath, ".srf" ); + } /* ydnar: set default sample size */ SetDefaultSampleSize( sampleSize ); /* ydnar: handle shaders */ - BeginMapShaderFile( source ); + BeginMapShaderFile( BSPFilePath ); LoadShaderInfo(); /* note loading */ Sys_Printf( "Loading %s\n", source ); /* ydnar: load surface file */ - LoadSurfaceExtraFile( source ); + LoadSurfaceExtraFile( surfaceFilePath ); /* load bsp file */ - LoadBSPFile( source ); + LoadBSPFile( BSPFilePath ); /* parse bsp entities */ ParseEntities(); @@ -2945,7 +3022,7 @@ int LightMain( int argc, char **argv ){ /* load map file */ value = ValueForKey( &entities[ 0 ], "_keepLights" ); if ( value[ 0 ] != '1' ) { - LoadMapFile( mapSource, qtrue, qfalse ); + LoadMapFile( source, qtrue, qfalse ); } /* set the entity/model origins and init yDrawVerts */ @@ -2961,15 +3038,12 @@ int LightMain( int argc, char **argv ){ SetupTraceNodes(); /* light the world */ - LightWorld(); - - /* ydnar: store off lightmaps */ - StoreSurfaceLightmaps(); + LightWorld( BSPFilePath, fastAllocate ); /* write out the bsp */ UnparseEntities(); - Sys_Printf( "Writing %s\n", source ); - WriteBSPFile( source ); + Sys_Printf( "Writing %s\n", BSPFilePath ); + WriteBSPFile( BSPFilePath ); /* ydnar: export lightmaps */ if ( exportLightmaps && !externalLightmaps ) {