From 9052ee6bc80c4ab647d5ac8c1e1f2886872f848f Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Wed, 22 Nov 2017 18:54:49 +0100 Subject: [PATCH] - 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;