diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4e68db60b..8e6233429 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -64,6 +64,7 @@ add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32 tables.c r_bsp.c r_data.c + r_debug.cpp r_draw.c r_fps.c r_main.c diff --git a/src/r_debug.cpp b/src/r_debug.cpp new file mode 100644 index 000000000..d090d230e --- /dev/null +++ b/src/r_debug.cpp @@ -0,0 +1,38 @@ +// RING RACERS +//----------------------------------------------------------------------------- +// Copyright (C) 2023 by James Robert Roman. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file r_debug.cpp +/// \brief Software renderer debugging + +#include // std::clamp + +#include "cxxutil.hpp" + +#include "command.h" +#include "m_fixed.h" +#include "r_main.h" + +namespace +{ + +CV_PossibleValue_t contrast_cons_t[] = {{-FRACUNIT, "MIN"}, {FRACUNIT, "MAX"}, {}}; + +}; // namespace + +consvar_t cv_debugrender_contrast = + CVAR_INIT("debugrender_contrast", "0.0", CV_CHEAT | CV_FLOAT, contrast_cons_t, nullptr); + +INT32 R_AdjustLightLevel(INT32 light) +{ + constexpr fixed_t kRange = (LIGHTLEVELS - 1) * FRACUNIT; + const fixed_t adjust = FixedMul(cv_debugrender_contrast.value, kRange); + + light = std::clamp((light * FRACUNIT) - adjust, 0, kRange); + + return light / FRACUNIT; +} diff --git a/src/r_main.c b/src/r_main.c index b00717810..1e5e7a430 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1656,4 +1656,8 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_fpscap); CV_RegisterVar(&cv_drawpickups); + + // debugging + + CV_RegisterVar(&cv_debugrender_contrast); } diff --git a/src/r_main.h b/src/r_main.h index 01a0d9b31..df17342a2 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -123,6 +123,13 @@ extern consvar_t cv_skybox; extern consvar_t cv_tailspickup; extern consvar_t cv_drawpickups; +// debugging + +INT32 R_AdjustLightLevel(INT32 light); + +extern consvar_t + cv_debugrender_contrast; + // Called by startup code. void R_Init(void); diff --git a/src/r_plane.c b/src/r_plane.c index 4472c9fc3..4638a4081 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -1030,6 +1030,8 @@ void R_DrawSinglePlane(visplane_t *pl) if (light < 0) light = 0; + light = R_AdjustLightLevel(light); + if (pl->slope) { mapfunc = R_MapTiltedPlane; diff --git a/src/r_segs.c b/src/r_segs.c index c00330a4d..b7a25daa0 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -298,6 +298,8 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) else if (P_ApplyLightOffset(lightnum)) lightnum += curline->lightOffset; + lightnum = R_AdjustLightLevel(lightnum); + if (lightnum < 0) walllights = scalelight[0]; else if (lightnum >= LIGHTLEVELS) @@ -413,12 +415,14 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) if ((rlight->flags & FOF_NOSHADE)) continue; - if (rlight->lightnum < 0) + lightnum = R_AdjustLightLevel(rlight->lightnum); + + if (lightnum < 0) xwalllights = scalelight[0]; - else if (rlight->lightnum >= LIGHTLEVELS) + else if (lightnum >= LIGHTLEVELS) xwalllights = scalelight[LIGHTLEVELS-1]; else - xwalllights = scalelight[rlight->lightnum]; + xwalllights = scalelight[lightnum]; pindex = FixedMul(spryscale, LIGHTRESOLUTIONFIX)>>LIGHTSCALESHIFT; @@ -789,6 +793,8 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) else if (P_ApplyLightOffset(lightnum)) lightnum += curline->lightOffset; + lightnum = R_AdjustLightLevel(lightnum); + if (lightnum < 0) walllights = scalelight[0]; else if (lightnum >= LIGHTLEVELS) @@ -963,7 +969,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) lighteffect = !(dc_lightlist[i].flags & FOF_NOSHADE); if (lighteffect) { - lightnum = rlight->lightnum; + lightnum = R_AdjustLightLevel(rlight->lightnum); if (lightnum < 0) xwalllights = scalelight[0]; @@ -1379,6 +1385,8 @@ static void R_RenderSegLoop (void) else if (P_ApplyLightOffset(lightnum)) lightnum += curline->lightOffset; + lightnum = R_AdjustLightLevel(lightnum); + if (lightnum < 0) xwalllights = scalelight[0]; else if (lightnum >= LIGHTLEVELS) @@ -2425,6 +2433,8 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (P_ApplyLightOffset(lightnum)) lightnum += curline->lightOffset; + lightnum = R_AdjustLightLevel(lightnum); + if (lightnum < 0) walllights = scalelight[0]; else if (lightnum >= LIGHTLEVELS)