From: Rudolf Polzer Date: Sat, 18 Apr 2020 00:10:39 +0000 (-0400) Subject: Fix ioq3 compatibility bug with lightgrid and only one light. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=22b786a4801336c623865d4b3e072223152033b3;p=xonotic%2Fnetradiant.git Fix ioq3 compatibility bug with lightgrid and only one light. Correct math requires the ambient component of the lightgrid to be zero in that case. However, ioq3 ignores lightgrid cells with all zero ambient value, EVEN if the directed value is nonzero. This change sets the ambient value to #010101 if it'd be pitch black. This should be a minimal change without affecting light hue that fixes lightgrid rendering. In engines like DarkPlaces, almost no map should look different from this. Fixes #137. --- diff --git a/tools/quake3/q3map2/light.c b/tools/quake3/q3map2/light.c index 79098148..b8ad379f 100644 --- a/tools/quake3/q3map2/light.c +++ b/tools/quake3/q3map2/light.c @@ -1771,7 +1771,17 @@ void TraceGrid( int num ){ } /* vortex: apply gridscale and gridambientscale here */ - ColorToBytes( color, bgp->ambient[ i ], gridScale * gridAmbientScale ); + if (gp->directed[0] || gp->directed[1] || gp->directed[2]) { + /* + * HACK: if there's a non-zero directed component, this + * lightgrid cell is useful. However, ioq3 skips grid + * cells with zero ambient. So let's force ambient to be + * nonzero unless directed is zero too. + */ + ColorToBytesNonZero(color, bgp->ambient[i], gridScale * gridAmbientScale); + } else { + ColorToBytes(color, bgp->ambient[i], gridScale * gridAmbientScale); + } ColorToBytes( gp->directed[ i ], bgp->directed[ i ], gridScale ); } diff --git a/tools/quake3/q3map2/light_ydnar.c b/tools/quake3/q3map2/light_ydnar.c index 19d1b31a..56539875 100644 --- a/tools/quake3/q3map2/light_ydnar.c +++ b/tools/quake3/q3map2/light_ydnar.c @@ -132,6 +132,13 @@ void ColorToBytes( const float *color, byte *colorBytes, float scale ){ colorBytes[ 2 ] = sample[ 2 ]; } +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; +} /* ------------------------------------------------------------------------------- diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 89f7915a..dfc971a9 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -1816,6 +1816,7 @@ void RadFreeLights(); /* light_ydnar.c */ void ColorToBytes( const float *color, byte *colorBytes, float scale ); +void ColorToBytesNonZero( const float *color, byte *colorBytes, float scale ); void SmoothNormals( void ); void MapRawLightmap( int num );