From 49b725a1b243cafe045ea81dc558b26e8e9f3cbb Mon Sep 17 00:00:00 2001 From: Garux Date: Tue, 14 Apr 2020 19:45:00 +0300 Subject: [PATCH] Fix q3 compatibility bug with lightgrid and only one light. Correct math requires the ambient component of the lightgrid to be zero in that case. However, q3 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 https://gitlab.com/xonotic/netradiant/-/issues/137 --- tools/quake3/q3map2/light.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/quake3/q3map2/light.c b/tools/quake3/q3map2/light.c index f0457d28..daa83815 100644 --- a/tools/quake3/q3map2/light.c +++ b/tools/quake3/q3map2/light.c @@ -1731,6 +1731,15 @@ void TraceGrid( int num ){ /* vortex: apply gridscale and gridambientscale here */ ColorToBytes( color, bgp->ambient[ i ], gridScale * gridAmbientScale ); ColorToBytes( gp->directed[ i ], bgp->directed[ i ], gridScale ); + /* + * HACK: if there's a non-zero directed component, this + * lightgrid cell is useful. However, q3 skips grid + * cells with zero ambient. So let's force ambient to be + * nonzero unless directed is zero too. + */ + if( bgp->ambient[i][0] + bgp->ambient[i][1] + bgp->ambient[i][2] == 0 + && bgp->directed[i][0] + bgp->directed[i][1] + bgp->directed[i][2] != 0 ) + VectorSet( bgp->ambient[i], 1, 1, 1 ); } /* debug code */