software: cleanup sky hacks

still horrid, but atleast this wont give me braindamage each time i have to look at it
this also read stale data from the previous frames and was just insanely messy
this still sucks ass but oh well
This commit is contained in:
alufolie91 committed 2026-07-13 07:47:48 +02:00
1 parent 7048eeacc3
commit 7971f76885
1 file changed
+71 -57
+71 -57
View File
@@ -713,16 +713,11 @@ void R_RenderThickSideRange(drawseg_t *drawseg, INT32 x1, INT32 x2, ffloor_t *pf
rw_scalestep = drawseg->scalestep;
spryscale = drawseg->scale1 + (x1 - drawseg->x1)*rw_scalestep;
#define CLAMPMAX INT32_MAX
#define CLAMPMIN (-INT32_MAX) // This is not INT32_MIN on purpose! INT32_MIN makes the drawers freak out.
auto overflow_clamp = [&](INT64 overflow_test)
{
return (overflow_test > (INT64)CLAMPMAX) ? CLAMPMAX :
(overflow_test > (INT64)CLAMPMIN) ? (fixed_t)overflow_test :
CLAMPMIN;
// This is not INT32_MIN on purpose! INT32_MIN makes the drawers freak out.
return (fixed_t)std::clamp<INT64>(overflow_test, (-INT32_MAX), INT32_MAX);
};
#undef CLAMPMAX
#undef CLAMPMIN
dc->numlights = 0;
if (frontsector->numlights)
@@ -2604,71 +2599,91 @@ void R_StoreWallRange(INT32 start, INT32 stop)
if (linedef->special == HORIZONSPECIAL) // HORIZON LINES
{
topstep = bottomstep = 0;
topfrac = bottomfrac = (centeryfrac>>4);
topfrac = bottomfrac = (centeryfrac >> 4);
topfrac++; // Prevent 1px HOM
}
else
{
topstep = -FixedMul(rw_scalestep, worldtop);
topfrac = (centeryfrac >> 4) - FixedMul(worldtop, rw_scale);
// for anyone that sees this
// dont.
// this is absolute shit-tier hacks
// but i just cant determine this in any sane way
// but this checks a shitton of things to make software handle skies better
auto set_topstep_normal = [&]
{
topstep = -FixedMul(rw_scalestep, worldtop);
topfrac = (centeryfrac>>4) - FixedMul(worldtop, rw_scale);
};
// untextured seg
if (!segtextured && !curline->polyseg)
if (!segtextured && !curline->polyseg) // not for polyobjects.....
{
const bool tophigh = (worldhigh <= worldtop && worldhighslope <= worldtopslope);
const boolean nofrontsky = (frontsector->floorpic != skyflatnum && frontsector->ceilingpic != skyflatnum);
const boolean inskybox = (skyboxmo[0] && cv_skybox.value && newview->sky); // dont mess with skyVisible within skybox rendering!
// if we cant see the goddamn skyplane, well there wont be any skybox
// we could kill skyVisible instead, but i want to keep the performance improvements it yields
// so we do this absolute trash
if ((tophigh
&& (frontsector->floorpic != skyflatnum && frontsector->ceilingpic != skyflatnum)) // try to guess if its a "window"
&& ((!backsector) // single sided
|| ((backsector && (worldhigh != worldtop || worldhighslope != worldtopslope))
&& (backsector->floorheight >= frontsector->ceilingheight || backsector->ceilingheight <= frontsector->floorheight)))) // check if there is a "thok" sector behind it
skyVisible = true;
// this is an attempt to fix issues with textureless single sided lines drawing nothing where they should just draw sky instead
if (tophigh && !backsector && frontsector->ceilingpic == skyflatnum)
// single sided line
if (!backsector)
{
// account for slopes to try and get rid of sharp edges from the black void
if (frontsector->f_slope || (backsector && backsector->f_slope))
// this is an attempt to fix issues with textureless single sided lines drawing nothing where they should just draw sky instead
// there is a sky flat on the ceiling
// so we can assume this is supposed to draw the sky
if (frontsector->ceilingpic == skyflatnum)
{
topstep = -FixedMul(rw_scalestep, worldbottomslope);
topfrac = (centeryfrac>>4) - FixedMul(worldbottomslope, rw_scale);
// just draw sky from top to bottom!
if (frontsector->f_slope)
{
topstep = -FixedMul(rw_scalestep, worldbottomslope);
topfrac = (centeryfrac >> 4) - FixedMul(worldbottomslope, rw_scale);
}
else
{
topstep = -FixedMul(rw_scalestep, worldbottom);
topfrac = (centeryfrac >> 4) - FixedMul(worldbottom, rw_scale);
}
}
else
else if (nofrontsky && !inskybox)
{
topstep = -FixedMul(rw_scalestep, worldbottom);
topfrac = (centeryfrac>>4) - FixedMul(worldbottom, rw_scale);
// completely empty wall without sky flats, just assume skybox is visible then
skyVisible = true;
}
}
else
set_topstep_normal();
else if (nofrontsky && !inskybox) // if there was a skyflat, drawplane would already set skyvisible
{
// "thok walls" are double sided
// so we need to check a few things here
// to be rather conservative
// as skyrendering is pretty costly!
// ideally we´d just dont care and always draw the skytexture
// or skybox at any time, like gl does
// wonder if there would be a fast way to draw atleast just the texture?
// gotta shift those here for proper comparisons
const INT32 whigh = worldhigh >> 4;
const INT32 whslope = worldhighslope >> 4;
// check if there is a window to force skybox to draw
if ((whigh <= worldtop && whslope <= worldtopslope) && (backsector->ceilingpic == skyflatnum)) // backsector has a skyflat?
skyVisible = true;
// otherwise check for thokwalls
else if ((whigh != worldtop || whslope != worldtopslope) && // FIXME: i forgor what this was for lol
(backsector->floorheight >= frontsector->ceilingheight || // thok walls usually are set up like that...
frontsector->floorheight >= backsector->ceilingheight)) // floor higher than the other sides ceiling
skyVisible = true;
}
}
else
set_topstep_normal();
bottomstep = -FixedMul(rw_scalestep, worldbottom);
bottomfrac = (centeryfrac>>4) - FixedMul(worldbottom, rw_scale);
bottomfrac = (centeryfrac >> 4) - FixedMul(worldbottom, rw_scale);
if (frontsector->c_slope)
{
fixed_t topfracend = (centeryfrac>>4) - FixedMul(worldtopslope, ds_p->scale2);
fixed_t topfracend = (centeryfrac >> 4) - FixedMul(worldtopslope, ds_p->scale2);
topstep = (topfracend-topfrac)/(range);
}
if (frontsector->f_slope)
{
fixed_t bottomfracend = (centeryfrac>>4) - FixedMul(worldbottomslope, ds_p->scale2);
fixed_t bottomfracend = (centeryfrac >> 4) - FixedMul(worldbottomslope, ds_p->scale2);
bottomstep = (bottomfracend-bottomfrac)/(range);
}
}
@@ -2706,12 +2721,13 @@ void R_StoreWallRange(INT32 start, INT32 stop)
if (leftheight < worldbottom && rightheight < worldbottomslope)
continue;
if (leftheight > worldtop && rightheight > worldtopslope && i+1 < dc.numlights && frontsector->lightlist[i+1].height > frontsector->ceilingheight)
if ((leftheight > worldtop) && (rightheight > worldtopslope) &&
(i+1 < dc.numlights) && (frontsector->lightlist[i+1].height > frontsector->ceilingheight))
continue;
}
rlight->height = (centeryfrac>>4) - FixedMul(leftheight, rw_scale);
rlight->heightstep = (centeryfrac>>4) - FixedMul(rightheight, ds_p->scale2);
rlight->height = (centeryfrac >> 4) - FixedMul(leftheight, rw_scale);
rlight->heightstep = (centeryfrac >> 4) - FixedMul(rightheight, ds_p->scale2);
rlight->heightstep = (rlight->heightstep-rlight->height)/(range);
rlight->flags = static_cast<ffloortype_e>(light->flags);
@@ -2730,10 +2746,9 @@ void R_StoreWallRange(INT32 start, INT32 stop)
leftheight >>= 4;
rightheight >>= 4;
rlight->botheight = (centeryfrac>>4) - FixedMul(leftheight, rw_scale);
rlight->botheightstep = (centeryfrac>>4) - FixedMul(rightheight, ds_p->scale2);
rlight->botheight = (centeryfrac >> 4) - FixedMul(leftheight, rw_scale);
rlight->botheightstep = (centeryfrac >> 4) - FixedMul(rightheight, ds_p->scale2);
rlight->botheightstep = (rlight->botheightstep-rlight->botheight)/(range);
}
rlight->lightlevel = *light->lightlevel;
@@ -2754,13 +2769,14 @@ void R_StoreWallRange(INT32 start, INT32 stop)
if (linedef->special == HORIZONSPECIAL) // Horizon lines extend FOFs in contact with them too.
{
visffloor[i].f_step = 0;
visffloor[i].f_frac = (centeryfrac>>4);
visffloor[i].f_frac = (centeryfrac >> 4);
topfrac++; // Prevent 1px HOM
}
else
{
visffloor[i].f_frac = (centeryfrac>>4) - FixedMul(visffloor[i].f_pos, rw_scale);
visffloor[i].f_step = ((centeryfrac>>4) - FixedMul(visffloor[i].f_pos_slope, ds_p->scale2) - visffloor[i].f_frac)/(range);
visffloor[i].f_frac = (centeryfrac >> 4) - FixedMul(visffloor[i].f_pos, rw_scale);
visffloor[i].f_step = (centeryfrac >> 4) - FixedMul(visffloor[i].f_pos_slope, ds_p->scale2);
visffloor[i].f_step = (visffloor[i].f_step - visffloor[i].f_frac)/(range);
}
}
}
@@ -2774,9 +2790,8 @@ void R_StoreWallRange(INT32 start, INT32 stop)
if (toptexture)
{
fixed_t topfracend = (centeryfrac>>4) - FixedMul(worldhighslope, ds_p->scale2);
pixhigh = (centeryfrac>>4) - FixedMul (worldhigh, rw_scale);
fixed_t topfracend = (centeryfrac >> 4) - FixedMul(worldhighslope, ds_p->scale2);
pixhigh = (centeryfrac >> 4) - FixedMul(worldhigh, rw_scale);
pixhighstep = (topfracend-pixhigh)/(range);
// If the lowest part of a ceiling stretching down covers the entire screen
@@ -2786,9 +2801,8 @@ void R_StoreWallRange(INT32 start, INT32 stop)
if (bottomtexture)
{
fixed_t bottomfracend = (centeryfrac>>4) - FixedMul(worldlowslope, ds_p->scale2);
pixlow = (centeryfrac>>4) - FixedMul (worldlow, rw_scale);
fixed_t bottomfracend = (centeryfrac >> 4) - FixedMul(worldlowslope, ds_p->scale2);
pixlow = (centeryfrac >> 4) - FixedMul(worldlow, rw_scale);
pixlowstep = (bottomfracend-pixlow)/(range);
// If the highest part of a floor stretching up covers the entire screen