From 5532266b147858d2184f42dd42d59722c20f6d3d Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Mon, 20 Nov 2017 22:43:44 +0100 Subject: [PATCH 1/9] - 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 02cb9e6570..8bc1c50549 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/9] - 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 cea7cbb3f0..7202ee2a91 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 5fa0970f1f..95d7c5fdf7 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 d568ce60ff..63722a3719 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/9] - 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 7202ee2a91..142358af68 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 63722a3719..ff05faca9b 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/9] - 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 c894e46ce1..793cf2ae47 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; From 0ef8105e6b6adbf7649fa599ab00d861f017e6fb Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Tue, 21 Nov 2017 18:57:44 +0100 Subject: [PATCH 5/9] - Add missing r_draw.cpp in CMakeLists.txt --- src/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7ede5128bb..f623de5a4a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -702,6 +702,7 @@ set ( SWRENDER_SOURCES swrenderer/r_swrenderer.cpp swrenderer/r_memory.cpp swrenderer/r_renderthread.cpp + swrenderer/drawers/r_draw.cpp swrenderer/drawers/r_draw_pal.cpp swrenderer/drawers/r_draw_rgba.cpp swrenderer/drawers/r_thread.cpp From 4e4f94db2f431e1d384b19cdadbc143dc744b83e Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Wed, 22 Nov 2017 06:32:55 +0100 Subject: [PATCH 6/9] - Implement newer scaled fuzz in softpoly's truecolor non-sse drawer --- src/polyrenderer/drawers/poly_drawer32.h | 42 +++++++++++++----------- src/polyrenderer/poly_renderer.cpp | 2 ++ src/swrenderer/drawers/r_draw.cpp | 4 +-- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/polyrenderer/drawers/poly_drawer32.h b/src/polyrenderer/drawers/poly_drawer32.h index 579488ea30..f3d05ae749 100644 --- a/src/polyrenderer/drawers/poly_drawer32.h +++ b/src/polyrenderer/drawers/poly_drawer32.h @@ -119,7 +119,7 @@ namespace TriScreenDrawerModes } template - FORCEINLINE unsigned int SampleShade32(int32_t u, int32_t v, const uint32_t *texPixels, int texWidth, int texHeight, int &fuzzpos) + FORCEINLINE unsigned int SampleShade32(int32_t u, int32_t v, const uint32_t *texPixels, int texWidth, int texHeight, int x, int y) { if (SamplerT::Mode == (int)Samplers::Shaded) { @@ -140,12 +140,23 @@ namespace TriScreenDrawerModes } else if (SamplerT::Mode == (int)Samplers::Fuzz) { + using namespace swrenderer; + uint32_t texelX = ((((uint32_t)u << 8) >> 16) * texWidth) >> 16; uint32_t texelY = ((((uint32_t)v << 8) >> 16) * texHeight) >> 16; unsigned int sampleshadeout = APART(texPixels[texelX * texHeight + texelY]); sampleshadeout += sampleshadeout >> 7; // 255 -> 256 - sampleshadeout = (sampleshadeout * fuzzcolormap[fuzzpos++]) >> 5; - if (fuzzpos >= FUZZTABLE) fuzzpos = 0; + + fixed_t fuzzscale = (200 << FRACBITS) / viewheight; + + int scaled_x = (x * fuzzscale) >> FRACBITS; + int fuzz_x = fuzz_random_x_offset[scaled_x % FUZZ_RANDOM_X_SIZE] + fuzzpos; + + fixed_t fuzzcount = FUZZTABLE << FRACBITS; + fixed_t fuzz = ((fuzz_x << FRACBITS) + y * fuzzscale) % fuzzcount; + unsigned int alpha = fuzzoffset[fuzz >> FRACBITS]; + + sampleshadeout = (sampleshadeout * alpha) >> 5; return sampleshadeout; } else @@ -373,8 +384,6 @@ private: uint32_t srcalpha = args->uniforms->SrcAlpha(); uint32_t destalpha = args->uniforms->DestAlpha(); - int fuzzpos = (ScreenTriangle::FuzzStart + destX * 123 + destY) % FUZZTABLE; - auto lights = args->uniforms->Lights(); auto num_lights = args->uniforms->NumLights(); FVector3 worldnormal = args->uniforms->Normal(); @@ -505,7 +514,7 @@ private: // Sample fgcolor if (SamplerT::Mode == (int)Samplers::FogBoundary) color = dest[ix]; unsigned int ifgcolor = Sample32(posU, posV, texPixels, texWidth, texHeight, oneU, oneV, color, translation); - unsigned int ifgshade = SampleShade32(posU, posV, texPixels, texWidth, texHeight, fuzzpos); + unsigned int ifgshade = SampleShade32(posU, posV, texPixels, texWidth, texHeight, destX + ix, destY + y); posU += stepU; posV += stepV; @@ -608,7 +617,7 @@ private: // Sample fgcolor if (SamplerT::Mode == (int)Samplers::FogBoundary && (mask0 & (1 << 31))) color = dest[x]; unsigned int ifgcolor = Sample32(posU, posV, texPixels, texWidth, texHeight, oneU, oneV, color, translation); - unsigned int ifgshade = SampleShade32(posU, posV, texPixels, texWidth, texHeight, fuzzpos); + unsigned int ifgshade = SampleShade32(posU, posV, texPixels, texWidth, texHeight, destX + x, destY + y); posU += stepU; posV += stepV; @@ -711,7 +720,7 @@ private: // Sample fgcolor if (SamplerT::Mode == (int)Samplers::FogBoundary && (mask1 & (1 << 31))) color = dest[x]; unsigned int ifgcolor = Sample32(posU, posV, texPixels, texWidth, texHeight, oneU, oneV, color, translation); - unsigned int ifgshade = SampleShade32(posU, posV, texPixels, texWidth, texHeight, fuzzpos); + unsigned int ifgshade = SampleShade32(posU, posV, texPixels, texWidth, texHeight, destX + x, destY + 4 + y); posU += stepU; posV += stepV; @@ -773,7 +782,11 @@ public: { using namespace TriScreenDrawerModes; - if (args->SimpleShade()) + if (SamplerT::Mode == (int)Samplers::Fuzz) + { + Loop(destOrg, destWidth, destHeight, destPitch, args, thread); + } + else if (args->SimpleShade()) { Loop(destOrg, destWidth, destHeight, destPitch, args, thread); } @@ -869,18 +882,9 @@ private: int count = x1 - x0; - int fuzzpos = (ScreenTriangle::FuzzStart + x0 * 123 + y0) % FUZZTABLE; - uint32_t posV = startV; for (int y = y0; y < y1; y++, posV += stepV) { - int coreBlock = y / 8; - if (coreBlock % thread->num_cores != thread->core) - { - fuzzpos = (fuzzpos + count) % FUZZTABLE; - continue; - } - uint32_t *dest = ((uint32_t*)destOrg) + y * destPitch + x0; uint32_t posU = startU; @@ -896,7 +900,7 @@ private: // Sample fgcolor if (SamplerT::Mode == (int)Samplers::FogBoundary) color = *dest; unsigned int ifgcolor = Sample32(posU, posV, texPixels, texWidth, texHeight, oneU, oneV, color, translation); - unsigned int ifgshade = SampleShade32(posU, posV, texPixels, texWidth, texHeight, fuzzpos); + unsigned int ifgshade = SampleShade32(posU, posV, texPixels, texWidth, texHeight, x0 + i, y); posU += stepU; // Shade and blend diff --git a/src/polyrenderer/poly_renderer.cpp b/src/polyrenderer/poly_renderer.cpp index c3389bba59..a0aa12c32e 100644 --- a/src/polyrenderer/poly_renderer.cpp +++ b/src/polyrenderer/poly_renderer.cpp @@ -119,6 +119,8 @@ void PolyRenderer::RenderActorView(AActor *actor, bool dontmaplines) P_FindParticleSubsectors(); PO_LinkToSubsectors(); + swrenderer::R_UpdateFuzzPosFrameStart(); + if (APART(R_OldBlend)) NormalLight.Maps = realcolormaps.Maps; else NormalLight.Maps = realcolormaps.Maps + NUMCOLORMAPS * 256 * R_OldBlend; diff --git a/src/swrenderer/drawers/r_draw.cpp b/src/swrenderer/drawers/r_draw.cpp index 793cf2ae47..bc7eb731dc 100644 --- a/src/swrenderer/drawers/r_draw.cpp +++ b/src/swrenderer/drawers/r_draw.cpp @@ -193,7 +193,7 @@ namespace swrenderer void R_UpdateFuzzPosFrameStart() { - if (r_fuzzscale) + if (r_fuzzscale || r_polyrenderer) { static int next_random = 0; @@ -207,7 +207,7 @@ namespace swrenderer void R_UpdateFuzzPos(const SpriteDrawerArgs &args) { - if (!r_fuzzscale) + if (!r_fuzzscale && !r_polyrenderer) { int yl = MAX(args.FuzzY1(), 1); int yh = MIN(args.FuzzY2(), fuzzviewheight); From f04fca75f710a2e82027911f17f6df22a424d9d8 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Wed, 22 Nov 2017 18:46:45 +0100 Subject: [PATCH 7/9] - Add scaled fuzz to softpoly sse2 drawer --- src/polyrenderer/drawers/poly_drawer32_sse2.h | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/polyrenderer/drawers/poly_drawer32_sse2.h b/src/polyrenderer/drawers/poly_drawer32_sse2.h index 8c245eec97..01c6144343 100644 --- a/src/polyrenderer/drawers/poly_drawer32_sse2.h +++ b/src/polyrenderer/drawers/poly_drawer32_sse2.h @@ -107,7 +107,7 @@ namespace TriScreenDrawerModes } template - FORCEINLINE unsigned int VECTORCALL SampleShade32(int32_t u, int32_t v, const uint32_t *texPixels, int texWidth, int texHeight, int &fuzzpos) + FORCEINLINE unsigned int VECTORCALL SampleShade32(int32_t u, int32_t v, const uint32_t *texPixels, int texWidth, int texHeight, int x, int y) { if (SamplerT::Mode == (int)Samplers::Shaded) { @@ -128,12 +128,23 @@ namespace TriScreenDrawerModes } else if (SamplerT::Mode == (int)Samplers::Fuzz) { + using namespace swrenderer; + uint32_t texelX = ((((uint32_t)u << 8) >> 16) * texWidth) >> 16; uint32_t texelY = ((((uint32_t)v << 8) >> 16) * texHeight) >> 16; unsigned int sampleshadeout = APART(texPixels[texelX * texHeight + texelY]); sampleshadeout += sampleshadeout >> 7; // 255 -> 256 - sampleshadeout = (sampleshadeout * fuzzcolormap[fuzzpos++]) >> 5; - if (fuzzpos >= FUZZTABLE) fuzzpos = 0; + + fixed_t fuzzscale = (200 << FRACBITS) / viewheight; + + int scaled_x = (x * fuzzscale) >> FRACBITS; + int fuzz_x = fuzz_random_x_offset[scaled_x % FUZZ_RANDOM_X_SIZE] + fuzzpos; + + fixed_t fuzzcount = FUZZTABLE << FRACBITS; + fixed_t fuzz = ((fuzz_x << FRACBITS) + y * fuzzscale) % fuzzcount; + unsigned int alpha = fuzzoffset[fuzz >> FRACBITS]; + + sampleshadeout = (sampleshadeout * alpha) >> 5; return sampleshadeout; } else @@ -392,8 +403,6 @@ private: uint32_t srcalpha = args->uniforms->SrcAlpha(); uint32_t destalpha = args->uniforms->DestAlpha(); - int fuzzpos = (ScreenTriangle::FuzzStart + destX * 123 + destY) % FUZZTABLE; - auto lights = args->uniforms->Lights(); auto num_lights = args->uniforms->NumLights(); __m128 worldnormal = _mm_setr_ps(args->uniforms->Normal().X, args->uniforms->Normal().Y, args->uniforms->Normal().Z, 0.0f); @@ -518,13 +527,13 @@ private: unsigned int ifgcolor[2], ifgshade[2]; if (SamplerT::Mode == (int)Samplers::FogBoundary) color = dest[ix * 2]; ifgcolor[0] = Sample32(posU, posV, texPixels, texWidth, texHeight, oneU, oneV, color, translation); - ifgshade[0] = SampleShade32(posU, posV, texPixels, texWidth, texHeight, fuzzpos); + ifgshade[0] = SampleShade32(posU, posV, texPixels, texWidth, texHeight, destX + ix * 2, destY + y); posU += stepU; posV += stepV; if (SamplerT::Mode == (int)Samplers::FogBoundary) color = dest[ix * 2 + 1]; ifgcolor[1] = Sample32(posU, posV, texPixels, texWidth, texHeight, oneU, oneV, color, translation); - ifgshade[1] = SampleShade32(posU, posV, texPixels, texWidth, texHeight, fuzzpos); + ifgshade[1] = SampleShade32(posU, posV, texPixels, texWidth, texHeight, destX + ix * 2 + 1, destY + y); posU += stepU; posV += stepV; @@ -626,13 +635,13 @@ private: unsigned int ifgcolor[2], ifgshade[2]; if (SamplerT::Mode == (int)Samplers::FogBoundary) color = dest[x * 2]; ifgcolor[0] = Sample32(posU, posV, texPixels, texWidth, texHeight, oneU, oneV, color, translation); - ifgshade[0] = SampleShade32(posU, posV, texPixels, texWidth, texHeight, fuzzpos); + ifgshade[0] = SampleShade32(posU, posV, texPixels, texWidth, texHeight, destX + x * 2, destY + y); posU += stepU; posV += stepV; if (SamplerT::Mode == (int)Samplers::FogBoundary) color = dest[x * 2 + 1]; ifgcolor[1] = Sample32(posU, posV, texPixels, texWidth, texHeight, oneU, oneV, color, translation); - ifgshade[1] = SampleShade32(posU, posV, texPixels, texWidth, texHeight, fuzzpos); + ifgshade[1] = SampleShade32(posU, posV, texPixels, texWidth, texHeight, destX + x * 2 + 1, destY + y); posU += stepU; posV += stepV; @@ -736,13 +745,13 @@ private: unsigned int ifgcolor[2], ifgshade[2]; if (SamplerT::Mode == (int)Samplers::FogBoundary && (mask1 & (1 << 31))) color = dest[x * 2]; ifgcolor[0] = Sample32(posU, posV, texPixels, texWidth, texHeight, oneU, oneV, color, translation); - ifgshade[0] = SampleShade32(posU, posV, texPixels, texWidth, texHeight, fuzzpos); + ifgshade[0] = SampleShade32(posU, posV, texPixels, texWidth, texHeight, destX + x * 2, destY + 4 + y); posU += stepU; posV += stepV; if (SamplerT::Mode == (int)Samplers::FogBoundary && (mask1 & (1 << 30))) color = dest[x * 2 + 1]; ifgcolor[1] = Sample32(posU, posV, texPixels, texWidth, texHeight, oneU, oneV, color, translation); - ifgshade[1] = SampleShade32(posU, posV, texPixels, texWidth, texHeight, fuzzpos); + ifgshade[1] = SampleShade32(posU, posV, texPixels, texWidth, texHeight, destX + x * 2 + 1, destY + 4 + y); posU += stepU; posV += stepV; @@ -889,18 +898,9 @@ private: int count = x1 - x0; int sseCount = count / 2; - int fuzzpos = (ScreenTriangle::FuzzStart + x0 * 123 + y0) % FUZZTABLE; - uint32_t posV = startV; for (int y = y0; y < y1; y++, posV += stepV) { - int coreBlock = y / 8; - if (coreBlock % thread->num_cores != thread->core) - { - fuzzpos = (fuzzpos + count) % FUZZTABLE; - continue; - } - uint32_t *dest = ((uint32_t*)destOrg) + y * destPitch + x0; uint32_t posU = startU; @@ -917,12 +917,12 @@ private: unsigned int ifgcolor[2], ifgshade[2]; if (SamplerT::Mode == (int)Samplers::FogBoundary) color = dest[0]; ifgcolor[0] = Sample32(posU, posV, texPixels, texWidth, texHeight, oneU, oneV, color, translation); - ifgshade[0] = SampleShade32(posU, posV, texPixels, texWidth, texHeight, fuzzpos); + ifgshade[0] = SampleShade32(posU, posV, texPixels, texWidth, texHeight, x0 + i * 2, y); posU += stepU; if (SamplerT::Mode == (int)Samplers::FogBoundary) color = dest[1]; ifgcolor[1] = Sample32(posU, posV, texPixels, texWidth, texHeight, oneU, oneV, color, translation); - ifgshade[1] = SampleShade32(posU, posV, texPixels, texWidth, texHeight, fuzzpos); + ifgshade[1] = SampleShade32(posU, posV, texPixels, texWidth, texHeight, x0 + i * 2 + 1, y); posU += stepU; // Shade and blend @@ -948,7 +948,7 @@ private: unsigned int ifgcolor[2], ifgshade[2]; if (SamplerT::Mode == (int)Samplers::FogBoundary) color = *dest; ifgcolor[0] = Sample32(posU, posV, texPixels, texWidth, texHeight, oneU, oneV, color, translation); - ifgshade[0] = SampleShade32(posU, posV, texPixels, texWidth, texHeight, fuzzpos); + ifgshade[0] = SampleShade32(posU, posV, texPixels, texWidth, texHeight, x0 + sseCount * 2, y); ifgcolor[1] = 0; ifgshade[1] = 0; posU += stepU; From 9052ee6bc80c4ab647d5ac8c1e1f2886872f848f Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Wed, 22 Nov 2017 18:54:49 +0100 Subject: [PATCH 8/9] - Added scaled fuzz to softpoly pal drawer --- src/polyrenderer/drawers/poly_drawer8.h | 36 ++++++++++++------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/polyrenderer/drawers/poly_drawer8.h b/src/polyrenderer/drawers/poly_drawer8.h index f78d2a31cc..d5ec5bade2 100644 --- a/src/polyrenderer/drawers/poly_drawer8.h +++ b/src/polyrenderer/drawers/poly_drawer8.h @@ -79,7 +79,7 @@ namespace TriScreenDrawerModes } template - FORCEINLINE unsigned int SampleShade8(int32_t u, int32_t v, const uint8_t *texPixels, int texWidth, int texHeight, int &fuzzpos) + FORCEINLINE unsigned int SampleShade8(int32_t u, int32_t v, const uint8_t *texPixels, int texWidth, int texHeight, int x, int y) { if (SamplerT::Mode == (int)Samplers::Shaded) { @@ -97,11 +97,22 @@ namespace TriScreenDrawerModes } else if (SamplerT::Mode == (int)Samplers::Fuzz) { + using namespace swrenderer; + uint32_t texelX = ((((uint32_t)u << 8) >> 16) * texWidth) >> 16; uint32_t texelY = ((((uint32_t)v << 8) >> 16) * texHeight) >> 16; unsigned int sampleshadeout = (texPixels[texelX * texHeight + texelY] != 0) ? 256 : 0; - sampleshadeout = (sampleshadeout * fuzzcolormap[fuzzpos++]) >> 5; - if (fuzzpos >= FUZZTABLE) fuzzpos = 0; + + fixed_t fuzzscale = (200 << FRACBITS) / viewheight; + + int scaled_x = (x * fuzzscale) >> FRACBITS; + int fuzz_x = fuzz_random_x_offset[scaled_x % FUZZ_RANDOM_X_SIZE] + fuzzpos; + + fixed_t fuzzcount = FUZZTABLE << FRACBITS; + fixed_t fuzz = ((fuzz_x << FRACBITS) + y * fuzzscale) % fuzzcount; + unsigned int alpha = fuzzoffset[fuzz >> FRACBITS]; + + sampleshadeout = (sampleshadeout * alpha) >> 5; return sampleshadeout; } else @@ -228,8 +239,6 @@ public: uint32_t srcalpha = args->uniforms->SrcAlpha(); uint32_t destalpha = args->uniforms->DestAlpha(); - int fuzzpos = (ScreenTriangle::FuzzStart + destX * 123 + destY) % FUZZTABLE; - // Calculate gradients const ShadedTriVertex &v1 = *args->v1; ScreenTriangleStepVariables gradientX = args->gradientX; @@ -292,7 +301,7 @@ public: uint8_t bgcolor = dest[ix]; if (SamplerT::Mode == (int)Samplers::FogBoundary) color = bgcolor; uint8_t fgcolor = Sample8(posU, posV, texPixels, texWidth, texHeight, color, translation); - uint32_t fgshade = SampleShade8(posU, posV, texPixels, texWidth, texHeight, fuzzpos); + uint32_t fgshade = SampleShade8(posU, posV, texPixels, texWidth, texHeight, destX + ix, destY + y); if (SamplerT::Mode == (int)Samplers::Fuzz) lightshade = 256; dest[ix] = ShadeAndBlend8(fgcolor, bgcolor, fgshade, lightshade, colormaps, srcalpha, destalpha); posU += stepU; @@ -342,7 +351,7 @@ public: uint8_t bgcolor = dest[x]; if (SamplerT::Mode == (int)Samplers::FogBoundary) color = bgcolor; uint8_t fgcolor = Sample8(posU, posV, texPixels, texWidth, texHeight, color, translation); - uint32_t fgshade = SampleShade8(posU, posV, texPixels, texWidth, texHeight, fuzzpos); + uint32_t fgshade = SampleShade8(posU, posV, texPixels, texWidth, texHeight, destX + x, destY + y); if (SamplerT::Mode == (int)Samplers::Fuzz) lightshade = 256; dest[x] = ShadeAndBlend8(fgcolor, bgcolor, fgshade, lightshade, colormaps, srcalpha, destalpha); } @@ -394,7 +403,7 @@ public: uint8_t bgcolor = dest[x]; if (SamplerT::Mode == (int)Samplers::FogBoundary) color = bgcolor; uint8_t fgcolor = Sample8(posU, posV, texPixels, texWidth, texHeight, color, translation); - uint32_t fgshade = SampleShade8(posU, posV, texPixels, texWidth, texHeight, fuzzpos); + uint32_t fgshade = SampleShade8(posU, posV, texPixels, texWidth, texHeight, destX + x, destY + 4 + y); if (SamplerT::Mode == (int)Samplers::Fuzz) lightshade = 256; dest[x] = ShadeAndBlend8(fgcolor, bgcolor, fgshade, lightshade, colormaps, srcalpha, destalpha); } @@ -458,18 +467,9 @@ public: int count = x1 - x0; - int fuzzpos = (ScreenTriangle::FuzzStart + x0 * 123 + y0) % FUZZTABLE; - uint32_t posV = startV; for (int y = y0; y < y1; y++, posV += stepV) { - int coreBlock = y / 8; - if (coreBlock % thread->num_cores != thread->core) - { - fuzzpos = (fuzzpos + count) % FUZZTABLE; - continue; - } - uint8_t *dest = ((uint8_t*)destOrg) + y * destPitch + x0; uint32_t posU = startU; @@ -478,7 +478,7 @@ public: uint8_t bgcolor = *dest; if (SamplerT::Mode == (int)Samplers::FogBoundary) color = bgcolor; uint8_t fgcolor = Sample8(posU, posV, texPixels, texWidth, texHeight, color, translation); - uint32_t fgshade = SampleShade8(posU, posV, texPixels, texWidth, texHeight, fuzzpos); + uint32_t fgshade = SampleShade8(posU, posV, texPixels, texWidth, texHeight, x0 + i, y); *dest = ShadeAndBlend8(fgcolor, bgcolor, fgshade, lightshade, colormaps, srcalpha, destalpha); posU += stepU; From e7e9d1a94206dd8ee0edcebdc6bebffc46e2301f Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Wed, 22 Nov 2017 19:02:25 +0100 Subject: [PATCH 9/9] - Fixed bug introduced by removing a little bit too much from the rect drawers --- src/polyrenderer/drawers/poly_drawer32.h | 6 ++++++ src/polyrenderer/drawers/poly_drawer32_sse2.h | 6 ++++++ src/polyrenderer/drawers/poly_drawer8.h | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/src/polyrenderer/drawers/poly_drawer32.h b/src/polyrenderer/drawers/poly_drawer32.h index f3d05ae749..1acb3de1b6 100644 --- a/src/polyrenderer/drawers/poly_drawer32.h +++ b/src/polyrenderer/drawers/poly_drawer32.h @@ -885,6 +885,12 @@ private: uint32_t posV = startV; for (int y = y0; y < y1; y++, posV += stepV) { + int coreBlock = y / 8; + if (coreBlock % thread->num_cores != thread->core) + { + continue; + } + uint32_t *dest = ((uint32_t*)destOrg) + y * destPitch + x0; uint32_t posU = startU; diff --git a/src/polyrenderer/drawers/poly_drawer32_sse2.h b/src/polyrenderer/drawers/poly_drawer32_sse2.h index 01c6144343..3826d063d3 100644 --- a/src/polyrenderer/drawers/poly_drawer32_sse2.h +++ b/src/polyrenderer/drawers/poly_drawer32_sse2.h @@ -901,6 +901,12 @@ private: uint32_t posV = startV; for (int y = y0; y < y1; y++, posV += stepV) { + int coreBlock = y / 8; + if (coreBlock % thread->num_cores != thread->core) + { + continue; + } + uint32_t *dest = ((uint32_t*)destOrg) + y * destPitch + x0; uint32_t posU = startU; diff --git a/src/polyrenderer/drawers/poly_drawer8.h b/src/polyrenderer/drawers/poly_drawer8.h index d5ec5bade2..fb71691866 100644 --- a/src/polyrenderer/drawers/poly_drawer8.h +++ b/src/polyrenderer/drawers/poly_drawer8.h @@ -470,6 +470,12 @@ public: uint32_t posV = startV; for (int y = y0; y < y1; y++, posV += stepV) { + int coreBlock = y / 8; + if (coreBlock % thread->num_cores != thread->core) + { + continue; + } + uint8_t *dest = ((uint8_t*)destOrg) + y * destPitch + x0; uint32_t posU = startU;