X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=tools%2Fquake3%2Fq3map2%2Flight_ydnar.c;h=ce9cf861fed4afd8f1e57fd967748855d169bda5;hb=acd4026b70958a6371bf09c8f1618f98db625234;hp=c9107407e3cf9c6c0b97c6f0a7e9c68d116521b8;hpb=7fc621fc78d0e040dc2c12f38dc53dd9048215dc;p=xonotic%2Fnetradiant.git diff --git a/tools/quake3/q3map2/light_ydnar.c b/tools/quake3/q3map2/light_ydnar.c index c9107407..ce9cf861 100644 --- a/tools/quake3/q3map2/light_ydnar.c +++ b/tools/quake3/q3map2/light_ydnar.c @@ -132,6 +132,19 @@ void ColorToBytes( const float *color, byte *colorBytes, float scale ){ colorBytes[ 2 ] = sample[ 2 ]; } +/* + * Same as ColorToBytes, but if the output color will never contain zero + * components. Used to avoid returning 0 0 0 due to an ioq3 issue. Reason + * to also map 0 0 1 to 1 1 1 is to ensure monotonicity in the color mapping + * to prevent banding-like artifacts on lightmaps. + */ +void ColorToBytesNonZero( const float *color, byte *colorBytes, float scale) { + int i; + ColorToBytes(color, colorBytes, scale); + for (i = 0; i < 3; ++i) + if (colorBytes[i] == 0) + colorBytes[i] = 1; +} /* ------------------------------------------------------------------------------- @@ -162,13 +175,11 @@ void SmoothNormals( void ){ /* allocate shade angle table */ - shadeAngles = safe_malloc( numBSPDrawVerts * sizeof( float ) ); - memset( shadeAngles, 0, numBSPDrawVerts * sizeof( float ) ); + shadeAngles = safe_malloc0( numBSPDrawVerts * sizeof( float ) ); /* allocate smoothed table */ cs = ( numBSPDrawVerts / 8 ) + 1; - smoothed = safe_malloc( cs ); - memset( smoothed, 0, cs ); + smoothed = safe_malloc0( cs ); /* set default shade angle */ defaultShadeAngle = DEG2RAD( shadeAngleDegrees ); @@ -1492,6 +1503,7 @@ float DirtForSample( trace_t *trace ){ /* set endpoint */ VectorMA( trace->origin, dirtDepth, direction, trace->end ); SetupTrace( trace ); + VectorSet(trace->color, 1.0f, 1.0f, 1.0f); /* trace */ TraceLine( trace ); @@ -1514,6 +1526,7 @@ float DirtForSample( trace_t *trace ){ /* set endpoint */ VectorMA( trace->origin, dirtDepth, direction, trace->end ); SetupTrace( trace ); + VectorSet(trace->color, 1.0f, 1.0f, 1.0f); /* trace */ TraceLine( trace ); @@ -1527,6 +1540,7 @@ float DirtForSample( trace_t *trace ){ /* direct ray */ VectorMA( trace->origin, dirtDepth, normal, trace->end ); SetupTrace( trace ); + VectorSet(trace->color, 1.0f, 1.0f, 1.0f); /* trace */ TraceLine( trace ); @@ -1737,9 +1751,8 @@ static qboolean SubmapRawLuxel( rawLightmap_t *lm, int x, int y, float bx, float origin2 = SUPER_ORIGIN( x, y ); //% normal2 = SUPER_NORMAL( x, y ); } - else - { - Error( "Spurious lightmap S vector\n" ); + else { + Sys_FPrintf( SYS_WRN, "WARNING: Spurious lightmap S vector\n" ); } VectorSubtract( origin2, origin, originVecs[ 0 ] ); @@ -1762,16 +1775,13 @@ static qboolean SubmapRawLuxel( rawLightmap_t *lm, int x, int y, float bx, float origin2 = SUPER_ORIGIN( x, y ); //% normal2 = SUPER_NORMAL( x, y ); } - else{ - Sys_Printf( "WARNING: Spurious lightmap T vector\n" ); + else { + Sys_FPrintf( SYS_WRN, "WARNING: Spurious lightmap T vector\n" ); } VectorSubtract( origin2, origin, originVecs[ 1 ] ); - //% VectorSubtract( normal2, normal, normalVecs[ 1 ] ); /* calculate new origin */ - //% VectorMA( origin, bx, originVecs[ 0 ], sampleOrigin ); - //% VectorMA( sampleOrigin, by, originVecs[ 1 ], sampleOrigin ); for ( i = 0; i < 3; i++ ) sampleOrigin[ i ] = sampleOrigin[ i ] + ( bx * originVecs[ 0 ][ i ] ) + ( by * originVecs[ 1 ][ i ] ); @@ -1782,10 +1792,6 @@ static qboolean SubmapRawLuxel( rawLightmap_t *lm, int x, int y, float bx, float } /* calculate new normal */ - //% VectorMA( normal, bx, normalVecs[ 0 ], sampleNormal ); - //% VectorMA( sampleNormal, by, normalVecs[ 1 ], sampleNormal ); - //% if( VectorNormalize( sampleNormal, sampleNormal ) <= 0.0f ) - //% return qfalse; normal = SUPER_NORMAL( x, y ); VectorCopy( normal, sampleNormal ); @@ -2193,7 +2199,7 @@ void IlluminateRawLightmap( int rawLightmapNum ){ /* max of MAX_LIGHTMAPS (4) styles allowed to hit a surface/lightmap */ if ( lightmapNum >= MAX_LIGHTMAPS ) { - Sys_Printf( "WARNING: Hit per-surface style limit (%d)\n", MAX_LIGHTMAPS ); + Sys_FPrintf( SYS_WRN, "WARNING: Hit per-surface style limit (%d)\n", MAX_LIGHTMAPS ); continue; } @@ -2213,7 +2219,7 @@ void IlluminateRawLightmap( int rawLightmapNum ){ } /* set luxel filter radius */ - luxelFilterRadius = superSample * filterRadius / lm->sampleSize; + luxelFilterRadius = lm->sampleSize != 0 ? superSample * filterRadius / lm->sampleSize : 0; if ( luxelFilterRadius == 0 && ( filterRadius > 0.0f || filter ) ) { luxelFilterRadius = 1; } @@ -2245,42 +2251,31 @@ void IlluminateRawLightmap( int rawLightmapNum ){ normal = SUPER_NORMAL( x, y ); flag = SUPER_FLAG( x, y ); -#if 0 - ////////// 27's temp hack for testing edge clipping //// - if ( origin[0] == 0 && origin[1] == 0 && origin[2] == 0 ) { - lightLuxel[ 1 ] = 255; - lightLuxel[ 3 ] = 1.0f; - totalLighted++; - } - else -#endif - { - /* set contribution count */ - lightLuxel[ 3 ] = 1.0f; + /* set contribution count */ + lightLuxel[ 3 ] = 1.0f; - /* setup trace */ - trace.cluster = *cluster; - VectorCopy( origin, trace.origin ); - VectorCopy( normal, trace.normal ); + /* setup trace */ + trace.cluster = *cluster; + VectorCopy( origin, trace.origin ); + VectorCopy( normal, trace.normal ); - /* get light for this sample */ - LightContributionToSample( &trace ); - VectorCopy( trace.color, lightLuxel ); + /* get light for this sample */ + LightContributionToSample( &trace ); + VectorCopy( trace.color, lightLuxel ); - /* add the contribution to the deluxemap */ - if ( deluxemap ) { - VectorCopy( trace.directionContribution, lightDeluxel ); - } + /* add the contribution to the deluxemap */ + if ( deluxemap ) { + VectorCopy( trace.directionContribution, lightDeluxel ); + } - /* check for evilness */ - if ( trace.forceSubsampling > 1.0f && ( lightSamples > 1 || lightRandomSamples ) && luxelFilterRadius == 0 ) { + /* check for evilness */ + if ( trace.forceSubsampling > 1.0f && ( lightSamples > 1 || lightRandomSamples ) && luxelFilterRadius == 0 ) { totalLighted++; - *flag |= FLAG_FORCE_SUBSAMPLING; /* force */ - } - /* add to count */ - else if ( trace.color[ 0 ] || trace.color[ 1 ] || trace.color[ 2 ] ) { - totalLighted++; - } + *flag |= FLAG_FORCE_SUBSAMPLING; /* force */ + } + /* add to count */ + else if ( trace.color[ 0 ] || trace.color[ 1 ] || trace.color[ 2 ] ) { + totalLighted++; } } } @@ -2408,8 +2403,7 @@ void IlluminateRawLightmap( int rawLightmapNum ){ if ( lm->superLuxels[ lightmapNum ] == NULL ) { /* allocate sampling lightmap storage */ size = lm->sw * lm->sh * SUPER_LUXEL_SIZE * sizeof( float ); - lm->superLuxels[ lightmapNum ] = safe_malloc( size ); - memset( lm->superLuxels[ lightmapNum ], 0, size ); + lm->superLuxels[ lightmapNum ] = safe_malloc0( size ); } /* set style */ @@ -2608,8 +2602,6 @@ void IlluminateRawLightmap( int rawLightmapNum ){ { /* get cluster */ cluster = SUPER_CLUSTER( x, y ); - //% if( *cluster < 0 ) // TODO why not do this check? These pixels should be zero anyway - //% continue; /* get particulars */ luxel = SUPER_LUXEL( lightmapNum, x, y ); @@ -2733,45 +2725,6 @@ void IlluminateRawLightmap( int rawLightmapNum ){ } } } - - -#if 0 - // audit pass - for ( lightmapNum = 0; lightmapNum < MAX_LIGHTMAPS; lightmapNum++ ) - { - /* early out */ - if ( lm->superLuxels[ lightmapNum ] == NULL ) { - continue; - } - for ( y = 0; y < lm->sh; y++ ) - for ( x = 0; x < lm->sw; x++ ) - { - /* get cluster */ - cluster = SUPER_CLUSTER( x, y ); - luxel = SUPER_LUXEL( lightmapNum, x, y ); - deluxel = SUPER_DELUXEL( x, y ); - if ( !luxel || !deluxel || !cluster ) { - Sys_FPrintf( SYS_VRB, "WARNING: I got NULL'd.\n" ); - continue; - } - else if ( *cluster < 0 ) { - // unmapped pixel - // should have neither deluxemap nor lightmap - if ( deluxel[3] ) { - Sys_FPrintf( SYS_VRB, "WARNING: I have written deluxe to an unmapped luxel. Sorry.\n" ); - } - } - else - { - // mapped pixel - // should have both deluxemap and lightmap - if ( deluxel[3] ) { - Sys_FPrintf( SYS_VRB, "WARNING: I forgot to write deluxe to a mapped luxel. Sorry.\n" ); - } - } - } - } -#endif } @@ -3181,7 +3134,7 @@ void IlluminateVertexes( int num ){ determines opaque brushes in the world and find sky shaders for sunlight calculations */ -void SetupBrushesFlags( int mask_any, int test_any, int mask_all, int test_all ){ +void SetupBrushesFlags( unsigned int mask_any, unsigned int test_any, unsigned int mask_all, unsigned int test_all ){ int i, j, b; unsigned int compileFlags, allCompileFlags; qboolean inside; @@ -3673,7 +3626,7 @@ void SetupEnvelopes( qboolean forGrid, qboolean fastFlag ){ else{ light->flags &= ~LIGHT_FAST_TEMP; } - if ( fastpoint && ( light->flags != EMIT_AREA ) ) { + if ( fastpoint && ( light->type != EMIT_AREA ) ) { light->flags |= LIGHT_FAST_TEMP; } if ( light->si && light->si->noFast ) { @@ -3792,7 +3745,7 @@ void SetupEnvelopes( qboolean forGrid, qboolean fastFlag ){ for ( i = 0; i < 3; i++ ) { if ( mins[ i ] > light->origin[ i ] || maxs[ i ] < light->origin[ i ] ) { - //% Sys_Printf( "WARNING: Light PVS bounds (%.0f, %.0f, %.0f) -> (%.0f, %.0f, %.0f)\ndo not encompass light %d (%f, %f, %f)\n", + //% Sys_FPrintf( SYS_WRN, "WARNING: Light PVS bounds (%.0f, %.0f, %.0f) -> (%.0f, %.0f, %.0f)\ndo not encompass light %d (%f, %f, %f)\n", //% mins[ 0 ], mins[ 1 ], mins[ 2 ], //% maxs[ 0 ], maxs[ 1 ], maxs[ 2 ], //% numLights, light->origin[ 0 ], light->origin[ 1 ], light->origin[ 2 ] ); @@ -4248,6 +4201,7 @@ float FloodLightForSample( trace_t *trace, float floodLightDistance, qboolean fl //VectorMA( trace->origin, 1, direction, trace->origin ); SetupTrace( trace ); + VectorSet(trace->color, 1.0f, 1.0f, 1.0f); /* trace */ TraceLine( trace ); contribution = 1; @@ -4480,6 +4434,9 @@ void FloodlightIlluminateLightmap( rawLightmap_t *lm ){ continue; } + if( lm->styles[lightmapNum] != LS_NORMAL && lm->styles[lightmapNum] != LS_NONE ) // isStyleLight + continue; + /* apply floodlight to each luxel */ for ( y = 0; y < lm->sh; y++ ) {