diff --git a/src/swrenderer/line/r_wallsetup.cpp b/src/swrenderer/line/r_wallsetup.cpp index 071ae799d..579ff21f2 100644 --- a/src/swrenderer/line/r_wallsetup.cpp +++ b/src/swrenderer/line/r_wallsetup.cpp @@ -159,19 +159,35 @@ namespace swrenderer float invZ = WallT.InvZorg + WallT.InvZstep * (float)(x1 + 0.5 - viewport->CenterX); float uGradient = WallT.UoverZstep; float zGradient = WallT.InvZstep; - float xrepeat = (float)walxrepeat; + float xrepeat = (float)fabs(walxrepeat); float depthScale = (float)(WallT.InvZstep * viewport->WallTMapScale2); float depthOrg = (float)(-WallT.UoverZstep * viewport->WallTMapScale2); - for (int x = x1; x < x2; x++) + if (walxrepeat < 0.0) { - float u = uOverZ / invZ; + for (int x = x1; x < x2; x++) + { + float u = uOverZ / invZ; - UPos[x] = (fixed_t)(u * xrepeat * FRACUNIT); - VStep[x] = depthOrg + u * depthScale; + UPos[x] = (fixed_t)((xrepeat - u * xrepeat) * FRACUNIT); + VStep[x] = depthOrg + u * depthScale; - uOverZ += uGradient; - invZ += zGradient; + uOverZ += uGradient; + invZ += zGradient; + } + } + else + { + for (int x = x1; x < x2; x++) + { + float u = uOverZ / invZ; + + UPos[x] = (fixed_t)(u * xrepeat * FRACUNIT); + VStep[x] = depthOrg + u * depthScale; + + uOverZ += uGradient; + invZ += zGradient; + } } } @@ -183,16 +199,31 @@ namespace swrenderer float invZ = WallT.InvZorg + WallT.InvZstep * (float)(x1 + 0.5 - viewport->CenterX); float uGradient = WallT.UoverZstep; float zGradient = WallT.InvZstep; - float xrepeat = (float)walxrepeat; + float xrepeat = (float)fabs(walxrepeat); - for (int x = x1; x < x2; x++) + if (walxrepeat < 0.0f) { - float u = uOverZ / invZ * xrepeat; + for (int x = x1; x < x2; x++) + { + float u = uOverZ / invZ * xrepeat - xrepeat; - UPos[x] = (fixed_t)(u * FRACUNIT); + UPos[x] = (fixed_t)(u * FRACUNIT); - uOverZ += uGradient; - invZ += zGradient; + uOverZ += uGradient; + invZ += zGradient; + } + } + else + { + for (int x = x1; x < x2; x++) + { + float u = uOverZ / invZ * xrepeat; + + UPos[x] = (fixed_t)(u * FRACUNIT); + + uOverZ += uGradient; + invZ += zGradient; + } } } }