* Add a blend field to FOFs.

* Set via a fourth digit in the upper midtexture for transparent FOFs
        * For example - #2551 is additive solid, #1282 is subtractive half...
    * The original method of setting the upper midtexture to #900 or 901 still works, since I'm not out to break existing maps.
* Software: Remove the horrible `else if` ladder for FOF translucency. Algorithms, baby!
* OpenGL: Move to using `HWR_GetBlendModeFlag` in more places, for more long-term extensible support for multiple blendmodes.
This commit is contained in:
toaster 2021-04-01 23:45:21 +01:00
parent e27506c660
commit ebe38ff518
9 changed files with 73 additions and 108 deletions

View file

@ -6467,6 +6467,15 @@ struct int_const_s const INT_CONST[] = {
{"tr_trans90",tr_trans90}, {"tr_trans90",tr_trans90},
{"NUMTRANSMAPS",NUMTRANSMAPS}, {"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 // Render flags
{"RF_HORIZONTALFLIP",RF_HORIZONTALFLIP}, {"RF_HORIZONTALFLIP",RF_HORIZONTALFLIP},
{"RF_VERTICALFLIP",RF_VERTICALFLIP}, {"RF_VERTICALFLIP",RF_VERTICALFLIP},

View file

@ -266,16 +266,7 @@ void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t p
FSurfaceInfo Surf; FSurfaceInfo Surf;
Surf.PolyColor.s.red = Surf.PolyColor.s.green = Surf.PolyColor.s.blue = 0xff; Surf.PolyColor.s.red = Surf.PolyColor.s.green = Surf.PolyColor.s.blue = 0xff;
if (!alphalevel) flags |= HWR_GetBlendModeFlag(blendmode);
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;
if (alphalevel == 10) if (alphalevel == 10)
Surf.PolyColor.s.alpha = softwaretranstogl_lo[st_translucency]; 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; FSurfaceInfo Surf;
Surf.PolyColor.s.red = Surf.PolyColor.s.green = Surf.PolyColor.s.blue = 0xff; Surf.PolyColor.s.red = Surf.PolyColor.s.green = Surf.PolyColor.s.blue = 0xff;
if (!alphalevel) flags |= HWR_GetBlendModeFlag(blendmode);
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;
if (alphalevel == 10) if (alphalevel == 10)
Surf.PolyColor.s.alpha = softwaretranstogl_lo[st_translucency]; Surf.PolyColor.s.alpha = softwaretranstogl_lo[st_translucency];

View file

@ -1752,15 +1752,11 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom
if (rover->flags & FF_TRANSLUCENT) if (rover->flags & FF_TRANSLUCENT)
{ {
if (rover->alpha < 256) if (rover->alpha < 256 || rover->blend)
{ {
blendmode = PF_Translucent; blendmode = HWR_GetBlendModeFlag(rover->blend);
Surf.PolyColor.s.alpha = (UINT8)(rover->alpha-1 > 255 ? 255 : rover->alpha-1); 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) 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->flags & FF_TRANSLUCENT)
{ {
if (rover->alpha < 256) if (rover->alpha < 256 || rover->blend)
{ {
blendmode = PF_Translucent; blendmode = HWR_GetBlendModeFlag(rover->blend);
Surf.PolyColor.s.alpha = (UINT8)(rover->alpha-1 > 255 ? 255 : rover->alpha-1); 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) if (gl_backsector->numlights)
@ -3152,14 +3144,9 @@ static void HWR_Subsector(size_t num)
true, rover->master->frontsector->extra_colormap); true, rover->master->frontsector->extra_colormap);
} }
else if (rover->flags & FF_TRANSLUCENT else if (rover->flags & FF_TRANSLUCENT
&& (rover->alpha < 256 && (rover->alpha < 256 || rover->blend)) // SoM: Flags are more efficient
|| rover->alpha == FFLOOR_ALPHA_SPECIAL_ADDITIVE || rover->alpha == FFLOOR_ALPHA_SPECIAL_SUBTRACTIVE)) // SoM: Flags are more efficient
{ {
FBITFIELD blendmode = PF_Translucent | HWR_RippleBlend(gl_frontsector, rover, false); FBITFIELD blendmode = HWR_GetBlendModeFlag(rover->blend) | 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;
light = R_GetPlaneLight(gl_frontsector, centerHeight, dup_viewz < cullHeight ? true : false); light = R_GetPlaneLight(gl_frontsector, centerHeight, dup_viewz < cullHeight ? true : false);
@ -3168,7 +3155,7 @@ static void HWR_Subsector(size_t num)
false, false,
*rover->bottomheight, *rover->bottomheight,
*gl_frontsector->lightlist[light].lightlevel, *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); false, *gl_frontsector->lightlist[light].extra_colormap);
} }
else else
@ -3205,14 +3192,9 @@ static void HWR_Subsector(size_t num)
true, rover->master->frontsector->extra_colormap); true, rover->master->frontsector->extra_colormap);
} }
else if (rover->flags & FF_TRANSLUCENT else if (rover->flags & FF_TRANSLUCENT
&& (rover->alpha < 256 && (rover->alpha < 256 || rover->blend)) // SoM: Flags are more efficient
|| rover->alpha == FFLOOR_ALPHA_SPECIAL_ADDITIVE || rover->alpha == FFLOOR_ALPHA_SPECIAL_SUBTRACTIVE)) // SoM: Flags are more efficient
{ {
FBITFIELD blendmode = PF_Translucent | HWR_RippleBlend(gl_frontsector, rover, true); FBITFIELD blendmode = HWR_GetBlendModeFlag(rover->blend) | 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;
light = R_GetPlaneLight(gl_frontsector, centerHeight, dup_viewz < cullHeight ? true : false); light = R_GetPlaneLight(gl_frontsector, centerHeight, dup_viewz < cullHeight ? true : false);
@ -3221,7 +3203,7 @@ static void HWR_Subsector(size_t num)
true, true,
*rover->topheight, *rover->topheight,
*gl_frontsector->lightlist[light].lightlevel, *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); false, *gl_frontsector->lightlist[light].extra_colormap);
} }
else else

View file

@ -196,6 +196,7 @@ enum ffloor_e {
ffloor_next, ffloor_next,
ffloor_prev, ffloor_prev,
ffloor_alpha, ffloor_alpha,
ffloor_blend,
}; };
static const char *const ffloor_opt[] = { static const char *const ffloor_opt[] = {
@ -214,6 +215,7 @@ static const char *const ffloor_opt[] = {
"next", "next",
"prev", "prev",
"alpha", "alpha",
"blend",
NULL}; NULL};
#ifdef HAVE_LUA_SEGS #ifdef HAVE_LUA_SEGS
@ -1796,6 +1798,9 @@ static int ffloor_get(lua_State *L)
case ffloor_alpha: case ffloor_alpha:
lua_pushinteger(L, ffloor->alpha); lua_pushinteger(L, ffloor->alpha);
return 1; return 1;
case ffloor_blend:
lua_pushinteger(L, ffloor->blend);
return 1;
} }
return 0; return 0;
} }
@ -1874,6 +1879,9 @@ static int ffloor_set(lua_State *L)
case ffloor_alpha: case ffloor_alpha:
ffloor->alpha = (INT32)luaL_checkinteger(L, 3); ffloor->alpha = (INT32)luaL_checkinteger(L, 3);
break; break;
case ffloor_blend:
ffloor->blend = (INT32)luaL_checkinteger(L, 3);
break;
} }
return 0; return 0;
} }

View file

@ -1337,8 +1337,11 @@ static void P_LoadSidedefs(UINT8 *data)
if (msd->toptexture[0] == '#') if (msd->toptexture[0] == '#')
{ {
char *col = msd->toptexture; char *col = msd->toptexture;
sd->toptexture = sd->bottomtexture = sd->toptexture =
((col[1]-'0')*100 + (col[2]-'0')*10 + col[3]-'0') + 1; ((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); sd->midtexture = R_TextureNumForName(msd->midtexture);
} }
else else

View file

@ -5380,7 +5380,26 @@ static ffloor_t *P_AddFakeFloor(sector_t *sec, sector_t *sec2, line_t *master, f
if (flags & FF_TRANSLUCENT) if (flags & FF_TRANSLUCENT)
{ {
if (sides[master->sidenum[0]].toptexture > 0) 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 else
fflr->alpha = 0x80; fflr->alpha = 0x80;
} }

View file

@ -154,9 +154,6 @@ typedef enum
FF_GOOWATER = FF_SHATTERBOTTOM, ///< Used with ::FF_SWIMMABLE. Makes thick bouncey goop. FF_GOOWATER = FF_SHATTERBOTTOM, ///< Used with ::FF_SWIMMABLE. Makes thick bouncey goop.
} ffloortype_e; } ffloortype_e;
#define FFLOOR_ALPHA_SPECIAL_ADDITIVE (901)
#define FFLOOR_ALPHA_SPECIAL_SUBTRACTIVE (902)
typedef struct ffloor_s typedef struct ffloor_s
{ {
fixed_t *topheight; fixed_t *topheight;
@ -187,6 +184,7 @@ typedef struct ffloor_s
INT32 lastlight; INT32 lastlight;
INT32 alpha; INT32 alpha;
UINT8 blend;
tic_t norender; // for culling tic_t norender; // for culling
// these are saved for netgames, so do not let Lua touch these! // these are saved for netgames, so do not let Lua touch these!

View file

@ -861,32 +861,14 @@ void R_DrawSinglePlane(visplane_t *pl)
spanfunctype = (pl->ffloor->master->flags & ML_EFFECT6) ? SPANDRAWFUNC_TRANSSPLAT : SPANDRAWFUNC_TRANS; spanfunctype = (pl->ffloor->master->flags & ML_EFFECT6) ? SPANDRAWFUNC_TRANSSPLAT : SPANDRAWFUNC_TRANS;
// Hacked up support for alpha value in software mode Tails 09-24-2002 // Hacked up support for alpha value in software mode Tails 09-24-2002
if (pl->ffloor->alpha < 12) // ...unhacked by toaster 04-01-2021
return; // Don't even draw it {
else if (pl->ffloor->alpha < 38) INT32 trans = (10*((256+12) - pl->ffloor->alpha))/255;
ds_transmap = R_GetTranslucencyTable(tr_trans90); if (trans >= 10)
else if (pl->ffloor->alpha < 64) return; // Don't even draw it
ds_transmap = R_GetTranslucencyTable(tr_trans80); if (!(ds_transmap = R_GetBlendTable(pl->ffloor->blend, trans)))
else if (pl->ffloor->alpha < 89) spanfunctype = SPANDRAWFUNC_SPLAT; // Opaque, but allow transparent flat pixels
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;
if ((spanfunctype == SPANDRAWFUNC_SPLAT) || (pl->extra_colormap && (pl->extra_colormap->flags & CMF_FOG))) if ((spanfunctype == SPANDRAWFUNC_SPLAT) || (pl->extra_colormap && (pl->extra_colormap->flags & CMF_FOG)))
light = (pl->lightlevel >> LIGHTSEGSHIFT); light = (pl->lightlevel >> LIGHTSEGSHIFT);

View file

@ -631,32 +631,14 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor)
boolean fuzzy = true; boolean fuzzy = true;
// Hacked up support for alpha value in software mode Tails 09-24-2002 // Hacked up support for alpha value in software mode Tails 09-24-2002
if (pfloor->alpha < 12) // ...unhacked by toaster 04-01-2021
return; // Don't even draw it {
else if (pfloor->alpha < 38) INT32 trans = (10*((256+12) - pfloor->alpha))/255;
dc_transmap = R_GetTranslucencyTable(tr_trans90); if (trans >= 10)
else if (pfloor->alpha < 64) return; // Don't even draw it
dc_transmap = R_GetTranslucencyTable(tr_trans80); if (!(dc_transmap = R_GetBlendTable(pfloor->blend, trans)))
else if (pfloor->alpha < 89) fuzzy = false; // Opaque
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
if (fuzzy) if (fuzzy)
colfunc = colfuncs[COLDRAWFUNC_FUZZY]; colfunc = colfuncs[COLDRAWFUNC_FUZZY];