From 0b6e7c421f792ececba1345aa6b99596dfe40f68 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 5 Dec 2021 13:33:51 -0800 Subject: [PATCH] softgpu: Make decal tex func more accurate. Tested for all values of A * B + 0 * (255 - B), as well as A * 127 + B * (255 - 127), and matches accurately. Spot checked other values, but not exhaustively. --- GPU/Common/ShaderId.cpp | 2 +- GPU/Software/Rasterizer.cpp | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/GPU/Common/ShaderId.cpp b/GPU/Common/ShaderId.cpp index 3bd5bd71f6..abc40143f9 100644 --- a/GPU/Common/ShaderId.cpp +++ b/GPU/Common/ShaderId.cpp @@ -243,7 +243,7 @@ void ComputeFragmentShaderID(FShaderID *id_out, const Draw::Bugs &bugs) { bool enableFog = gstate.isFogEnabled() && !isModeThrough; bool enableAlphaTest = gstate.isAlphaTestEnabled() && !IsAlphaTestTriviallyTrue(); bool enableColorTest = gstate.isColorTestEnabled() && !IsColorTestTriviallyTrue(); - bool enableColorDoubling = gstate.isColorDoublingEnabled() && gstate.isTextureMapEnabled() && gstate.getTextureFunction() == GE_TEXFUNC_MODULATE; + bool enableColorDoubling = gstate.isColorDoublingEnabled() && gstate.isTextureMapEnabled(); bool doTextureProjection = (gstate.getUVGenMode() == GE_TEXMAP_TEXTURE_MATRIX && MatrixNeedsProjection(gstate.tgenMatrix)); bool doTextureAlpha = gstate.isTextureAlphaUsed(); bool doFlatShading = gstate.getShadeMode() == GE_SHADE_FLAT; diff --git a/GPU/Software/Rasterizer.cpp b/GPU/Software/Rasterizer.cpp index 581fb8d7d0..7073fa36dd 100644 --- a/GPU/Software/Rasterizer.cpp +++ b/GPU/Software/Rasterizer.cpp @@ -283,7 +283,6 @@ Vec4IntResult SOFTRAST_CALL GetTextureFunctionOutput(Vec4IntArg prim_color_in, V const __m128i pboost = _mm_add_epi16(p, _mm_set1_epi16(1 << 4)); __m128i t = _mm_slli_epi16(_mm_packs_epi32(texcolor.ivec, texcolor.ivec), 4); if (gstate.isColorDoublingEnabled()) { - // We double right here, only for modulate. Other tex funcs do not color double. const __m128i amask = _mm_set_epi16(-1, 0, 0, 0, -1, 0, 0, 0); const __m128i a = _mm_and_si128(t, amask); const __m128i rgb = _mm_andnot_si128(amask, t); @@ -310,9 +309,18 @@ Vec4IntResult SOFTRAST_CALL GetTextureFunctionOutput(Vec4IntArg prim_color_in, V case GE_TEXFUNC_DECAL: { - int t = (rgba) ? texcolor.a() : 255; - int invt = (rgba) ? 255 - t : 0; - out_rgb = (prim_color.rgb() * invt + texcolor.rgb() * t) / 255; + if (rgba) { + int t = (rgba) ? texcolor.a() : 255; + int invt = (rgba) ? 255 - t : 0; + Vec3 one = Vec3::AssignToAll(1); + out_rgb = ((prim_color.rgb() + one) * invt + (texcolor.rgb() + one) * t); + if (gstate.isColorDoublingEnabled()) + out_rgb /= 128; + else + out_rgb /= 256; + } else { + out_rgb = texcolor.rgb(); + } out_a = prim_color.a(); break; }