Skip to content

Commit

Permalink
spearmint: Fix repeatedly overbrighting the light grid
Browse files Browse the repository at this point in the history
Running vid_restart repeatedly in a map caused the ambient light to
increase as reported by r_debugLight 1. (It stops at 255 bightness and
normalizes the color.)

Spearmint's BSP abstraction layer shares the same BSP data for collision
and the renderer. The renderer applied overbright to the bspFile_t
light grid data each time it registered the map causing the changes to
persist across vid_restart.

The renderer now allocates memory for overbright light grid.
  • Loading branch information
zturtleman committed Sep 27, 2024
1 parent 16faf6f commit f21a776
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion code/renderergl1/tr_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1985,11 +1985,13 @@ void R_LoadLightGrid( const bspFile_t *bsp ) {
return;
}

w->lightGridData = bsp->lightGridData;
w->lightGridData = ri.Hunk_Alloc( bsp->numGridPoints * 8, h_low );
w->numGridPoints = bsp->numGridPoints;
w->lightGridArray = bsp->lightGridArray;
w->numGridArrayPoints = bsp->numGridArrayPoints;

Com_Memcpy( w->lightGridData, bsp->lightGridData, bsp->numGridPoints * 8 );

// deal with overbright bits
for ( i = 0 ; i < bsp->numGridPoints ; i++ ) {
R_ColorShiftLightingBytes( 4, &w->lightGridData[i*8], &w->lightGridData[i*8] );
Expand Down
4 changes: 3 additions & 1 deletion code/renderergl2/tr_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2533,11 +2533,13 @@ void R_LoadLightGrid( const bspFile_t *bsp ) {
return;
}

w->lightGridData = bsp->lightGridData;
w->lightGridData = ri.Hunk_Alloc( bsp->numGridPoints * 8, h_low );
w->numGridPoints = bsp->numGridPoints;
w->lightGridArray = bsp->lightGridArray;
w->numGridArrayPoints = bsp->numGridArrayPoints;

Com_Memcpy( w->lightGridData, bsp->lightGridData, bsp->numGridPoints * 8 );

// deal with overbright bits
for ( i = 0 ; i < bsp->numGridPoints ; i++ ) {
R_ColorShiftLightingBytes( 4, &w->lightGridData[i*8], &w->lightGridData[i*8] );
Expand Down

0 comments on commit f21a776

Please sign in to comment.