From 5532266b147858d2184f42dd42d59722c20f6d3d Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Mon, 20 Nov 2017 22:43:44 +0100 Subject: [PATCH 1/4] - Fix softpoly sprite positioning bug --- src/polyrenderer/scene/poly_sprite.cpp | 41 ++++++++++---------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/src/polyrenderer/scene/poly_sprite.cpp b/src/polyrenderer/scene/poly_sprite.cpp index 02cb9e657..8bc1c5054 100644 --- a/src/polyrenderer/scene/poly_sprite.cpp +++ b/src/polyrenderer/scene/poly_sprite.cpp @@ -57,18 +57,17 @@ bool RenderPolySprite::GetLine(AActor *thing, DVector2 &left, DVector2 &right) double thingxscalemul = spriteScale.X / tex->Scale.X; double thingyscalemul = spriteScale.Y / tex->Scale.Y; - if (flipTextureX) - pos.X -= (tex->GetWidth() - tex->LeftOffset) * thingxscalemul; - else - pos.X -= tex->LeftOffset * thingxscalemul; - - double spriteHalfWidth = thingxscalemul * tex->GetWidth() * 0.5; + double spriteWidth = thingxscalemul * tex->GetWidth(); double spriteHeight = thingyscalemul * tex->GetHeight(); - pos.X += spriteHalfWidth; + double offsetX; + if (flipTextureX) + offsetX = (tex->GetWidth() - tex->LeftOffset) * thingxscalemul; + else + offsetX = tex->LeftOffset * thingxscalemul; - left = DVector2(pos.X - viewpoint.Sin * spriteHalfWidth, pos.Y + viewpoint.Cos * spriteHalfWidth); - right = DVector2(pos.X + viewpoint.Sin * spriteHalfWidth, pos.Y - viewpoint.Cos * spriteHalfWidth); + left = DVector2(pos.X - viewpoint.Sin * offsetX, pos.Y + viewpoint.Cos * offsetX); + right = DVector2(left.X + viewpoint.Sin * spriteWidth, left.Y - viewpoint.Cos * spriteWidth); return true; } @@ -81,36 +80,26 @@ void RenderPolySprite::Render(PolyRenderThread *thread, const TriMatrix &worldTo const auto &viewpoint = PolyRenderer::Instance()->Viewpoint; DVector3 thingpos = thing->InterpolatedPosition(viewpoint.TicFrac); - DVector3 pos = thingpos; + double posZ = thingpos.Z; uint32_t spritetype = (thing->renderflags & RF_SPRITETYPEMASK); if (spritetype == RF_FACESPRITE) - pos.Z -= thing->Floorclip; + posZ -= thing->Floorclip; if (thing->flags2 & MF2_FLOATBOB) - pos.Z += thing->GetBobOffset(viewpoint.TicFrac); + posZ += thing->GetBobOffset(viewpoint.TicFrac); bool flipTextureX = false; FTexture *tex = GetSpriteTexture(thing, flipTextureX); if (tex == nullptr || tex->UseType == FTexture::TEX_Null) return; - DVector2 spriteScale = thing->Scale; - double thingxscalemul = spriteScale.X / tex->Scale.X; - double thingyscalemul = spriteScale.Y / tex->Scale.Y; - double spriteHalfWidth = thingxscalemul * tex->GetWidth() * 0.5; + double thingyscalemul = thing->Scale.Y / tex->Scale.Y; double spriteHeight = thingyscalemul * tex->GetHeight(); - if (flipTextureX) - pos.X -= (tex->GetWidth() - tex->LeftOffset) * thingxscalemul; - else - pos.X -= tex->LeftOffset * thingxscalemul; - - pos.X += spriteHalfWidth; - - pos.Z -= (tex->GetHeight() - tex->TopOffset) * thingyscalemul; - pos.Z = PerformSpriteClipAdjustment(thing, thingpos, spriteHeight, pos.Z); + posZ -= (tex->GetHeight() - tex->TopOffset) * thingyscalemul; + posZ = PerformSpriteClipAdjustment(thing, thingpos, spriteHeight, posZ); //double depth = 1.0; //visstyle_t visstyle = GetSpriteVisStyle(thing, depth); @@ -142,7 +131,7 @@ void RenderPolySprite::Render(PolyRenderThread *thread, const TriMatrix &worldTo vertices[i].x = (float)p.X; vertices[i].y = (float)p.Y; - vertices[i].z = (float)(pos.Z + spriteHeight * offsets[i].second); + vertices[i].z = (float)(posZ + spriteHeight * offsets[i].second); vertices[i].w = 1.0f; vertices[i].u = (float)(offsets[i].first * tex->Scale.X); vertices[i].v = (float)((1.0f - offsets[i].second) * tex->Scale.Y); From 2bc86b52c8e8cf2005e8ab3d894f7a62625d1caf Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Tue, 21 Nov 2017 04:05:47 -0500 Subject: [PATCH 2/4] - fixed a few of the more obvious logic errors --- src/gl/renderer/gl_postprocess.cpp | 2 +- src/vectors.h | 1 + src/win32/fb_d3d9.cpp | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp index cea7cbb3f..7202ee2a9 100644 --- a/src/gl/renderer/gl_postprocess.cpp +++ b/src/gl/renderer/gl_postprocess.cpp @@ -938,7 +938,7 @@ int FGLRenderer::PTM_BestColor (const uint32_t *pal_in, int r, int g, int b, int static bool firstTime = true; static float trackpowtable = 0.; - double fbestdist, fdist; + double fbestdist = (double)(1<<53), fdist; int bestcolor = 0; if (firstTime || trackpowtable != gl_paltonemap_powtable) diff --git a/src/vectors.h b/src/vectors.h index 5fa0970f1..95d7c5fdf 100644 --- a/src/vectors.h +++ b/src/vectors.h @@ -651,6 +651,7 @@ struct TVector3 TVector3 &operator ^= (const TVector3 &other) { *this = *this ^ other; + return *this; } }; diff --git a/src/win32/fb_d3d9.cpp b/src/win32/fb_d3d9.cpp index d568ce60f..63722a371 100644 --- a/src/win32/fb_d3d9.cpp +++ b/src/win32/fb_d3d9.cpp @@ -1223,7 +1223,7 @@ void D3DFB::Flip() { RECT box; GetClientRect(Window, &box); - if (box.right > 0 && box.right > 0 && (Width != box.right || Height != box.bottom)) + if (box.right > 0 && (Width != box.right || Height != box.bottom)) { Resize(box.right, box.bottom); From 47e9975e9068e4c2f6020937122c9d2f83601994 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Tue, 21 Nov 2017 05:20:02 -0500 Subject: [PATCH 3/4] - fixed a couple of fixes from the previous commit --- src/gl/renderer/gl_postprocess.cpp | 2 +- src/win32/fb_d3d9.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp index 7202ee2a9..142358af6 100644 --- a/src/gl/renderer/gl_postprocess.cpp +++ b/src/gl/renderer/gl_postprocess.cpp @@ -938,7 +938,7 @@ int FGLRenderer::PTM_BestColor (const uint32_t *pal_in, int r, int g, int b, int static bool firstTime = true; static float trackpowtable = 0.; - double fbestdist = (double)(1<<53), fdist; + double fbestdist = DBL_MAX, fdist; int bestcolor = 0; if (firstTime || trackpowtable != gl_paltonemap_powtable) diff --git a/src/win32/fb_d3d9.cpp b/src/win32/fb_d3d9.cpp index 63722a371..ff05faca9 100644 --- a/src/win32/fb_d3d9.cpp +++ b/src/win32/fb_d3d9.cpp @@ -1223,7 +1223,7 @@ void D3DFB::Flip() { RECT box; GetClientRect(Window, &box); - if (box.right > 0 && (Width != box.right || Height != box.bottom)) + if (box.right > 0 && box.bottom > 0 && (Width != box.right || Height != box.bottom)) { Resize(box.right, box.bottom); From 495fc79fe93b0ea6a92e8889dbe14e426449ce17 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Tue, 21 Nov 2017 05:26:46 -0500 Subject: [PATCH 4/4] - added dpJudas's drawer fix for the upscaled fuzz drawing --- src/swrenderer/drawers/r_draw.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/swrenderer/drawers/r_draw.cpp b/src/swrenderer/drawers/r_draw.cpp index c894e46ce..793cf2ae4 100644 --- a/src/swrenderer/drawers/r_draw.cpp +++ b/src/swrenderer/drawers/r_draw.cpp @@ -195,7 +195,7 @@ namespace swrenderer { if (r_fuzzscale) { - int next_random = 0; + static int next_random = 0; fuzzpos = (fuzzpos + fuzz_random_x_offset[next_random] * FUZZTABLE / 100) % FUZZTABLE;