diff --git a/src/deh_tables.c b/src/deh_tables.c index da35393a3..8a4f31808 100644 --- a/src/deh_tables.c +++ b/src/deh_tables.c @@ -6467,6 +6467,15 @@ struct int_const_s const INT_CONST[] = { {"tr_trans90",tr_trans90}, {"NUMTRANSMAPS",NUMTRANSMAPS}, + // Alpha styles (blend modes) + //{"AST_COPY",AST_COPY}, -- not useful in lua + //{"AST_TRANSLUCENT",AST_TRANSLUCENT}, -- ditto + {"AST_ADD",AST_ADD}, + {"AST_SUBTRACT",AST_SUBTRACT}, + {"AST_REVERSESUBTRACT",AST_REVERSESUBTRACT}, + {"AST_MODULATE",AST_MODULATE}, + {"AST_OVERLAY",AST_OVERLAY}, + // Render flags {"RF_HORIZONTALFLIP",RF_HORIZONTALFLIP}, {"RF_VERTICALFLIP",RF_VERTICALFLIP}, diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index eaabb0ed4..6a9b1a853 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -266,16 +266,7 @@ void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t p FSurfaceInfo Surf; Surf.PolyColor.s.red = Surf.PolyColor.s.green = Surf.PolyColor.s.blue = 0xff; - if (!alphalevel) - flags &= ~PF_Translucent; - if (blendmode == AST_ADD) - flags |= PF_Additive; - else if (blendmode == AST_SUBTRACT) - flags |= PF_Subtractive; - else if (blendmode == AST_REVERSESUBTRACT) - flags |= PF_ReverseSubtract; - else if (blendmode == AST_MODULATE) - flags |= PF_Multiplicative; + flags |= HWR_GetBlendModeFlag(blendmode); if (alphalevel == 10) Surf.PolyColor.s.alpha = softwaretranstogl_lo[st_translucency]; @@ -439,16 +430,7 @@ void HWR_DrawCroppedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, FSurfaceInfo Surf; Surf.PolyColor.s.red = Surf.PolyColor.s.green = Surf.PolyColor.s.blue = 0xff; - if (!alphalevel) - flags &= ~PF_Translucent; - if (blendmode == AST_ADD) - flags |= PF_Additive; - else if (blendmode == AST_SUBTRACT) - flags |= PF_Subtractive; - else if (blendmode == AST_REVERSESUBTRACT) - flags |= PF_ReverseSubtract; - else if (blendmode == AST_MODULATE) - flags |= PF_Multiplicative; + flags |= HWR_GetBlendModeFlag(blendmode); if (alphalevel == 10) Surf.PolyColor.s.alpha = softwaretranstogl_lo[st_translucency]; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index f1afa8f1c..609f5c8e9 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -1752,15 +1752,11 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (rover->flags & FF_TRANSLUCENT) { - if (rover->alpha < 256) + if (rover->alpha < 256 || rover->blend) { - blendmode = PF_Translucent; - Surf.PolyColor.s.alpha = (UINT8)(rover->alpha-1 > 255 ? 255 : rover->alpha-1); + blendmode = HWR_GetBlendModeFlag(rover->blend); + Surf.PolyColor.s.alpha = (UINT8)(rover->alpha-1); } - else if (rover->alpha == FFLOOR_ALPHA_SPECIAL_ADDITIVE) - blendmode = PF_Additive; - else if (rover->alpha == FFLOOR_ALPHA_SPECIAL_SUBTRACTIVE) - blendmode = PF_Subtractive; } if (gl_frontsector->numlights) @@ -1871,15 +1867,11 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (rover->flags & FF_TRANSLUCENT) { - if (rover->alpha < 256) + if (rover->alpha < 256 || rover->blend) { - blendmode = PF_Translucent; - Surf.PolyColor.s.alpha = (UINT8)(rover->alpha-1 > 255 ? 255 : rover->alpha-1); + blendmode = HWR_GetBlendModeFlag(rover->blend); + Surf.PolyColor.s.alpha = (UINT8)(rover->alpha-1); } - else if (rover->alpha == FFLOOR_ALPHA_SPECIAL_ADDITIVE) - blendmode = PF_Additive; - else if (rover->alpha == FFLOOR_ALPHA_SPECIAL_SUBTRACTIVE) - blendmode = PF_Subtractive; } if (gl_backsector->numlights) @@ -3152,14 +3144,9 @@ static void HWR_Subsector(size_t num) true, rover->master->frontsector->extra_colormap); } 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 + && (rover->alpha < 256 || rover->blend)) // SoM: Flags are more efficient { - FBITFIELD blendmode = PF_Translucent | HWR_RippleBlend(gl_frontsector, rover, false); - if (rover->alpha == FFLOOR_ALPHA_SPECIAL_ADDITIVE) - blendmode = PF_Additive; - else if (rover->alpha == FFLOOR_ALPHA_SPECIAL_SUBTRACTIVE) - blendmode = PF_Subtractive; + FBITFIELD blendmode = HWR_GetBlendModeFlag(rover->blend) | HWR_RippleBlend(gl_frontsector, rover, false); light = R_GetPlaneLight(gl_frontsector, centerHeight, dup_viewz < cullHeight ? true : false); @@ -3168,7 +3155,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, blendmode, + rover->alpha-1, rover->master->frontsector, blendmode, false, *gl_frontsector->lightlist[light].extra_colormap); } else @@ -3205,14 +3192,9 @@ static void HWR_Subsector(size_t num) true, rover->master->frontsector->extra_colormap); } 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 + && (rover->alpha < 256 || rover->blend)) // SoM: Flags are more efficient { - FBITFIELD blendmode = PF_Translucent | HWR_RippleBlend(gl_frontsector, rover, true); - if (rover->alpha == FFLOOR_ALPHA_SPECIAL_ADDITIVE) - blendmode = PF_Additive; - else if (rover->alpha == FFLOOR_ALPHA_SPECIAL_SUBTRACTIVE) - blendmode = PF_Subtractive; + FBITFIELD blendmode = HWR_GetBlendModeFlag(rover->blend) | HWR_RippleBlend(gl_frontsector, rover, false); light = R_GetPlaneLight(gl_frontsector, centerHeight, dup_viewz < cullHeight ? true : false); @@ -3221,7 +3203,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, blendmode, + rover->alpha-1, rover->master->frontsector, blendmode, false, *gl_frontsector->lightlist[light].extra_colormap); } else diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 9fefa76c1..60821080c 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -196,6 +196,7 @@ enum ffloor_e { ffloor_next, ffloor_prev, ffloor_alpha, + ffloor_blend, }; static const char *const ffloor_opt[] = { @@ -214,6 +215,7 @@ static const char *const ffloor_opt[] = { "next", "prev", "alpha", + "blend", NULL}; #ifdef HAVE_LUA_SEGS @@ -1796,6 +1798,9 @@ static int ffloor_get(lua_State *L) case ffloor_alpha: lua_pushinteger(L, ffloor->alpha); return 1; + case ffloor_blend: + lua_pushinteger(L, ffloor->blend); + return 1; } return 0; } @@ -1874,6 +1879,9 @@ static int ffloor_set(lua_State *L) case ffloor_alpha: ffloor->alpha = (INT32)luaL_checkinteger(L, 3); break; + case ffloor_blend: + ffloor->blend = (INT32)luaL_checkinteger(L, 3); + break; } return 0; } diff --git a/src/p_setup.c b/src/p_setup.c index 8ee160c11..6f50e4f04 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1337,8 +1337,11 @@ static void P_LoadSidedefs(UINT8 *data) if (msd->toptexture[0] == '#') { char *col = msd->toptexture; - sd->toptexture = sd->bottomtexture = - ((col[1]-'0')*100 + (col[2]-'0')*10 + col[3]-'0') + 1; + sd->toptexture = + ((col[1]-'0')*100 + (col[2]-'0')*10 + col[3]-'0')+1; + if (col[4]) // extra num for blendmode + sd->toptexture += (col[4]-'0')*1000; + sd->bottomtexture = sd->toptexture; sd->midtexture = R_TextureNumForName(msd->midtexture); } else diff --git a/src/p_spec.c b/src/p_spec.c index 272846bf0..063d7e23e 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -5380,7 +5380,26 @@ static ffloor_t *P_AddFakeFloor(sector_t *sec, sector_t *sec2, line_t *master, f if (flags & FF_TRANSLUCENT) { if (sides[master->sidenum[0]].toptexture > 0) - fflr->alpha = sides[master->sidenum[0]].toptexture; // for future reference, "#0" is 1, and "#255" is 256. Be warned + { + // for future reference, "#0" is 1, and "#255" is 256. Be warned + fflr->alpha = sides[master->sidenum[0]].toptexture; + + if (fflr->alpha == 901) // additive special + { + fflr->blend = AST_ADD; + fflr->alpha = 0xff; + } + else if (fflr->alpha == 902) // subtractive special + { + fflr->blend = AST_SUBTRACT; + fflr->alpha = 0xff; + } + else if (fflr->alpha >= 1001) // fourth digit + { + fflr->blend = (fflr->alpha/1000)+1; // becomes an AST + fflr->alpha %= 1000; + } + } else fflr->alpha = 0x80; } diff --git a/src/r_defs.h b/src/r_defs.h index 6d2b3aea7..41b0cdaab 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -154,9 +154,6 @@ 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; @@ -187,6 +184,7 @@ typedef struct ffloor_s INT32 lastlight; INT32 alpha; + UINT8 blend; tic_t norender; // for culling // these are saved for netgames, so do not let Lua touch these! diff --git a/src/r_plane.c b/src/r_plane.c index 13bb5c226..928ecbe80 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -861,32 +861,14 @@ void R_DrawSinglePlane(visplane_t *pl) spanfunctype = (pl->ffloor->master->flags & ML_EFFECT6) ? SPANDRAWFUNC_TRANSSPLAT : SPANDRAWFUNC_TRANS; // Hacked up support for alpha value in software mode Tails 09-24-2002 - if (pl->ffloor->alpha < 12) - return; // Don't even draw it - else if (pl->ffloor->alpha < 38) - ds_transmap = R_GetTranslucencyTable(tr_trans90); - else if (pl->ffloor->alpha < 64) - ds_transmap = R_GetTranslucencyTable(tr_trans80); - else if (pl->ffloor->alpha < 89) - ds_transmap = R_GetTranslucencyTable(tr_trans70); - else if (pl->ffloor->alpha < 115) - ds_transmap = R_GetTranslucencyTable(tr_trans60); - else if (pl->ffloor->alpha < 140) - ds_transmap = R_GetTranslucencyTable(tr_trans50); - else if (pl->ffloor->alpha < 166) - ds_transmap = R_GetTranslucencyTable(tr_trans40); - else if (pl->ffloor->alpha < 192) - ds_transmap = R_GetTranslucencyTable(tr_trans30); - else if (pl->ffloor->alpha < 217) - ds_transmap = R_GetTranslucencyTable(tr_trans20); - else if (pl->ffloor->alpha < 243) - ds_transmap = R_GetTranslucencyTable(tr_trans10); - else if (pl->ffloor->alpha == FFLOOR_ALPHA_SPECIAL_ADDITIVE) - ds_transmap = R_GetTranslucencyTable(tr_trans50); // TODOOOOOOOOOOOOO - else if (pl->ffloor->alpha == FFLOOR_ALPHA_SPECIAL_SUBTRACTIVE) - ds_transmap = R_GetTranslucencyTable(tr_trans50); // TODOOOOOOOOOOOOO - else // Opaque, but allow transparent flat pixels - spanfunctype = SPANDRAWFUNC_SPLAT; + // ...unhacked by toaster 04-01-2021 + { + INT32 trans = (10*((256+12) - pl->ffloor->alpha))/255; + if (trans >= 10) + return; // Don't even draw it + if (!(ds_transmap = R_GetBlendTable(pl->ffloor->blend, trans))) + spanfunctype = SPANDRAWFUNC_SPLAT; // Opaque, but allow transparent flat pixels + } if ((spanfunctype == SPANDRAWFUNC_SPLAT) || (pl->extra_colormap && (pl->extra_colormap->flags & CMF_FOG))) light = (pl->lightlevel >> LIGHTSEGSHIFT); diff --git a/src/r_segs.c b/src/r_segs.c index f78834ce4..7443561c6 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -631,32 +631,14 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) boolean fuzzy = true; // Hacked up support for alpha value in software mode Tails 09-24-2002 - if (pfloor->alpha < 12) - return; // Don't even draw it - else if (pfloor->alpha < 38) - dc_transmap = R_GetTranslucencyTable(tr_trans90); - else if (pfloor->alpha < 64) - dc_transmap = R_GetTranslucencyTable(tr_trans80); - else if (pfloor->alpha < 89) - dc_transmap = R_GetTranslucencyTable(tr_trans70); - else if (pfloor->alpha < 115) - dc_transmap = R_GetTranslucencyTable(tr_trans60); - else if (pfloor->alpha < 140) - dc_transmap = R_GetTranslucencyTable(tr_trans50); - else if (pfloor->alpha < 166) - dc_transmap = R_GetTranslucencyTable(tr_trans40); - else if (pfloor->alpha < 192) - dc_transmap = R_GetTranslucencyTable(tr_trans30); - else if (pfloor->alpha < 217) - dc_transmap = R_GetTranslucencyTable(tr_trans20); - else if (pfloor->alpha < 243) - dc_transmap = R_GetTranslucencyTable(tr_trans10); - else if (pfloor->alpha == FFLOOR_ALPHA_SPECIAL_ADDITIVE) - dc_transmap = R_GetTranslucencyTable(tr_trans50); // TODOOOOOOOOOOOOO - else if (pfloor->alpha == FFLOOR_ALPHA_SPECIAL_SUBTRACTIVE) - dc_transmap = R_GetTranslucencyTable(tr_trans50); // TODOOOOOOOOOOOOO - else - fuzzy = false; // Opaque + // ...unhacked by toaster 04-01-2021 + { + INT32 trans = (10*((256+12) - pfloor->alpha))/255; + if (trans >= 10) + return; // Don't even draw it + if (!(dc_transmap = R_GetBlendTable(pfloor->blend, trans))) + fuzzy = false; // Opaque + } if (fuzzy) colfunc = colfuncs[COLDRAWFUNC_FUZZY];