Avoid Z-fighting on extra textures in the OpenGL renderer

This commit is contained in:
Lactozilla 2024-01-25 17:36:33 -03:00
parent 69256fe56a
commit 0535ad845b

View file

@ -1367,6 +1367,24 @@ static void HWR_DoExtraTextureCut(UINT8 intersected, UINT8 which, v2d_t vs, v2d_
HWR_GetExtraTextureCoords(which, polytop, polybottom, polytopslope, polybottomslope, *worldtop, *worldbottom, *worldhigh, *worldlow, *worldtopslope, *worldbottomslope, *worldhighslope, *worldlowslope, midtexheight); HWR_GetExtraTextureCoords(which, polytop, polybottom, polytopslope, polybottomslope, *worldtop, *worldbottom, *worldhigh, *worldlow, *worldtopslope, *worldbottomslope, *worldhighslope, *worldlowslope, midtexheight);
} }
static void HWR_SetWallStartCoordsOffset(FOutVector wallVerts[4], float wallx1, float wally1, angle_t wallang, fixed_t wallpush)
{
wallx1 += FixedToFloat(FixedMul(wallpush, FINECOSINE(wallang)));
wally1 += FixedToFloat(FixedMul(wallpush, FINESINE(wallang)));
wallVerts[0].x = wallVerts[3].x = wallx1;
wallVerts[0].z = wallVerts[3].z = wally1;
}
static void HWR_SetWallEndCoordsOffset(FOutVector wallVerts[4], float wallx2, float wally2, angle_t wallang, fixed_t wallpush)
{
wallx2 += FixedToFloat(FixedMul(wallpush, FINECOSINE(wallang)));
wally2 += FixedToFloat(FixedMul(wallpush, FINESINE(wallang)));
wallVerts[2].x = wallVerts[1].x = wallx2;
wallVerts[2].z = wallVerts[1].z = wally2;
}
// Draws an extra texture (sorry for the length) // Draws an extra texture (sorry for the length)
static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, float xcliplow, float xcliphigh, UINT32 lightnum) static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, float xcliplow, float xcliphigh, UINT32 lightnum)
{ {
@ -1379,6 +1397,9 @@ static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, float xcl
fixed_t v2x = FloatToFixed(ve.x); fixed_t v2x = FloatToFixed(ve.x);
fixed_t v2y = FloatToFixed(ve.y); fixed_t v2y = FloatToFixed(ve.y);
angle_t wallang = (R_PointToAngle2(v1x, v1y, v2x, v2y) - ANGLE_90) >> ANGLETOFINESHIFT;
fixed_t wallpush = FRACUNIT/4 * which;
float flength = gl_curline->flength; float flength = gl_curline->flength;
sector_t *back = gl_backsector ? gl_backsector : gl_frontsector; sector_t *back = gl_backsector ? gl_backsector : gl_frontsector;
@ -1486,10 +1507,8 @@ static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, float xcl
fixed_t lS = polybottomslope; fixed_t lS = polybottomslope;
FOutVector wallVerts[4]; FOutVector wallVerts[4];
wallVerts[0].x = wallVerts[3].x = vs.x; HWR_SetWallStartCoordsOffset(wallVerts, vs.x, vs.y, wallang, wallpush);
wallVerts[0].z = wallVerts[3].z = vs.y; HWR_SetWallEndCoordsOffset(wallVerts, ve.x, ve.y, wallang, wallpush);
wallVerts[2].x = wallVerts[1].x = ve.x;
wallVerts[2].z = wallVerts[1].z = ve.y;
// If this edge extends over a wall that is sloped, it needs to be split // If this edge extends over a wall that is sloped, it needs to be split
UINT8 intersected = 0; UINT8 intersected = 0;
@ -1567,10 +1586,7 @@ static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, float xcl
ve.x = ptx; ve.x = ptx;
ve.y = pty; ve.y = pty;
flength = hypotf(ve.x - vs.x, ve.y - vs.y); HWR_SetWallEndCoordsOffset(wallVerts, ve.x, ve.y, wallang, wallpush);
wallVerts[2].x = wallVerts[1].x = ptx;
wallVerts[2].z = wallVerts[1].z = pty;
} }
else if (intersected == 2) else if (intersected == 2)
{ {
@ -1579,12 +1595,11 @@ static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, float xcl
xcliplowbase += flength * t * FRACUNIT; xcliplowbase += flength * t * FRACUNIT;
flength = hypotf(ve.x - vs.x, ve.y - vs.y); HWR_SetWallStartCoordsOffset(wallVerts, vs.x, vs.y, wallang, wallpush);
wallVerts[0].x = wallVerts[3].x = ptx;
wallVerts[0].z = wallVerts[3].z = pty;
} }
flength = hypotf(ve.x - vs.x, ve.y - vs.y);
xcliplow = xcliplowbase; xcliplow = xcliplowbase;
xcliphigh = xcliplow + (flength*FRACUNIT); xcliphigh = xcliplow + (flength*FRACUNIT);
@ -1713,8 +1728,7 @@ static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, float xcl
if (intersected == 1) if (intersected == 1)
{ {
wallVerts[2].x = wallVerts[1].x = ptx; HWR_SetWallEndCoordsOffset(wallVerts, ptx, pty, wallang, wallpush);
wallVerts[2].z = wallVerts[1].z = pty;
xclipoffset = flength * t * FRACUNIT; xclipoffset = flength * t * FRACUNIT;
xcliphigh = (float)(xcliplow + xclipoffset); xcliphigh = (float)(xcliplow + xclipoffset);
@ -1722,8 +1736,7 @@ static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, float xcl
// Left side // Left side
else if (intersected == 2) else if (intersected == 2)
{ {
wallVerts[0].x = wallVerts[3].x = ptx; HWR_SetWallStartCoordsOffset(wallVerts, ptx, pty, wallang, wallpush);
wallVerts[0].z = wallVerts[3].z = pty;
xcliplow = (float)(xcliphigh - (flength * (1.0f - t) * FRACUNIT)); xcliplow = (float)(xcliphigh - (flength * (1.0f - t) * FRACUNIT));
} }
@ -1787,6 +1800,9 @@ static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, float xcl
else else
HWR_ProjectWall(wallVerts, &Surf, blendmode, lightnum, colormap); HWR_ProjectWall(wallVerts, &Surf, blendmode, lightnum, colormap);
if (!intersected)
return;
// Draw the rest of the wall if it was split // Draw the rest of the wall if it was split
if (intersected == 1) if (intersected == 1)
{ {
@ -1800,14 +1816,10 @@ static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, float xcl
ve.x = ptx; ve.x = ptx;
ve.y = pty; ve.y = pty;
} }
else
return;
// Redefine the wall X/Y // Redefine the wall X/Y
wallVerts[0].x = wallVerts[3].x = vs.x; HWR_SetWallStartCoordsOffset(wallVerts, vs.x, vs.y, wallang, wallpush);
wallVerts[0].z = wallVerts[3].z = vs.y; HWR_SetWallEndCoordsOffset(wallVerts, ve.x, ve.y, wallang, wallpush);
wallVerts[2].x = wallVerts[1].x = ve.x;
wallVerts[2].z = wallVerts[1].z = ve.y;
v1x = FloatToFixed(vs.x); v1x = FloatToFixed(vs.x);
v1y = FloatToFixed(vs.y); v1y = FloatToFixed(vs.y);