]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/light.c
-lightmapsearchpower
[xonotic/netradiant.git] / tools / quake3 / q3map2 / light.c
index 8995e9feea7140df93c3aee33e0982adeef1dbd0..1517ba962eef050a059ee19300662f8ed6a0c2af 100644 (file)
@@ -313,7 +313,15 @@ void CreateEntityLights( void )
                        flags |= LIGHT_GRID;
                        flags &= ~LIGHT_SURFACES;
                }
-               
+
+               /* vortex: unnormalized? */
+               if (spawnflags & 32)
+                       flags |= LIGHT_UNNORMALIZED;
+
+               /* vortex: distance atten? */
+               if (spawnflags & 64)
+                       flags |= LIGHT_ATTEN_DISTANCE;
+
                /* store the flags */
                light->flags = flags;
                
@@ -385,14 +393,17 @@ void CreateEntityLights( void )
                if( _color && _color[ 0 ] )
                {
                        sscanf( _color, "%f %f %f", &light->color[ 0 ], &light->color[ 1 ], &light->color[ 2 ] );
-                       ColorNormalize( light->color, light->color );
+                       if (!(light->flags & LIGHT_UNNORMALIZED))
+                       {
+                               ColorNormalize( light->color, light->color );
+                       }
                }
                else
                        light->color[ 0 ] = light->color[ 1 ] = light->color[ 2 ] = 1.0f;
-               
+
                intensity = intensity * pointScale;
                light->photons = intensity;
-               
+
                light->type = EMIT_POINT;
                
                /* set falloff threshold */
@@ -741,6 +752,7 @@ int LightContributionToSample( trace_t *trace )
        
        /* clear color */
        VectorClear( trace->color );
+       VectorClear( trace->colorNoShadow );
        
        /* ydnar: early out */
        if( !(light->flags & LIGHT_SURFACES) || light->envelope <= 0.0f )
@@ -766,7 +778,6 @@ int LightContributionToSample( trace_t *trace )
                float           d;
                vec3_t          pushedOrigin;
                
-               
                /* project sample point into light plane */
                d = DotProduct( trace->origin, light->normal ) - light->dist;
                if( d < 3.0f )
@@ -881,8 +892,7 @@ int LightContributionToSample( trace_t *trace )
                {
                        float   distByNormal, radiusAtDist, sampleRadius;
                        vec3_t  pointAtDist, distToSample;
-                       
-                       
+       
                        /* do cone calculation */
                        distByNormal = -DotProduct( trace->displacement, light->normal );
                        if( distByNormal < 0.0f )
@@ -922,6 +932,9 @@ int LightContributionToSample( trace_t *trace )
                add = light->photons * angle;
                if( add <= 0.0f )
                        return 0;
+
+               /* VorteX: set noShadow color */
+               VectorScale(light->color, add, trace->colorNoShadow);
                
                /* setup trace */
                trace->testAll = qtrue;
@@ -942,6 +955,9 @@ int LightContributionToSample( trace_t *trace )
                /* return to sender */
                return 1;
        }
+
+       /* VorteX: set noShadow color */
+       VectorScale(light->color, add, trace->colorNoShadow);
        
        /* ydnar: changed to a variable number */
        if( add <= 0.0f || (add <= light->falloffTolerance && (light->flags & LIGHT_FAST_ACTUAL)) )
@@ -1409,7 +1425,7 @@ void TraceGrid( int num )
                                trace.normal[2]=-1;
                        }
 
-                       f = FloodLightForSample(&trace);
+                       f = FloodLightForSample(&trace, floodlightDistance, floodlight_lowquality);
 
                        contributions[ numCon ].color[0]=col[0]*f;
                        contributions[ numCon ].color[1]=col[1]*f;
@@ -1470,6 +1486,9 @@ void TraceGrid( int num )
                
                /* ambient light will be at 1/4 the value of directed light */
                /* (ydnar: nuke this in favor of more dramatic lighting?) */
+               /* (PM: how about actually making it work? d=1 when it got here for single lights/sun :P */
+//             d = 0.25f;
+               /* (Hobbes: always setting it to .25 is hardly any better) */
                d = 0.25f * (1.0f - d);
                VectorMA( gp->ambient[ j ], d, contributions[ i ].color, gp->ambient[ j ] );
        }
@@ -1487,8 +1506,10 @@ void TraceGrid( int num )
                for( j = 0; j < 3; j++ )
                        if( color[ j ] < minGridLight[ j ] )
                                color[ j ] = minGridLight[ j ];
-               ColorToBytes( color, bgp->ambient[ i ], 1.0f );
-               ColorToBytes( gp->directed[ i ], bgp->directed[ i ], 1.0f );
+
+               /* vortex: apply gridscale and gridambientscale here */
+               ColorToBytes( color, bgp->ambient[ i ], gridScale*gridAmbientScale );
+               ColorToBytes( gp->directed[ i ], bgp->directed[ i ], gridScale );
        }
        
        /* debug code */
@@ -1711,12 +1732,8 @@ void LightWorld( void )
                RunThreadsOnIndividual( numRawLightmaps, qtrue, DirtyRawLightmap );
        }
        
-       /* floodlight them up */
-       if( floodlighty )
-       {
-               Sys_Printf( "--- FloodlightRawLightmap ---\n" );
-               RunThreadsOnIndividual( numRawLightmaps, qtrue, FloodLightRawLightmap );
-       }
+       /* floodlight pass */
+       FloodlightRawLightmaps();
 
        /* ydnar: set up light envelopes */
        SetupEnvelopes( qfalse, fast );
@@ -1828,16 +1845,69 @@ int LightMain( int argc, char **argv )
        float           f;
        char            mapSource[ 1024 ];
        const char      *value;
+       int lightmapMergeSize = 0;
        
        
        /* note it */
        Sys_Printf( "--- Light ---\n" );
-       
+       Sys_Printf( "--- ProcessGameSpecific ---\n" );
+
        /* set standard game flags */
        wolfLight = game->wolfLight;
+       if (wolfLight == qtrue)
+               Sys_Printf( " lightning model: wolf\n" );
+       else
+               Sys_Printf( " lightning model: quake3\n" );
+
        lmCustomSize = game->lightmapSize;
+       Sys_Printf( " lightmap size: %d x %d pixels\n", lmCustomSize, lmCustomSize );
+
        lightmapGamma = game->lightmapGamma;
+       Sys_Printf( " lightning gamma: %f\n", lightmapGamma );
+
        lightmapCompensate = game->lightmapCompensate;
+       Sys_Printf( " lightning compensation: %f\n", lightmapCompensate );
+
+       lightmapExposure = game->lightmapExposure;
+       Sys_Printf( " lightning exposure: %f\n", lightmapExposure );
+
+       gridScale = game->gridScale;
+       Sys_Printf( " lightgrid scale: %f\n", gridScale );
+
+       gridAmbientScale = game->gridAmbientScale;
+       Sys_Printf( " lightgrid ambient scale: %f\n", gridAmbientScale );
+
+       noStyles = game->noStyles;
+       if (noStyles == qtrue)
+               Sys_Printf( " shader lightstyles hack: disabled\n" );
+       else
+               Sys_Printf( " shader lightstyles hack: enabled\n" );
+
+       keepLights = game->keepLights;
+       if (keepLights == qtrue)
+               Sys_Printf( " keep lights: enabled\n" );
+       else
+               Sys_Printf( " keep lights: disabled\n" );
+
+       patchShadows = game->patchShadows;
+       if (patchShadows == qtrue)
+               Sys_Printf( " patch shadows: enabled\n" );
+       else
+               Sys_Printf( " patch shadows: disabled\n" );
+
+       deluxemap = game->deluxeMap;
+       deluxemode = game->deluxeMode;
+       if (deluxemap == qtrue)
+       {
+               if (deluxemode)
+                       Sys_Printf( " deluxemapping: enabled with tangentspace deluxemaps\n" );
+               else
+                       Sys_Printf( " deluxemapping: enabled with modelspace deluxemaps\n" );
+       }
+       else
+               Sys_Printf( " deluxemapping: disabled\n" );
+
+       Sys_Printf( "--- ProcessCommandLine ---\n" );
        
        /* process commandline arguments */
        for( i = 1; i < (argc - 1); i++ )
@@ -1885,6 +1955,22 @@ int LightMain( int argc, char **argv )
                        Sys_Printf( "All light scaled by %f\n", f );
                        i++;
                }
+
+               else if( !strcmp( argv[ i ], "-gridscale" ) )
+               {
+                       f = atof( argv[ i + 1 ] );
+                       Sys_Printf( "Grid lightning scaled by %f\n", f );
+                       gridScale *= f;
+                       i++;
+               }
+
+               else if( !strcmp( argv[ i ], "-gridambientscale" ) )
+               {
+                       f = atof( argv[ i + 1 ] );
+                       Sys_Printf( "Grid ambient lightning scaled by %f\n", f );
+                       gridAmbientScale *= f;
+                       i++;
+               }
                
                else if( !strcmp( argv[ i ], "-gamma" ) )
                {
@@ -1955,12 +2041,6 @@ int LightMain( int argc, char **argv )
                        Sys_Printf( "Dark lightmap seams enabled\n" );
                }
                
-
-
-
-
-
-
                else if( !strcmp( argv[ i ], "-shadeangle" ) )
                {
                        shadeAngleDegrees = atof( argv[ i + 1 ] );
@@ -1993,19 +2073,28 @@ int LightMain( int argc, char **argv )
                                Sys_Printf( "Approximating lightmaps within a byte tolerance of %d\n", approximateTolerance );
                        i++;
                }
-               
                else if( !strcmp( argv[ i ], "-deluxe" ) || !strcmp( argv[ i ], "-deluxemap" ) )
                {
                        deluxemap = qtrue;
                        Sys_Printf( "Generating deluxemaps for average light direction\n" );
                }
-               
-               else if( !strcmp( argv[ i ], "-nodeluxenormalize" ) )
+               else if( !strcmp( argv[ i ], "-deluxemode" ))
                {
-                       normalizeDeluxemap = qfalse;
-                       Sys_Printf( "Not normalizing deluxemaps\n" );
+                       deluxemode = atoi( argv[ i + 1 ] );
+                       if (deluxemode == 0 || deluxemode > 1 || deluxemode < 0)
+                       {
+                               Sys_Printf( "Generating modelspace deluxemaps\n" );
+                               deluxemode = 0;
+                       }
+                       else 
+                               Sys_Printf( "Generating tangentspace deluxemaps\n" );
+                       i++;
+               }
+               else if( !strcmp( argv[ i ], "-nodeluxe" ) || !strcmp( argv[ i ], "-nodeluxemap" ) )
+               {
+                       deluxemap = qfalse;
+                       Sys_Printf( "Disabling generating of deluxemaps for average light direction\n" );
                }
-               
                else if( !strcmp( argv[ i ], "-external" ) )
                {
                        externalLightmaps = qtrue;
@@ -2033,6 +2122,15 @@ int LightMain( int argc, char **argv )
                        }
                }
                
+               else if( !strcmp( argv[ i ], "-lightmapdir" ) )
+               {
+                       lmCustomDir = argv[i + 1];
+                       i++;
+                       Sys_Printf( "Lightmap directory set to %s\n", lmCustomDir );
+                       externalLightmaps = qtrue;
+                       Sys_Printf( "Storing all lightmaps externally\n" );
+               }
+               
                /* ydnar: add this to suppress warnings */
                else if( !strcmp( argv[ i ],  "-custinfoparms") )
                {
@@ -2071,6 +2169,26 @@ int LightMain( int argc, char **argv )
                        noCollapse = qtrue;
                        Sys_Printf( "Identical lightmap collapsing disabled\n" );
                }
+
+               else if( !strcmp( argv[ i ], "-nolightmapsearch" ) )
+               {
+                       lightmapSearchBlockSize = 1;
+                       Sys_Printf( "No lightmap searching - all lightmaps will be sequential\n" );
+               }
+               
+               else if( !strcmp( argv[ i ], "-lightmapsearchpower" ) )
+               {
+                       lightmapMergeSize = (game->lightmapSize << atoi(argv[i+1]));
+                       ++i;
+                       Sys_Printf( "Restricted lightmap searching enabled - optimize for lightmap merge power %d (size %d)\n", atoi(argv[i]), lightmapMergeSize );
+               }
+               
+               else if( !strcmp( argv[ i ], "-lightmapsearchblocksize" ) )
+               {
+                       lightmapSearchBlockSize = atoi(argv[i+1]);
+                       ++i;
+                       Sys_Printf( "Restricted lightmap searching enabled - block size set to %d\n", lightmapSearchBlockSize );
+               }
                
                else if( !strcmp( argv[ i ], "-shade" ) )
                {
@@ -2231,6 +2349,12 @@ int LightMain( int argc, char **argv )
                        i++;
                        Sys_Printf( "Minimum lightmap sample size set to %dx%d units\n", minSampleSize, minSampleSize );
                }
+               else if( !strcmp( argv[ i ],  "-samplescale" ) )
+               {
+                       sampleScale = atoi( argv[ i + 1 ] );
+                       i++;
+                       Sys_Printf( "Lightmaps sample scale set to %d\n", sampleScale);
+               }
                else if( !strcmp( argv[ i ], "-novertex" ) )
                {
                        noVertexLighting = qtrue;
@@ -2266,6 +2390,16 @@ int LightMain( int argc, char **argv )
                        noStyles = qtrue;
                        Sys_Printf( "Disabling lightstyles\n" );
                }
+               else if( !strcmp( argv[ i ], "-style" ) || !strcmp( argv[ i ], "-styles" ) )
+               {
+                       noStyles = qfalse;
+                       Sys_Printf( "Enabling lightstyles\n" );
+               }
+               else if( !strcmp( argv[ i ], "-keeplights" ))
+               {
+                       keepLights = qtrue;
+                       Sys_Printf( "Leaving light entities on map after compile\n" );
+               }
                else if( !strcmp( argv[ i ], "-cpma" ) )
                {
                        cpmaHack = qtrue;
@@ -2307,6 +2441,7 @@ int LightMain( int argc, char **argv )
                                Sys_Printf( "Enabling randomized dirtmapping\n" );
                        else
                                Sys_Printf( "Enabling ordered dir mapping\n" );
+                       i++;
                }
                else if( !strcmp( argv[ i ], "-dirtdepth" ) )
                {
@@ -2314,6 +2449,7 @@ int LightMain( int argc, char **argv )
                        if( dirtDepth <= 0.0f )
                                dirtDepth = 128.0f;
                        Sys_Printf( "Dirtmapping depth set to %.1f\n", dirtDepth );
+                       i++;
                }
                else if( !strcmp( argv[ i ], "-dirtscale" ) )
                {
@@ -2321,6 +2457,7 @@ int LightMain( int argc, char **argv )
                        if( dirtScale <= 0.0f )
                                dirtScale = 1.0f;
                        Sys_Printf( "Dirtmapping scale set to %.1f\n", dirtScale );
+                       i++;
                }
                else if( !strcmp( argv[ i ], "-dirtgain" ) )
                {
@@ -2328,6 +2465,7 @@ int LightMain( int argc, char **argv )
                        if( dirtGain <= 0.0f )
                                dirtGain = 1.0f;
                        Sys_Printf( "Dirtmapping gain set to %.1f\n", dirtGain );
+                       i++;
                }
                else if( !strcmp( argv[ i ], "-trianglecheck" ) )
                {
@@ -2340,11 +2478,20 @@ int LightMain( int argc, char **argv )
                /* unhandled args */
                else
                {
-                       Sys_Printf( "WARNING: Unknown argument \"%s\"\a\n", argv[ i ] );
-                       sleep(1);
+                       Sys_Printf( "WARNING: Unknown argument \"%s\"\n", argv[ i ] );
                }
 
        }
+
+       /* fix up lightmap search power */
+       if(lightmapMergeSize)
+       {
+               lightmapSearchBlockSize = (lightmapMergeSize / lmCustomSize) * (lightmapMergeSize / lmCustomSize);
+               if(lightmapSearchBlockSize < 1)
+                       lightmapSearchBlockSize = 1;
+
+               Sys_Printf( "Restricted lightmap searching enabled - block size adjusted to %d\n", lightmapSearchBlockSize );
+       }
        
        /* clean up map name */
        strcpy( source, ExpandArg( argv[ i ] ) );
@@ -2372,6 +2519,9 @@ int LightMain( int argc, char **argv )
        
        /* parse bsp entities */
        ParseEntities();
+
+       /* inject command line parameters */
+       InjectCommandLine(argv, 0, argc - 1);
        
        /* load map file */
        value = ValueForKey( &entities[ 0 ], "_keepLights" );