]> git.rm.cloudns.org Git - xonotic/netradiant.git/commitdiff
Fix ioq3 compatibility bug with lightgrid and only one light.
authorRudolf Polzer <divVerent@gmail.com>
Sat, 18 Apr 2020 00:10:39 +0000 (20:10 -0400)
committerRudolf Polzer <divVerent@gmail.com>
Sat, 18 Apr 2020 00:18:58 +0000 (20:18 -0400)
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.

tools/quake3/q3map2/light.c
tools/quake3/q3map2/light_ydnar.c
tools/quake3/q3map2/q3map2.h

index 79098148cbe5c503b33cf27497ed6c33fe486ec8..b8ad379f158b9ab853d966d97f0fc3b44b18cfe4 100644 (file)
@@ -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 );
        }
 
index 19d1b31a6d1f8c291fbd2188a38b4151e8fea31e..5653987557017e5db02c49537149233c13b1e880 100644 (file)
@@ -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;
+}
 
 
 /* -------------------------------------------------------------------------------
index 89f7915ace9d276d6d054ccdd6ee46bac76038d3..dfc971a92dd71d0912218a53e431e6d5c7421161 100644 (file)
@@ -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 );