X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=tools%2Fquake3%2Fq3map2%2Flight.c;h=e1fbeaca5a769ee7941bf34ea860fbb8c2359ff7;hb=4631d505d92f09d6d6e7b477d02f590bca020d15;hp=5130b2a21886461c99115948f72ddb737c2b4c88;hpb=81c10be0f48a9071bf23cdd709ae31eb801f42d5;p=xonotic%2Fnetradiant.git diff --git a/tools/quake3/q3map2/light.c b/tools/quake3/q3map2/light.c index 5130b2a2..e1fbeaca 100644 --- a/tools/quake3/q3map2/light.c +++ b/tools/quake3/q3map2/light.c @@ -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)) ) @@ -1244,7 +1260,7 @@ grid samples are for quickly determining the lighting of dynamically placed entities in the world */ -#define MAX_CONTRIBUTIONS 1024 +#define MAX_CONTRIBUTIONS 32768 typedef struct { @@ -1256,9 +1272,9 @@ contribution_t; void TraceGrid( int num ) { - int i, j, x, y, z, mod, step, numCon, numStyles; - float d; - vec3_t baseOrigin, cheapColor, color; + int i, j, x, y, z, mod, numCon, numStyles; + float d, step; + vec3_t baseOrigin, cheapColor, color, thisdir; rawGridPoint_t *gp; bspGridPoint_t *bgp; contribution_t contributions[ MAX_CONTRIBUTIONS ]; @@ -1295,38 +1311,21 @@ void TraceGrid( int num ) { /* try to nudge the origin around to find a valid point */ VectorCopy( trace.origin, baseOrigin ); - for( step = 9; step <= 18; step += 9 ) + for( step = 0; (step += 0.005) <= 1.0; ) { - for( i = 0; i < 8; i++ ) - { - VectorCopy( baseOrigin, trace.origin ); - if( i & 1 ) - trace.origin[ 0 ] += step; - else - trace.origin[ 0 ] -= step; - - if( i & 2 ) - trace.origin[ 1 ] += step; - else - trace.origin[ 1 ] -= step; + VectorCopy( baseOrigin, trace.origin ); + trace.origin[ 0 ] += step * (Random() - 0.5) * gridSize[0]; + trace.origin[ 1 ] += step * (Random() - 0.5) * gridSize[1]; + trace.origin[ 2 ] += step * (Random() - 0.5) * gridSize[2]; - if( i & 4 ) - trace.origin[ 2 ] += step; - else - trace.origin[ 2 ] -= step; - - /* ydnar: changed to find cluster num */ - trace.cluster = ClusterForPointExt( trace.origin, VERTEX_EPSILON ); - if( trace.cluster >= 0 ) - break; - } - - if( i != 8 ) + /* ydnar: changed to find cluster num */ + trace.cluster = ClusterForPointExt( trace.origin, VERTEX_EPSILON ); + if( trace.cluster >= 0 ) break; } /* can't find a valid point at all */ - if( step > 18 ) + if( step > 0.5 ) return; } @@ -1409,7 +1408,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; @@ -1429,15 +1428,18 @@ void TraceGrid( int num ) ///////////////////// /* normalize to get primary light direction */ - VectorNormalize( gp->dir, gp->dir ); + VectorNormalize( gp->dir, thisdir ); /* now that we have identified the primary light direction, go back and separate all the light into directed and ambient */ + numStyles = 1; for( i = 0; i < numCon; i++ ) { /* get relative directed strength */ - d = DotProduct( contributions[ i ].dir, gp->dir ); + d = DotProduct( contributions[ i ].dir, thisdir ); + /* we map 1 to gridDirectionality, and 0 to gridAmbientDirectionality */ + d = gridAmbientDirectionality + d * (gridDirectionality - gridAmbientDirectionality); if( d < 0.0f ) d = 0.0f; @@ -1470,25 +1472,45 @@ 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 ] ); + +/* + * div0: + * the total light average = ambient value + 0.25 * sum of all directional values + * we can also get the total light average as 0.25 * the sum of all contributions + * + * 0.25 * sum(contribution_i) == ambient + 0.25 * sum(d_i contribution_i) + * + * THIS YIELDS: + * ambient == 0.25 * sum((1 - d_i) contribution_i) + * + * So, 0.25f * (1.0f - d) IS RIGHT. If you want to tune it, tune d BEFORE. + */ } /* store off sample */ for( i = 0; i < MAX_LIGHTMAPS; i++ ) { +#if 0 /* do some fudging to keep the ambient from being too low (2003-07-05: 0.25 -> 0.125) */ if( !bouncing ) VectorMA( gp->ambient[ i ], 0.125f, gp->directed[ i ], gp->ambient[ i ] ); +#endif /* set minimum light and copy off to bytes */ VectorCopy( gp->ambient[ i ], color ); 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 */ @@ -1501,8 +1523,7 @@ void TraceGrid( int num ) #endif /* store direction */ - if( !bouncing ) - NormalToLatLong( gp->dir, bgp->latLong ); + NormalToLatLong( thisdir, bgp->latLong ); } @@ -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 ); @@ -1750,6 +1767,7 @@ void LightWorld( void ) { /* store off the bsp between bounces */ StoreSurfaceLightmaps(); + UnparseEntities(); Sys_Printf( "Writing %s\n", source ); WriteBSPFile( source ); @@ -1827,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++ ) @@ -1884,6 +1955,42 @@ 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 ], "-griddirectionality" ) ) + { + f = atof( argv[ i + 1 ] ); + if(f < 0) f = 0; + if(f > gridAmbientDirectionality) f = gridAmbientDirectionality; + Sys_Printf( "Grid directionality is %f\n", f ); + gridDirectionality *= f; + i++; + } + + else if( !strcmp( argv[ i ], "-gridambientdirectionality" ) ) + { + f = atof( argv[ i + 1 ] ); + if(f > gridDirectionality) f = gridDirectionality; + if(f > 1) f = 1; + Sys_Printf( "Grid ambient directionality is %f\n", f ); + gridAmbientDirectionality *= f; + i++; + } else if( !strcmp( argv[ i ], "-gamma" ) ) { @@ -1954,12 +2061,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 ] ); @@ -1992,13 +2093,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 ], "-deluxemode" )) + { + 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; @@ -2026,6 +2142,23 @@ int LightMain( int argc, char **argv ) } } + else if( !strcmp( argv[ i ], "-rawlightmapsizelimit" ) ) + { + lmLimitSize = atoi( argv[ i + 1 ] ); + + i++; + Sys_Printf( "Raw lightmap size limit set to %d x %d pixels\n", lmLimitSize, lmLimitSize ); + } + + 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") ) { @@ -2064,6 +2197,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" ) ) { @@ -2224,6 +2377,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; @@ -2259,6 +2418,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; @@ -2300,6 +2469,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" ) ) { @@ -2307,6 +2477,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" ) ) { @@ -2314,6 +2485,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" ) ) { @@ -2321,16 +2493,33 @@ 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" ) ) + { + lightmapTriangleCheck = qtrue; + } + else if( !strcmp( argv[ i ], "-extravisnudge" ) ) + { + lightmapExtraVisClusterNudge = qtrue; } - /* 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 ] ) ); @@ -2358,6 +2547,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" );