From d311242a6e226c367c3f0c0e5f2f62a57a709f4d Mon Sep 17 00:00:00 2001 From: Sryder Date: Thu, 22 Oct 2020 23:13:51 +0100 Subject: [PATCH] Support for additive/subtractive translation maps on FOFs and Polyobjects Polyobjects set translucency to 11 for additive, and 12 for subtractive FOFs using the regular translucency settings set the top texture to #900 for additive, and #901 for subtractive --- src/hardware/hw_main.c | 50 +++++++++++++++++++++++++++++++++--------- src/p_polyobj.c | 2 +- src/r_defs.h | 3 +++ src/r_plane.c | 6 ++++- src/r_segs.c | 4 ++++ 5 files changed, 53 insertions(+), 12 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 9d0dc91b0..0e0c83f9f 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -1735,10 +1735,17 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom { FBITFIELD blendmode = PF_Masked; - if (rover->flags & FF_TRANSLUCENT && rover->alpha < 256) + if (rover->flags & FF_TRANSLUCENT) { - blendmode = PF_Translucent; - Surf.PolyColor.s.alpha = (UINT8)rover->alpha-1 > 255 ? 255 : rover->alpha-1; + if (rover->alpha < 256) + { + blendmode = PF_Translucent; + Surf.PolyColor.s.alpha = (UINT8)(rover->alpha-1 > 255 ? 255 : rover->alpha-1); + } + else if (rover->alpha == FFLOOR_ALPHA_SPECIAL_ADDITIVE) + blendmode = PF_Additive; + else if (rover->alpha == FFLOOR_ALPHA_SPECIAL_SUBTRACTIVE) + blendmode = PF_Substractive; } if (gl_frontsector->numlights) @@ -1835,10 +1842,17 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom { FBITFIELD blendmode = PF_Masked; - if (rover->flags & FF_TRANSLUCENT && rover->alpha < 256) + if (rover->flags & FF_TRANSLUCENT) { - blendmode = PF_Translucent; - Surf.PolyColor.s.alpha = (UINT8)rover->alpha-1 > 255 ? 255 : rover->alpha-1; + if (rover->alpha < 256) + { + blendmode = PF_Translucent; + Surf.PolyColor.s.alpha = (UINT8)(rover->alpha-1 > 255 ? 255 : rover->alpha-1); + } + else if (rover->alpha == FFLOOR_ALPHA_SPECIAL_ADDITIVE) + blendmode = PF_Additive; + else if (rover->alpha == FFLOOR_ALPHA_SPECIAL_SUBTRACTIVE) + blendmode = PF_Substractive; } if (gl_backsector->numlights) @@ -3098,8 +3112,16 @@ static void HWR_Subsector(size_t num) alpha, rover->master->frontsector, PF_Fog|PF_NoTexture, true, rover->master->frontsector->extra_colormap); } - else if (rover->flags & FF_TRANSLUCENT && rover->alpha < 256) // SoM: Flags are more efficient + else if (rover->flags & FF_TRANSLUCENT + && (rover->alpha < 256 + || rover->alpha == FFLOOR_ALPHA_SPECIAL_ADDITIVE || rover->alpha == FFLOOR_ALPHA_SPECIAL_SUBTRACTIVE)) // SoM: Flags are more efficient { + FBITFIELD blendmode = PF_Translucent; + if (rover->alpha == FFLOOR_ALPHA_SPECIAL_ADDITIVE) + blendmode = PF_Additive; + else if (rover->alpha == FFLOOR_ALPHA_SPECIAL_SUBTRACTIVE) + blendmode = PF_Substractive; + light = R_GetPlaneLight(gl_frontsector, centerHeight, dup_viewz < cullHeight ? true : false); HWR_AddTransparentFloor(&levelflats[*rover->bottompic], @@ -3107,7 +3129,7 @@ static void HWR_Subsector(size_t num) false, *rover->bottomheight, *gl_frontsector->lightlist[light].lightlevel, - rover->alpha-1 > 255 ? 255 : rover->alpha-1, rover->master->frontsector, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Translucent, + rover->alpha-1 > 255 ? 255 : rover->alpha-1, rover->master->frontsector, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|blendmode, false, *gl_frontsector->lightlist[light].extra_colormap); } else @@ -3143,8 +3165,16 @@ static void HWR_Subsector(size_t num) alpha, rover->master->frontsector, PF_Fog|PF_NoTexture, true, rover->master->frontsector->extra_colormap); } - else if (rover->flags & FF_TRANSLUCENT && rover->alpha < 256) + else if (rover->flags & FF_TRANSLUCENT + && (rover->alpha < 256 + || rover->alpha == FFLOOR_ALPHA_SPECIAL_ADDITIVE || rover->alpha == FFLOOR_ALPHA_SPECIAL_SUBTRACTIVE)) // SoM: Flags are more efficient { + FBITFIELD blendmode = PF_Translucent; + if (rover->alpha == FFLOOR_ALPHA_SPECIAL_ADDITIVE) + blendmode = PF_Additive; + else if (rover->alpha == FFLOOR_ALPHA_SPECIAL_SUBTRACTIVE) + blendmode = PF_Substractive; + light = R_GetPlaneLight(gl_frontsector, centerHeight, dup_viewz < cullHeight ? true : false); HWR_AddTransparentFloor(&levelflats[*rover->toppic], @@ -3152,7 +3182,7 @@ static void HWR_Subsector(size_t num) true, *rover->topheight, *gl_frontsector->lightlist[light].lightlevel, - rover->alpha-1 > 255 ? 255 : rover->alpha-1, rover->master->frontsector, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Translucent, + rover->alpha-1 > 255 ? 255 : rover->alpha-1, rover->master->frontsector, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|blendmode, false, *gl_frontsector->lightlist[light].extra_colormap); } else diff --git a/src/p_polyobj.c b/src/p_polyobj.c index 5ec8fe007..645cf010d 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -2563,7 +2563,7 @@ void T_PolyObjFade(polyfade_t *th) { if (po->translucency >= NUMTRANSMAPS) // HACK: OpenGL renders fully opaque when >= NUMTRANSMAPS - po->translucency = NUMTRANSMAPS-1; + po->translucency = tr_trans90; po->flags |= (po->spawnflags & POF_RENDERALL); diff --git a/src/r_defs.h b/src/r_defs.h index 715067176..8372a5ae5 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -152,6 +152,9 @@ typedef enum FF_GOOWATER = FF_SHATTERBOTTOM, ///< Used with ::FF_SWIMMABLE. Makes thick bouncey goop. } ffloortype_e; +#define FFLOOR_ALPHA_SPECIAL_ADDITIVE (901) +#define FFLOOR_ALPHA_SPECIAL_SUBTRACTIVE (902) + typedef struct ffloor_s { fixed_t *topheight; diff --git a/src/r_plane.c b/src/r_plane.c index 3e6f30235..7439886d7 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -952,7 +952,7 @@ void R_DrawSinglePlane(visplane_t *pl) if (pl->polyobj) { // Hacked up support for alpha value in software mode Tails 09-24-2002 (sidenote: ported to polys 10-15-2014, there was no time travel involved -Red) - if (pl->polyobj->translucency >= 10) + if (pl->polyobj->translucency >= NUMTRANSMAPS) return; // Don't even draw it else if (pl->polyobj->translucency > 0) { @@ -1013,6 +1013,10 @@ void R_DrawSinglePlane(visplane_t *pl) ds_transmap = transtables + ((tr_trans20-1)<ffloor->alpha < 243) ds_transmap = transtables + ((tr_trans10-1)<ffloor->alpha == FFLOOR_ALPHA_SPECIAL_ADDITIVE) + dc_transmap = transtables + ((tr_transadd-1)<ffloor->alpha == FFLOOR_ALPHA_SPECIAL_SUBTRACTIVE) + dc_transmap = transtables + ((tr_transsub-1)<alpha < 243) dc_transmap = transtables + ((tr_trans10-1)<alpha == FFLOOR_ALPHA_SPECIAL_ADDITIVE) + dc_transmap = transtables + ((tr_transadd-1)<alpha == FFLOOR_ALPHA_SPECIAL_SUBTRACTIVE) + dc_transmap = transtables + ((tr_transsub-1)<