From 920b322d72bb69dfa29f1815eec4a69eb83609a5 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Wed, 11 Mar 2020 02:18:43 +0100 Subject: [PATCH] Add missing segment clipping clamps for decals, sprites and wall sprites --- src/rendering/swrenderer/things/r_decal.cpp | 10 +--------- src/rendering/swrenderer/things/r_sprite.cpp | 2 +- src/rendering/swrenderer/things/r_wallsprite.cpp | 2 +- .../swrenderer/viewport/r_spritedrawer.cpp | 16 +++++++++++++--- .../swrenderer/viewport/r_spritedrawer.h | 2 +- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/rendering/swrenderer/things/r_decal.cpp b/src/rendering/swrenderer/things/r_decal.cpp index cfcc01ccd..263b86d3a 100644 --- a/src/rendering/swrenderer/things/r_decal.cpp +++ b/src/rendering/swrenderer/things/r_decal.cpp @@ -218,14 +218,6 @@ namespace swrenderer } } - // Clip sprite to drawseg - x1 = MAX(clipper->x1, x1); - x2 = MIN(clipper->x2, x2); - if (x1 >= x2) - { - return; - } - // Prepare lighting ProjectedWallLight light; light.SetColormap(lightsector, curline); @@ -250,7 +242,7 @@ namespace swrenderer if (visible) { thread->PrepareTexture(WallSpriteTile, decal->RenderStyle); - drawerargs.DrawMasked(thread, zpos + WallSpriteTile->GetTopOffset(0) * decal->ScaleY, decal->ScaleY, decal->RenderFlags & RF_XFLIP, decal->RenderFlags & RF_YFLIP, WallC, light, WallSpriteTile, mfloorclip, mceilingclip, decal->RenderStyle); + drawerargs.DrawMasked(thread, zpos + WallSpriteTile->GetTopOffset(0) * decal->ScaleY, decal->ScaleY, decal->RenderFlags & RF_XFLIP, decal->RenderFlags & RF_YFLIP, WallC, clipper->x1, clipper->x2, light, WallSpriteTile, mfloorclip, mceilingclip, decal->RenderStyle); } // If this sprite is RF_CLIPFULL on a two-sided line, needrepeat will diff --git a/src/rendering/swrenderer/things/r_sprite.cpp b/src/rendering/swrenderer/things/r_sprite.cpp index 164432e69..cedb0fa22 100644 --- a/src/rendering/swrenderer/things/r_sprite.cpp +++ b/src/rendering/swrenderer/things/r_sprite.cpp @@ -274,7 +274,7 @@ namespace swrenderer mlight.SetSpriteLight(); drawerargs.SetBaseColormap(Light.BaseColormap); - drawerargs.DrawMasked(thread, gzt - floorclip, SpriteScale, renderflags & RF_XFLIP, renderflags & RF_YFLIP, wallc, mlight, pic, portalfloorclip, mceilingclip, RenderStyle); + drawerargs.DrawMasked(thread, gzt - floorclip, SpriteScale, renderflags & RF_XFLIP, renderflags & RF_YFLIP, wallc, x1, x2, mlight, pic, portalfloorclip, mceilingclip, RenderStyle); } } } diff --git a/src/rendering/swrenderer/things/r_wallsprite.cpp b/src/rendering/swrenderer/things/r_wallsprite.cpp index d80cb0edc..b5ee7ba14 100644 --- a/src/rendering/swrenderer/things/r_wallsprite.cpp +++ b/src/rendering/swrenderer/things/r_wallsprite.cpp @@ -199,6 +199,6 @@ namespace swrenderer } drawerargs.SetBaseColormap(spr->Light.BaseColormap); - drawerargs.DrawMasked(thread, spr->gzt, spr->yscale, spr->renderflags & RF_XFLIP, spr->renderflags & RF_YFLIP, spr->wallc, mlight, WallSpriteTile, floorclip, mceilingclip, spr->RenderStyle); + drawerargs.DrawMasked(thread, spr->gzt, spr->yscale, spr->renderflags & RF_XFLIP, spr->renderflags & RF_YFLIP, spr->wallc, x1, x2, mlight, WallSpriteTile, floorclip, mceilingclip, spr->RenderStyle); } } diff --git a/src/rendering/swrenderer/viewport/r_spritedrawer.cpp b/src/rendering/swrenderer/viewport/r_spritedrawer.cpp index 9a0586076..7d3af54ec 100644 --- a/src/rendering/swrenderer/viewport/r_spritedrawer.cpp +++ b/src/rendering/swrenderer/viewport/r_spritedrawer.cpp @@ -43,7 +43,7 @@ namespace swrenderer colfunc = &SWPixelFormatDrawers::DrawColumn; } - void SpriteDrawerArgs::DrawMasked(RenderThread* thread, double topZ, double scale, bool flipX, bool flipY, const FWallCoords& WallC, const ProjectedWallLight& light, FSoftwareTexture* tex, const short* mfloorclip, const short* mceilingclip, FRenderStyle style) + void SpriteDrawerArgs::DrawMasked(RenderThread* thread, double topZ, double scale, bool flipX, bool flipY, const FWallCoords& WallC, int clipx1, int clipx2, const ProjectedWallLight& light, FSoftwareTexture* tex, const short* mfloorclip, const short* mceilingclip, FRenderStyle style) { auto viewport = thread->Viewport.get(); auto cameraLight = CameraLight::Instance(); @@ -73,8 +73,10 @@ namespace swrenderer wpos += wstepX * 0.5f; upos += ustepX * 0.5f; - int x1 = WallC.sx1; - int x2 = WallC.sx2; + int x1 = MAX(WallC.sx1, clipx1); + int x2 = MIN(WallC.sx2, clipx2); + if (x1 >= x2) + return; float centerY = thread->Viewport->CenterY; topZ -= thread->Viewport->viewpoint.Pos.Z; @@ -88,6 +90,14 @@ namespace swrenderer float lightpos = light.GetLightPos(x1); float lightstep = light.GetLightStep(); + if (x1 > WallC.sx1) + { + int dx = x1 - WallC.sx1; + upos += ustepX * dx; + wpos += wstepX * dx; + lightpos += lightstep * dx; + } + dc_viewport = viewport; dc_textureheight = texheight; diff --git a/src/rendering/swrenderer/viewport/r_spritedrawer.h b/src/rendering/swrenderer/viewport/r_spritedrawer.h index f07b81fba..f233d2c03 100644 --- a/src/rendering/swrenderer/viewport/r_spritedrawer.h +++ b/src/rendering/swrenderer/viewport/r_spritedrawer.h @@ -33,7 +33,7 @@ namespace swrenderer void SetSolidColor(int color) { dc_color = color; dc_color_bgra = GPalette.BaseColors[color]; } void SetDynamicLight(uint32_t color) { dynlightcolor = color; } - void DrawMasked(RenderThread* thread, double topZ, double scale, bool flipX, bool flipY, const FWallCoords& WallC, const ProjectedWallLight& light, FSoftwareTexture* texture, const short* mfloorclip, const short* mceilingclip, FRenderStyle style); + void DrawMasked(RenderThread* thread, double topZ, double scale, bool flipX, bool flipY, const FWallCoords& WallC, int clipx1, int clipx2, const ProjectedWallLight& light, FSoftwareTexture* texture, const short* mfloorclip, const short* mceilingclip, FRenderStyle style); void DrawMasked2D(RenderThread *thread, double x0, double x1, double y0, double y1, FSoftwareTexture* texture, FRenderStyle style); void DrawVoxelBlocks(RenderThread *thread, const VoxelBlock *blocks, int blockcount);