Make sector texture offsets not scale

This commit is contained in:
Lactozilla 2023-11-24 13:44:20 -03:00
parent b411b9e523
commit 89770d9821
2 changed files with 38 additions and 50 deletions

View file

@ -373,8 +373,9 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool
INT32 i; INT32 i;
float height; // constant y for all points on the convex flat polygon float height; // constant y for all points on the convex flat polygon
float flatxref, flatyref, anglef = 0.0f; float anglef = 0.0f;
float fflatwidth = 64.0f, fflatheight = 64.0f; float fflatwidth = 64.0f, fflatheight = 64.0f;
float xscale, yscale;
float tempxsow, tempytow; float tempxsow, tempytow;
float scrollx = 0.0f, scrolly = 0.0f; float scrollx = 0.0f, scrolly = 0.0f;
@ -409,11 +410,7 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool
slope = gl_frontsector->c_slope; slope = gl_frontsector->c_slope;
} }
// Set fixedheight to the slope's height from our viewpoint, if we have a slope height = FixedToFloat(fixedheight);
if (slope)
fixedheight = P_GetSlopeZAt(slope, viewx, viewy);
height = FIXED_TO_FLOAT(fixedheight);
// Allocate plane-vertex buffer if we need to // Allocate plane-vertex buffer if we need to
if (!planeVerts || nrPlaneVerts > numAllocedPlaneVerts) if (!planeVerts || nrPlaneVerts > numAllocedPlaneVerts)
@ -449,25 +446,21 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool
else // set no texture else // set no texture
HWR_SetCurrentTexture(NULL); HWR_SetCurrentTexture(NULL);
// reference point for flat texture coord for each vertex around the polygon
flatxref = 0.0;
flatyref = 0.0;
// transform // transform
if (FOFsector != NULL) if (FOFsector != NULL)
{ {
if (!isceiling) // it's a floor if (!isceiling) // it's a floor
{ {
fflatwidth /= FixedToFloat(FOFsector->floorxscale); xscale = FixedToFloat(FOFsector->floorxscale);
fflatheight /= FixedToFloat(FOFsector->flooryscale); yscale = FixedToFloat(FOFsector->flooryscale);
scrollx = FixedToFloat(FOFsector->floorxoffset) / fflatwidth; scrollx = FixedToFloat(FOFsector->floorxoffset) / fflatwidth;
scrolly = FixedToFloat(FOFsector->flooryoffset) / fflatheight; scrolly = FixedToFloat(FOFsector->flooryoffset) / fflatheight;
angle = FOFsector->floorangle; angle = FOFsector->floorangle;
} }
else // it's a ceiling else // it's a ceiling
{ {
fflatwidth /= FixedToFloat(FOFsector->ceilingxscale); xscale = FixedToFloat(FOFsector->ceilingxscale);
fflatheight /= FixedToFloat(FOFsector->ceilingyscale); yscale = FixedToFloat(FOFsector->ceilingyscale);
scrollx = FixedToFloat(FOFsector->ceilingxoffset) / fflatwidth; scrollx = FixedToFloat(FOFsector->ceilingxoffset) / fflatwidth;
scrolly = FixedToFloat(FOFsector->ceilingyoffset) / fflatheight; scrolly = FixedToFloat(FOFsector->ceilingyoffset) / fflatheight;
angle = FOFsector->ceilingangle; angle = FOFsector->ceilingangle;
@ -477,16 +470,16 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool
{ {
if (!isceiling) // it's a floor if (!isceiling) // it's a floor
{ {
fflatwidth /= FixedToFloat(gl_frontsector->floorxscale); xscale = FixedToFloat(gl_frontsector->floorxscale);
fflatheight /= FixedToFloat(gl_frontsector->flooryscale); yscale = FixedToFloat(gl_frontsector->flooryscale);
scrollx = FixedToFloat(gl_frontsector->floorxoffset) / fflatwidth; scrollx = FixedToFloat(gl_frontsector->floorxoffset) / fflatwidth;
scrolly = FixedToFloat(gl_frontsector->flooryoffset) / fflatheight; scrolly = FixedToFloat(gl_frontsector->flooryoffset) / fflatheight;
angle = gl_frontsector->floorangle; angle = gl_frontsector->floorangle;
} }
else // it's a ceiling else // it's a ceiling
{ {
fflatwidth /= FixedToFloat(gl_frontsector->ceilingxscale); xscale = FixedToFloat(gl_frontsector->ceilingxscale);
fflatheight /= FixedToFloat(gl_frontsector->ceilingyscale); yscale = FixedToFloat(gl_frontsector->ceilingyscale);
scrollx = FixedToFloat(gl_frontsector->ceilingxoffset) / fflatwidth; scrollx = FixedToFloat(gl_frontsector->ceilingxoffset) / fflatwidth;
scrolly = FixedToFloat(gl_frontsector->ceilingyoffset) / fflatheight; scrolly = FixedToFloat(gl_frontsector->ceilingyoffset) / fflatheight;
angle = gl_frontsector->ceilingangle; angle = gl_frontsector->ceilingangle;
@ -497,8 +490,8 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool
#define SETUP3DVERT(vert, vx, vy) {\ #define SETUP3DVERT(vert, vx, vy) {\
/* Hurdler: add scrolling texture on floor/ceiling */\ /* Hurdler: add scrolling texture on floor/ceiling */\
vert->s = (float)(((vx) / fflatwidth) - flatxref + scrollx);\ vert->s = ((vx) / fflatwidth) + (scrollx / xscale);\
vert->t = (float)(flatyref - ((vy) / fflatheight) + scrolly);\ vert->t = -((vy) / fflatheight) + (scrolly / yscale);\
\ \
/* Need to rotate before translate */\ /* Need to rotate before translate */\
if (angle) /* Only needs to be done if there's an altered angle */\ if (angle) /* Only needs to be done if there's an altered angle */\
@ -509,15 +502,18 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool
vert->t = (tempxsow * sin(anglef)) + (tempytow * cos(anglef));\ vert->t = (tempxsow * sin(anglef)) + (tempytow * cos(anglef));\
}\ }\
\ \
vert->x = (vx);\ vert->s *= xscale;\
vert->y = height;\ vert->t *= yscale;\
vert->z = (vy);\
\ \
if (slope)\ if (slope)\
{\ {\
fixedheight = P_GetSlopeZAt(slope, FLOAT_TO_FIXED((vx)), FLOAT_TO_FIXED((vy)));\ fixedheight = P_GetSlopeZAt(slope, FloatToFixed((vx)), FloatToFixed((vy)));\
vert->y = FIXED_TO_FLOAT(fixedheight);\ height = FixedToFloat(fixedheight);\
}\ }\
\
vert->x = (vx);\
vert->y = height;\
vert->z = (vy);\
} }
for (i = 0, v3d = planeVerts; i < (INT32)nrPlaneVerts; i++,v3d++,pv++) for (i = 0, v3d = planeVerts; i < (INT32)nrPlaneVerts; i++,v3d++,pv++)
@ -2649,8 +2645,8 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling,
INT32 i; INT32 i;
float height = FIXED_TO_FLOAT(fixedheight); // constant y for all points on the convex flat polygon float height = FIXED_TO_FLOAT(fixedheight); // constant y for all points on the convex flat polygon
float flatxref, flatyref;
float fflatwidth = 64.0f, fflatheight = 64.0f; float fflatwidth = 64.0f, fflatheight = 64.0f;
float xscale, yscale;
float scrollx = 0.0f, scrolly = 0.0f; float scrollx = 0.0f, scrolly = 0.0f;
float tempxsow, tempytow, anglef = 0.0f; float tempxsow, tempytow, anglef = 0.0f;
@ -2701,11 +2697,6 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling,
else // set no texture else // set no texture
HWR_SetCurrentTexture(NULL); HWR_SetCurrentTexture(NULL);
// reference point for flat texture coord for each vertex around the polygon
flatxref = 0.0;
flatyref = 0.0;
// transform // transform
v3d = planeVerts; v3d = planeVerts;
@ -2713,16 +2704,16 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling,
{ {
if (!isceiling) // it's a floor if (!isceiling) // it's a floor
{ {
fflatwidth /= FixedToFloat(FOFsector->floorxscale); xscale = FixedToFloat(FOFsector->floorxscale);
fflatheight /= FixedToFloat(FOFsector->flooryscale); yscale = FixedToFloat(FOFsector->flooryscale);
scrollx = FixedToFloat(FOFsector->floorxoffset) / fflatwidth; scrollx = FixedToFloat(FOFsector->floorxoffset) / fflatwidth;
scrolly = FixedToFloat(FOFsector->flooryoffset) / fflatheight; scrolly = FixedToFloat(FOFsector->flooryoffset) / fflatheight;
angle = FOFsector->floorangle; angle = FOFsector->floorangle;
} }
else // it's a ceiling else // it's a ceiling
{ {
fflatwidth /= FixedToFloat(FOFsector->ceilingxscale); xscale = FixedToFloat(FOFsector->ceilingxscale);
fflatheight /= FixedToFloat(FOFsector->ceilingyscale); yscale = FixedToFloat(FOFsector->ceilingyscale);
scrollx = FixedToFloat(FOFsector->ceilingxoffset) / fflatwidth; scrollx = FixedToFloat(FOFsector->ceilingxoffset) / fflatwidth;
scrolly = FixedToFloat(FOFsector->ceilingyoffset) / fflatheight; scrolly = FixedToFloat(FOFsector->ceilingyoffset) / fflatheight;
angle = FOFsector->ceilingangle; angle = FOFsector->ceilingangle;
@ -2732,16 +2723,16 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling,
{ {
if (!isceiling) // it's a floor if (!isceiling) // it's a floor
{ {
fflatwidth /= FixedToFloat(gl_frontsector->floorxscale); xscale = FixedToFloat(gl_frontsector->floorxscale);
fflatheight /= FixedToFloat(gl_frontsector->flooryscale); yscale = FixedToFloat(gl_frontsector->flooryscale);
scrollx = FixedToFloat(gl_frontsector->floorxoffset) / fflatwidth; scrollx = FixedToFloat(gl_frontsector->floorxoffset) / fflatwidth;
scrolly = FixedToFloat(gl_frontsector->flooryoffset) / fflatheight; scrolly = FixedToFloat(gl_frontsector->flooryoffset) / fflatheight;
angle = gl_frontsector->floorangle; angle = gl_frontsector->floorangle;
} }
else // it's a ceiling else // it's a ceiling
{ {
fflatwidth /= FixedToFloat(gl_frontsector->ceilingxscale); xscale = FixedToFloat(gl_frontsector->ceilingxscale);
fflatheight /= FixedToFloat(gl_frontsector->ceilingyscale); yscale = FixedToFloat(gl_frontsector->ceilingyscale);
scrollx = FixedToFloat(gl_frontsector->ceilingxoffset) / fflatwidth; scrollx = FixedToFloat(gl_frontsector->ceilingxoffset) / fflatwidth;
scrolly = FixedToFloat(gl_frontsector->ceilingyoffset) / fflatheight; scrolly = FixedToFloat(gl_frontsector->ceilingyoffset) / fflatheight;
angle = gl_frontsector->ceilingangle; angle = gl_frontsector->ceilingangle;
@ -2754,8 +2745,8 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling,
{ {
// Go from the polysector's original vertex locations // Go from the polysector's original vertex locations
// Means the flat is offset based on the original vertex locations // Means the flat is offset based on the original vertex locations
v3d->s = (float)((FIXED_TO_FLOAT(polysector->origVerts[i].x) / fflatwidth) - flatxref + scrollx); v3d->s = (FixedToFloat(polysector->origVerts[i].x) / fflatwidth) + (scrollx / xscale);
v3d->t = (float)(flatyref - (FIXED_TO_FLOAT(polysector->origVerts[i].y) / fflatheight) + scrolly); v3d->t = -(FixedToFloat(polysector->origVerts[i].y) / fflatheight) + (scrolly / yscale);
// Need to rotate before translate // Need to rotate before translate
if (angle) // Only needs to be done if there's an altered angle if (angle) // Only needs to be done if there's an altered angle
@ -2767,6 +2758,9 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling,
v3d->t = (tempxsow * sin(anglef)) + (tempytow * cos(anglef)); v3d->t = (tempxsow * sin(anglef)) + (tempytow * cos(anglef));
} }
v3d->s *= xscale;
v3d->t *= yscale;
v3d->x = FIXED_TO_FLOAT(polysector->vertices[i]->x); v3d->x = FIXED_TO_FLOAT(polysector->vertices[i]->x);
v3d->y = height; v3d->y = height;
v3d->z = FIXED_TO_FLOAT(polysector->vertices[i]->y); v3d->z = FIXED_TO_FLOAT(polysector->vertices[i]->y);

View file

@ -380,8 +380,8 @@ visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel,
if (!slope) // Don't mess with this right now if a slope is involved if (!slope) // Don't mess with this right now if a slope is involved
{ {
xoff += viewx; xoff += FixedMul(viewx, xscale);
yoff -= viewy; yoff -= FixedMul(viewy, yscale);
if (plangle != 0) if (plangle != 0)
{ {
@ -411,12 +411,6 @@ visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel,
} }
} }
if (!slope)
{
xoff = FixedMul(xoff, xscale);
yoff = FixedMul(yoff, yscale);
}
// This appears to fix the Nimbus Ruins sky bug. // This appears to fix the Nimbus Ruins sky bug.
if (picnum == skyflatnum && pfloor) if (picnum == skyflatnum && pfloor)
{ {
@ -809,7 +803,7 @@ static void R_SetSlopePlaneVectors(visplane_t *pl, INT32 y, fixed_t xoff, fixed_
{ {
R_SetScaledSlopePlane(pl->slope, pl->viewx, pl->viewy, pl->viewz, R_SetScaledSlopePlane(pl->slope, pl->viewx, pl->viewy, pl->viewz,
FixedDiv(FRACUNIT, pl->xscale), FixedDiv(FRACUNIT, pl->yscale), FixedDiv(FRACUNIT, pl->xscale), FixedDiv(FRACUNIT, pl->yscale),
xoff, yoff, pl->viewangle, pl->plangle); FixedDiv(xoff, pl->xscale), FixedDiv(yoff, pl->yscale), pl->viewangle, pl->plangle);
} }
else else
R_SetSlopePlane(pl->slope, pl->viewx, pl->viewy, pl->viewz, xoff, yoff, pl->viewangle, pl->plangle); R_SetSlopePlane(pl->slope, pl->viewx, pl->viewy, pl->viewz, xoff, yoff, pl->viewangle, pl->plangle);