diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index f87f187a..145a0150 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -987,40 +987,26 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, // Average all of the translation's colors { - UINT16 r, g, b; - UINT8 div = 0; + const UINT8 div = 6; + const UINT8 start = 4; + UINT32 r, g, b; - blendcolor = V_GetColor(colortranslations[color][0]); - r = (UINT16)blendcolor.s.red; - g = (UINT16)blendcolor.s.green; - b = (UINT16)blendcolor.s.blue; + blendcolor = V_GetColor(colortranslations[color][start]); + r = (UINT32)(blendcolor.s.red*blendcolor.s.red); + g = (UINT32)(blendcolor.s.green*blendcolor.s.green); + b = (UINT32)(blendcolor.s.blue*blendcolor.s.blue); - for (i = 1; i < 16; i++) + for (i = 1; i < div; i++) { - RGBA_t nextcolor = V_GetColor(colortranslations[color][i]); - UINT8 mul = 1; - // Weight these shades more. Indices 1-9 weren't randomly picked, they are commonly used on sprites and are generally what the colors "look" like - if (i >= 1 && i <= 9) - mul++; - // The mid & dark tons on the minimap icons get weighted even harder - if (i == 4 || i == 6) - mul += 2; - // And the shade between them, why not - if (i == 5) - mul++; - r += (UINT16)(nextcolor.s.red)*mul; - g += (UINT16)(nextcolor.s.green)*mul; - b += (UINT16)(nextcolor.s.blue)*mul; - div += mul; + RGBA_t nextcolor = V_GetColor(colortranslations[color][start+i]); + r += (UINT32)(nextcolor.s.red*nextcolor.s.red); + g += (UINT32)(nextcolor.s.green*nextcolor.s.green); + b += (UINT32)(nextcolor.s.blue*nextcolor.s.blue); } - // This shouldn't happen. - if (div < 1) - div = 1; - - blendcolor.s.red = (UINT8)(r/div); - blendcolor.s.green = (UINT8)(g/div); - blendcolor.s.blue = (UINT8)(b/div); + blendcolor.s.red = (UINT8)(FixedSqrt((r/div)<>FRACBITS); + blendcolor.s.green = (UINT8)(FixedSqrt((g/div)<>FRACBITS); + blendcolor.s.blue = (UINT8)(FixedSqrt((b/div)<>FRACBITS); } // rainbow support, could theoretically support boss ones too