diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c
index 35a01ffd11ed25d0d7943ddd37a95e82238fd132..924808343e5c6ade6654a12d970ca318fa4ec7f2 100644
--- a/src/hardware/hw_main.c
+++ b/src/hardware/hw_main.c
@@ -1719,12 +1719,12 @@ static void HWR_StoreWallRange(double startfrac, double endfrac)
 				if (!(gr_linedef->flags & ML_DONTPEGBOTTOM))
 					texturevpegbottom = 0;
 				else if (gr_linedef->flags & ML_EFFECT1)
-					texturevpegbottom = worldbottom - worldlow;
+					texturevpegbottom = worldtop - worldlow;
 				else
-					texturevpegbottom = gr_frontsector->floorheight - gr_backsector->floorheight;
+					texturevpegbottom = gr_frontsector->ceilingheight - gr_backsector->floorheight;
 #else
 				if (gr_linedef->flags & ML_DONTPEGBOTTOM)
-					texturevpegbottom = worldbottom - worldlow;
+					texturevpegbottom = worldtop - worldlow;
                 else
                     texturevpegbottom = 0;
 #endif
diff --git a/src/r_segs.c b/src/r_segs.c
index 59b4f5db936c2cd4a8b2e83738324e4e4384708d..cfca6b59ca07f94c3e390048f361c66936fe5f09 100644
--- a/src/r_segs.c
+++ b/src/r_segs.c
@@ -2214,7 +2214,7 @@ void R_StoreWallRange(INT32 start, INT32 stop)
 #ifdef ESLOPE
 			if (!(linedef->flags & ML_EFFECT1)) { // Ignore slopes for lower/upper textures unless flag is checked
 				if (linedef->flags & ML_DONTPEGBOTTOM)
-					rw_bottomtexturemid = frontsector->floorheight - viewz;
+					rw_bottomtexturemid = frontsector->ceilingheight - viewz; // use front ceilingheight, not floorheight
 				else
 					rw_bottomtexturemid = backsector->floorheight - viewz;
 			} else
@@ -2223,7 +2223,7 @@ void R_StoreWallRange(INT32 start, INT32 stop)
 			{
 				// bottom of texture at bottom
 				// top of texture at top
-				rw_bottomtexturemid = worldbottom;
+				rw_bottomtexturemid = worldtop; // use front ceilingheight, not floorheight
 #ifdef ESLOPE
 				rw_bottomtextureslide = floorfrontslide;
 #endif