From 816f5a991f2e785b686372082ed63c1939b2c700 Mon Sep 17 00:00:00 2001 From: MIDIMan <miditheman2.0@gmail.com> Date: Wed, 5 Mar 2025 12:47:11 -0500 Subject: [PATCH] Make alpha scaling and blending more accurate to FF_TRANSMASK in OpenGL --- src/hardware/hw_main.c | 16 ++++++++++++++-- src/hardware/hw_md2.c | 9 +++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index d84322dfda..7746cc3a9f 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3137,7 +3137,13 @@ static void HWR_SplitSprite(gl_vissprite_t *spr) if (!occlusion) use_linkdraw_hack = true; } - Surf.PolyColor.s.alpha = FixedMul(newalpha, Surf.PolyColor.s.alpha); + if (cv_translucency.value && newalpha < FRACUNIT) + { + // TODO: The ternary operator is a hack to make alpha values roughly match what their FF_TRANSMASK equivalent would be + // See if there's a better way of doing this + Surf.PolyColor.s.alpha = min(FixedMul(newalpha, Surf.PolyColor.s.alpha == 0xFF ? 256 : Surf.PolyColor.s.alpha), 0xFF); + blend = HWR_GetBlendModeFlag(blendmode); + } if (HWR_UseShader()) { @@ -3632,7 +3638,13 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) if (!occlusion) use_linkdraw_hack = true; } - Surf.PolyColor.s.alpha = FixedMul(newalpha, Surf.PolyColor.s.alpha); + if (cv_translucency.value && newalpha < FRACUNIT) + { + // TODO: The ternary operator is a hack to make alpha values roughly match what their FF_TRANSMASK equivalent would be + // See if there's a better way of doing this + Surf.PolyColor.s.alpha = min(FixedMul(newalpha, Surf.PolyColor.s.alpha == 0xFF ? 256 : Surf.PolyColor.s.alpha), 0xFF); + blend = HWR_GetBlendModeFlag(blendmode); + } if (spr->renderflags & RF_SHADOWEFFECTS) { diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index ce2c2c3463..fa337bd211 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1388,8 +1388,13 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) Surf.PolyColor.s.alpha = (spr->mobj->flags2 & MF2_SHADOW) ? 0x40 : 0xff; Surf.PolyFlags = HWR_GetBlendModeFlag(blendmode); } - - Surf.PolyColor.s.alpha = FixedMul(newalpha, Surf.PolyColor.s.alpha); + + if (newalpha < FRACUNIT) + { + // TODO: The ternary operator is a hack to make alpha values roughly match what their FF_TRANSMASK equivalent would be + // See if there's a better way of doing this + Surf.PolyColor.s.alpha = min(FixedMul(newalpha, Surf.PolyColor.s.alpha == 0xFF ? 256 : Surf.PolyColor.s.alpha), 0xFF); + } // don't forget to enable the depth test because we can't do this // like before: model polygons are not sorted -- GitLab