]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/light.c
Fix default minimum/ambience color for sRGB lightmaps
[xonotic/netradiant.git] / tools / quake3 / q3map2 / light.c
index ffcd832a5105f8f5648dc2381706d1c6ab2a506c..2571d4d2080cfefb656cd13b5e8e0964f4121fc8 100644 (file)
@@ -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,14 @@ 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 +2033,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 );
@@ -2109,10 +2109,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 */
@@ -2343,12 +2347,21 @@ int LightMain( int argc, char **argv ){
                        Sys_Printf( "Colors are linear\n" );
                }
 
-               else if ( !strcmp( argv[ i ], "-nosRGB" ) ) {
+               else if ( !strcmp( argv[ i ], "-sRGB" ) ) {
                        lightmapsRGB = qtrue;
-                       Sys_Printf( "Lighting is linear\n" );
+                       Sys_Printf( "Lighting is in sRGB\n" );
                        texturesRGB = qtrue;
-                       Sys_Printf( "Textures are linear\n" );
+                       Sys_Printf( "Textures are in sRGB\n" );
                        colorsRGB = qtrue;
+                       Sys_Printf( "Colors are in sRGB\n" );
+               }
+
+               else if ( !strcmp( argv[ i ], "-nosRGB" ) ) {
+                       lightmapsRGB = qfalse;
+                       Sys_Printf( "Lighting is linear\n" );
+                       texturesRGB = qfalse;
+                       Sys_Printf( "Textures are linear\n" );
+                       colorsRGB = qfalse;
                        Sys_Printf( "Colors are linear\n" );
                }
 
@@ -2624,6 +2637,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" );
@@ -2850,6 +2868,18 @@ 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
                {
@@ -2903,29 +2933,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();
@@ -2936,7 +2974,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 */
@@ -2952,15 +2990,15 @@ int LightMain( int argc, char **argv ){
        SetupTraceNodes();
 
        /* light the world */
-       LightWorld();
+       LightWorld( BSPFilePath, fastAllocate );
 
        /* ydnar: store off lightmaps */
-       StoreSurfaceLightmaps();
+       StoreSurfaceLightmaps( 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 ) {