From fdf2464ccf8a33e63a475cc589fe08bd3c14611f Mon Sep 17 00:00:00 2001 From: chromaticpipe Date: Fri, 1 Aug 2025 10:33:19 -0500 Subject: [PATCH] Configurable sector brightness in software --- src/hardware/hw_main.c | 2 +- src/hardware/hw_main.h | 1 - src/r_main.cpp | 4 ++++ src/r_main.h | 1 + src/r_plane.cpp | 11 +++++++---- src/r_segs.cpp | 18 +++++++++--------- src/r_things.cpp | 6 +++--- 7 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index b74f66291..adf9cc13f 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -296,7 +296,7 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col } // Clamp the light level, since it can sometimes go out of the 0-255 range from animations - light_level = min(max(light_level, cv_glsecbright.value), 255); + light_level = min(max(light_level, cv_secbright.value), 255); V_CubeApply(&tint_color.s.red, &tint_color.s.green, &tint_color.s.blue); V_CubeApply(&fade_color.s.red, &fade_color.s.green, &fade_color.s.blue); diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 52581545f..d73e161c9 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -97,7 +97,6 @@ extern consvar_t cv_glcoronasize; #endif extern consvar_t cv_glshaders, cv_glallowshaders; -extern consvar_t cv_glsecbright; extern consvar_t cv_glmodels; // SRB2Kart: We don't like these options. diff --git a/src/r_main.cpp b/src/r_main.cpp index 2612d4daa..f857dcb2e 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -140,6 +140,7 @@ static CV_PossibleValue_t fov_cons_t[] = {{60*FRACUNIT, "MIN"}, {179*FRACUNIT, " static CV_PossibleValue_t translucenthud_cons_t[] = {{0, "MIN"}, {10, "MAX"}, {0, NULL}}; static CV_PossibleValue_t maxportals_cons_t[] = {{0, "MIN"}, {12, "MAX"}, {0, NULL}}; // lmao rendering 32 portals, you're a card static CV_PossibleValue_t homremoval_cons_t[] = {{0, "No"}, {1, "Yes"}, {2, "Flash"}, {0, NULL}}; +static CV_PossibleValue_t secbright_cons_t[] = {{0, "MIN"}, {255, "MAX"}, {0, NULL}}; static void Fov_OnChange(void); @@ -182,6 +183,8 @@ consvar_t cv_fov[MAXSPLITSCREENPLAYERS] = { // Okay, whoever said homremoval causes a performance hit should be shot. consvar_t cv_homremoval = CVAR_INIT ("homremoval", "Yes", CV_SAVE, homremoval_cons_t, NULL); +consvar_t cv_secbright = CVAR_INIT ("r_secbright", "0", CV_SAVE, secbright_cons_t, NULL); + consvar_t cv_maxportals = CVAR_INIT ("maxportals", "2", CV_SAVE, maxportals_cons_t, NULL); consvar_t cv_renderstats = CVAR_INIT ("renderstats", "Off", 0, CV_OnOff, NULL); @@ -1780,6 +1783,7 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_shadow); CV_RegisterVar(&cv_skybox); CV_RegisterVar(&cv_ffloorclip); + CV_RegisterVar(&cv_secbright); for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { diff --git a/src/r_main.h b/src/r_main.h index c9fd110a7..ad018adaa 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -154,6 +154,7 @@ extern consvar_t cv_fov[MAXSPLITSCREENPLAYERS]; extern consvar_t cv_skybox; extern consvar_t cv_tailspickup; extern consvar_t cv_debugfinishline; +extern consvar_t cv_secbright; extern consvar_t cv_sloperoll; extern consvar_t cv_sliptidetilt; diff --git a/src/r_plane.cpp b/src/r_plane.cpp index c3836b43e..1f44bb27b 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -1038,7 +1038,7 @@ void R_DrawSinglePlane(drawspandata_t *ds, visplane_t *pl, boolean allow_paralle spanfunctype = SPANDRAWFUNC_SPLAT; if (pl->polyobj->translucency == 0 || (pl->extra_colormap && (pl->extra_colormap->flags & CMF_FOG))) - light = (pl->lightlevel >> LIGHTSEGSHIFT); + light = std::max((pl->lightlevel >> LIGHTSEGSHIFT), cv_secbright.value); else light = LIGHTLEVELS-1; } @@ -1079,16 +1079,17 @@ void R_DrawSinglePlane(drawspandata_t *ds, visplane_t *pl, boolean allow_paralle } if ((spanfunctype == SPANDRAWFUNC_SPLAT) || (pl->extra_colormap && (pl->extra_colormap->flags & CMF_FOG))) - light = (pl->lightlevel >> LIGHTSEGSHIFT); + light = std::max((pl->lightlevel >> LIGHTSEGSHIFT), cv_secbright.value); else light = LIGHTLEVELS-1; } else if (pl->ffloor->fofflags & FOF_FOG) { spanfunctype = SPANDRAWFUNC_FOG; - light = (pl->lightlevel >> LIGHTSEGSHIFT); + light = std::max((pl->lightlevel >> LIGHTSEGSHIFT), cv_secbright.value); } - else light = (pl->lightlevel >> LIGHTSEGSHIFT); + else + light = std::max((pl->lightlevel >> LIGHTSEGSHIFT), cv_secbright.value); debug = SW_HI_FOFPLANES; } @@ -1147,6 +1148,8 @@ void R_DrawSinglePlane(drawspandata_t *ds, visplane_t *pl, boolean allow_paralle vidwidth, vidwidth); } } + else + light = std::max((pl->lightlevel >> LIGHTSEGSHIFT), cv_secbright.value); } ds->currentplane = pl; diff --git a/src/r_segs.cpp b/src/r_segs.cpp index e631578f6..af01e3f3d 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -274,7 +274,7 @@ static void R_RenderMaskedSegLoop(drawcolumndata_t* dc, drawseg_t *drawseg, INT3 if ((R_CheckColumnFunc(COLDRAWFUNC_FUZZY) == false) || (rlight->flags & FOF_FOG) || (rlight->extra_colormap && (rlight->extra_colormap->flags & CMF_FOG))) - lightnum = (rlight->lightlevel >> LIGHTSEGSHIFT); + lightnum = std::max((rlight->lightlevel >> LIGHTSEGSHIFT), cv_secbright.value); else lightnum = LIGHTLEVELS - 1; @@ -919,9 +919,9 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) // Check if the current light effects the colormap/lightlevel if (pfloor->fofflags & FOF_FOG) - rlight->lightnum = (pfloor->master->frontsector->lightlevel >> LIGHTSEGSHIFT); + rlight->lightnum = std::max((pfloor->master->frontsector->lightlevel >> LIGHTSEGSHIFT), cv_secbright.value); else - rlight->lightnum = (rlight->lightlevel >> LIGHTSEGSHIFT); + rlight->lightnum = std::max((rlight->lightlevel >> LIGHTSEGSHIFT), cv_secbright.value); if (pfloor->fofflags & FOF_FOG || rlight->flags & FOF_FOG || (rlight->extra_colormap && (rlight->extra_colormap->flags & CMF_FOG))) ; @@ -937,14 +937,14 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) { // Get correct light level! if ((frontsector->extra_colormap && (frontsector->extra_colormap->flags & CMF_FOG))) - lightnum = (frontsector->lightlevel >> LIGHTSEGSHIFT); + lightnum = std::max((frontsector->lightlevel >> LIGHTSEGSHIFT), cv_secbright.value); else if (pfloor->fofflags & FOF_FOG) - lightnum = (pfloor->master->frontsector->lightlevel >> LIGHTSEGSHIFT); + lightnum = std::max((pfloor->master->frontsector->lightlevel >> LIGHTSEGSHIFT), cv_secbright.value); else if (R_CheckColumnFunc(COLDRAWFUNC_FUZZY) == true) lightnum = LIGHTLEVELS-1; else - lightnum = R_FakeFlat(frontsector, &tempsec, &templight, &templight, false) - ->lightlevel >> LIGHTSEGSHIFT; + lightnum = std::max((R_FakeFlat(frontsector, &tempsec, &templight, &templight, false) + ->lightlevel >> LIGHTSEGSHIFT), cv_secbright.value); if (pfloor->fofflags & FOF_FOG || (frontsector->extra_colormap && (frontsector->extra_colormap->flags & CMF_FOG))) ; @@ -1556,7 +1556,7 @@ static void R_RenderSegLoop (drawcolumndata_t* dc) for (i = 0; i < dc->numlights; i++) { INT32 lightnum; - lightnum = (dc->lightlist[i].lightlevel >> LIGHTSEGSHIFT); + lightnum = std::max((dc->lightlist[i].lightlevel >> LIGHTSEGSHIFT), cv_secbright.value); if (dc->lightlist[i].extra_colormap) ; @@ -2665,7 +2665,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) // use different light tables // for horizontal / vertical / diagonal // OPTIMIZE: get rid of LIGHTSEGSHIFT globally - lightnum = (frontsector->lightlevel >> LIGHTSEGSHIFT); + lightnum = std::max((frontsector->lightlevel >> LIGHTSEGSHIFT), cv_secbright.value); if (P_ApplyLightOffset(lightnum, frontsector)) lightnum += curline->lightOffset; diff --git a/src/r_things.cpp b/src/r_things.cpp index 4b95b98cc..c537c5745 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -1320,7 +1320,7 @@ static void R_SplitSprite(vissprite_t *sprite) newsprite->cut = static_cast(newsprite->cut | SC_TOP); if (!(sector->lightlist[i].caster->fofflags & FOF_NOSHADE)) { - lightnum = (*sector->lightlist[i].lightlevel >> LIGHTSEGSHIFT); + lightnum = std::max((*sector->lightlist[i].lightlevel >> LIGHTSEGSHIFT), cv_secbright.value); if (lightnum < 0) spritelights = scalelight[0]; @@ -2354,7 +2354,7 @@ static void R_ProjectSprite(mobj_t *thing) lightnum = thing->subsector->sector->lightlevel; } - lightnum = (lightnum + R_ThingLightLevel(thing)) >> LIGHTSEGSHIFT; + lightnum = std::max((lightnum + R_ThingLightLevel(thing)) >> LIGHTSEGSHIFT, cv_secbright.value); if (maplighting.directional == true && P_SectorUsesDirectionalLighting(thing->subsector->sector)) { @@ -2780,7 +2780,7 @@ void R_AddSprites(sector_t *sec, INT32 lightlevel) { if (sec->heightsec == -1) lightlevel = sec->lightlevel; - lightnum = (lightlevel >> LIGHTSEGSHIFT); + lightnum = std::max((lightlevel >> LIGHTSEGSHIFT), cv_secbright.value); if (lightnum < 0) spritelights = scalelight[0];