From 918a4e8cd944dee29d587fc4fcfdb5635ae9a2f2 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 11 Jun 2025 17:10:47 +0200 Subject: [PATCH] add tilted fog span drawer fixes the red fog blocks on mkrevamp --- src/r_draw.h | 2 ++ src/r_draw_span.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/r_plane.cpp | 3 +++ src/screen.c | 1 + 4 files changed, 46 insertions(+) diff --git a/src/r_draw.h b/src/r_draw.h index 946139ac1..fc8b344e7 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -141,6 +141,7 @@ enum SPANDRAWFUNC_TILTEDWATER, SPANDRAWFUNC_FOG, + SPANDRAWFUNC_TILTEDFOG, SPANDRAWFUNC_MAX }; @@ -258,6 +259,7 @@ void R_DrawTranslucentSpan(drawspandata_t* ds); void R_DrawTranslucentWaterSpan(drawspandata_t* ds); void R_DrawFogSpan(drawspandata_t* ds); +void R_DrawFogSpan_Tilted(drawspandata_t* ds); void R_DrawSplat_Tilted(drawspandata_t* ds); void R_DrawSplat(drawspandata_t* ds); diff --git a/src/r_draw_span.c b/src/r_draw_span.c index 54400fac4..15ae7b1a2 100644 --- a/src/r_draw_span.c +++ b/src/r_draw_span.c @@ -1188,3 +1188,43 @@ void R_DrawSplat_Tilted(drawspandata_t* ds) } #endif } + +void R_DrawFogSpan_Tilted(drawspandata_t* ds) +{ + int width = ds->x2 - ds->x1; + float iz = ds->szp.z + ds->szp.y*(centery-ds->y) + ds->szp.x*(ds->x1-centerx); + register UINT8 *dest; + + local_for_thread INT32 *tiltlighting = NULL; + local_for_thread INT32 oldviewwidth = 0; + + // dont realloc every frame pls thx + if (tiltlighting == NULL || oldviewwidth != viewwidth) + { + tiltlighting = realloc(tiltlighting, sizeof(*tiltlighting) * viewwidth); + oldviewwidth = viewwidth; + } + + dest = R_Address(ds->x1, ds->y); + + // Lighting is simple. It's just linear interpolation from start to end + { + float planelightfloat = PLANELIGHTFLOAT; + float lightstart, lightend; + + lightend = (iz + ds->szp.x*width) * planelightfloat; + lightstart = iz * planelightfloat; + + R_CalcTiltedLighting(tiltlighting, ds->x1, ds->x2, FLOAT_TO_FIXED(lightstart), FLOAT_TO_FIXED(lightend)); + //CONS_Printf("tilted lighting %f to %f (foc %f)\n", lightstart, lightend, focallengthf); + } + + do + { + UINT8 *colormap = ds->planezlight[tiltlighting[ds->x1++]] + (ds->colormap - colormaps); + *dest = colormap[*dest]; + dest++; + } + while (--width >= 0); +} + diff --git a/src/r_plane.cpp b/src/r_plane.cpp index b3aa29f7b..c7a5f793b 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -1213,6 +1213,9 @@ void R_DrawSinglePlane(drawspandata_t* ds, visplane_t *pl, boolean allow_paralle case SPANDRAWFUNC_SPLAT: spanfunctype = SPANDRAWFUNC_TILTEDSPLAT; break; + case SPANDRAWFUNC_FOG: + spanfunctype = SPANDRAWFUNC_TILTEDFOG; + break; default: spanfunctype = SPANDRAWFUNC_TILTED; break; diff --git a/src/screen.c b/src/screen.c index 3d83d57fb..cec9b4b9b 100644 --- a/src/screen.c +++ b/src/screen.c @@ -94,6 +94,7 @@ static void SCR_SetDrawFuncs(void) spanfuncs[SPANDRAWFUNC_WATER] = R_DrawTranslucentWaterSpan; spanfuncs[SPANDRAWFUNC_TILTEDWATER] = R_DrawTranslucentWaterSpan_Tilted; spanfuncs[SPANDRAWFUNC_FOG] = R_DrawFogSpan; + spanfuncs[SPANDRAWFUNC_TILTEDFOG] = R_DrawFogSpan_Tilted; colfuncs[BASEDRAWFUNC] = R_DrawColumn; colfuncs[COLDRAWFUNC_FUZZY] = R_DrawTranslucentColumn;