@@ -3446,7 +3446,7 @@ static void R_SetConstantColorLightGrid( const byte color[3] )
34463446 gridPoint2->direction [ 0 ] = floatToSnorm8 (0 .0f );
34473447 gridPoint2->direction [ 1 ] = floatToSnorm8 (0 .0f );
34483448 gridPoint2->direction [ 2 ] = floatToSnorm8 (1 .0f );
3449- gridPoint2->unused = 255 ;
3449+ gridPoint2->isSet = 255 ;
34503450
34513451 w->lightGridData1 = gridPoint1;
34523452 w->lightGridData2 = gridPoint2;
@@ -3589,6 +3589,13 @@ void R_LoadLightGrid( lump_t *l )
35893589 tmpAmbient[ 2 ] = in->ambient [ 2 ];
35903590 tmpAmbient[ 3 ] = 255 ;
35913591
3592+ /* Make sure we don't change the (0, 0, 0) points because those are points in walls,
3593+ which we'll fill up by interpolating nearby points later */
3594+ if ( tmpAmbient[ 0 ] == 0 && tmpAmbient[ 1 ] == 0 && tmpAmbient[ 2 ] == 0 )
3595+ {
3596+ continue ;
3597+ }
3598+
35923599 tmpDirected[ 0 ] = in->directed [ 0 ];
35933600 tmpDirected[ 1 ] = in->directed [ 1 ];
35943601 tmpDirected[ 2 ] = in->directed [ 2 ];
@@ -3612,12 +3619,8 @@ void R_LoadLightGrid( lump_t *l )
36123619 const float forceAmbient = r_forceAmbient.Get ();
36133620 if ( ambientColor[0 ] < forceAmbient &&
36143621 ambientColor[1 ] < forceAmbient &&
3615- ambientColor[2 ] < forceAmbient &&
3616- /* Make sure we don't change the (0, 0, 0) points because those are points in walls,
3617- which we'll fill up by interpolating nearby points later */
3618- ( ambientColor[0 ] != 0 ||
3619- ambientColor[1 ] != 0 ||
3620- ambientColor[2 ] != 0 ) ) {
3622+ ambientColor[2 ] < forceAmbient )
3623+ {
36213624 VectorSet ( ambientColor, forceAmbient, forceAmbient, forceAmbient );
36223625 }
36233626
@@ -3639,16 +3642,15 @@ void R_LoadLightGrid( lump_t *l )
36393642 gridPoint1->color [ 1 ] = floatToUnorm8 ( 0 .5f * (ambientColor[ 1 ] + directedColor[ 1 ]) );
36403643 gridPoint1->color [ 2 ] = floatToUnorm8 ( 0 .5f * (ambientColor[ 2 ] + directedColor[ 2 ]) );
36413644
3642- // Avoid division-by-zero.
36433645 float ambientLength = VectorLength (ambientColor);
36443646 float directedLength = VectorLength (directedColor);
36453647 float length = ambientLength + directedLength;
3646- gridPoint1->ambientPart = length ? floatToUnorm8 ( ambientLength / length ) : 0 ;
3648+ gridPoint1->ambientPart = floatToUnorm8 ( ambientLength / length );
36473649
36483650 gridPoint2->direction [0 ] = 128 + floatToSnorm8 ( direction[ 0 ] );
36493651 gridPoint2->direction [1 ] = 128 + floatToSnorm8 ( direction[ 1 ] );
36503652 gridPoint2->direction [2 ] = 128 + floatToSnorm8 ( direction[ 2 ] );
3651- gridPoint2->unused = 255 ;
3653+ gridPoint2->isSet = 255 ;
36523654 }
36533655
36543656 // fill in gridpoints with zero light (samples in walls) to avoid
@@ -3671,10 +3673,10 @@ void R_LoadLightGrid( lump_t *l )
36713673 from[ 0 ] = i - 1 ;
36723674 to[ 0 ] = i + 1 ;
36733675
3674- if ( gridPoint1->color [ 0 ] ||
3675- gridPoint1->color [ 1 ] ||
3676- gridPoint1->color [ 2 ] )
3676+ if ( gridPoint2->isSet )
3677+ {
36773678 continue ;
3679+ }
36783680
36793681 scale = R_InterpolateLightGrid ( w, from, to, factors,
36803682 ambientColor, directedColor,
@@ -3695,6 +3697,7 @@ void R_LoadLightGrid( lump_t *l )
36953697 gridPoint2->direction [0 ] = 128 + floatToSnorm8 (direction[0 ]);
36963698 gridPoint2->direction [1 ] = 128 + floatToSnorm8 (direction[1 ]);
36973699 gridPoint2->direction [2 ] = 128 + floatToSnorm8 (direction[2 ]);
3700+ gridPoint2->isSet = 255 ;
36983701 }
36993702 }
37003703 }
0 commit comments