diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 63f1191ca..a1dd53eb7 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -556,7 +556,7 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool HWR_Lighting(&Surf, lightlevel, planecolormap); - if (PolyFlags & (PF_Translucent|PF_Fog)) + if (PolyFlags & (PF_Translucent|PF_Fog|PF_Additive|PF_Subtractive|PF_ReverseSubtract|PF_Multiplicative|PF_Environment)) { Surf.PolyColor.s.alpha = (UINT8)alpha; PolyFlags |= PF_Modulated; @@ -980,8 +980,8 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, if (cutflag & FF_FOG) HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Fog|PF_NoTexture|polyflags, true, lightnum, colormap); - else if (cutflag & FF_TRANSLUCENT) - HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Translucent|polyflags, false, lightnum, colormap); + else if (polyflags & (PF_Translucent|PF_Additive|PF_Subtractive|PF_ReverseSubtract|PF_Multiplicative|PF_Environment)) + HWR_AddTransparentWall(wallVerts, Surf, texnum, polyflags, false, lightnum, colormap); else HWR_ProjectWall(wallVerts, Surf, PF_Masked|polyflags, lightnum, colormap); @@ -1009,8 +1009,8 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, if (cutflag & FF_FOG) HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Fog|PF_NoTexture|polyflags, true, lightnum, colormap); - else if (cutflag & FF_TRANSLUCENT) - HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Translucent|polyflags, false, lightnum, colormap); + else if (polyflags & (PF_Translucent|PF_Additive|PF_Subtractive|PF_ReverseSubtract|PF_Multiplicative|PF_Environment)) + HWR_AddTransparentWall(wallVerts, Surf, texnum, polyflags, false, lightnum, colormap); else HWR_ProjectWall(wallVerts, Surf, PF_Masked|polyflags, lightnum, colormap); } @@ -1264,6 +1264,7 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom else HWR_ProjectWall(wallVerts, &Surf, PF_Masked, lightnum, colormap); } + gl_midtexture = R_GetTextureNum(gl_sidedef->midtexture); if (gl_midtexture) { @@ -1453,10 +1454,20 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom case 221: case 253: case 256: - blendmode = PF_Translucent; + if (gl_linedef->blendmode) + blendmode = HWR_SurfaceBlend(gl_linedef->blendmode, R_GetLinedefTransTable(gl_linedef->alpha), &Surf); + else + blendmode = PF_Translucent; break; default: - if (gl_linedef->alpha >= 0 && gl_linedef->alpha < FRACUNIT) + if (gl_linedef->blendmode) + { + if (gl_linedef->alpha >= 0 && gl_linedef->alpha < FRACUNIT) + blendmode = HWR_SurfaceBlend(gl_linedef->blendmode, R_GetLinedefTransTable(gl_linedef->alpha), &Surf); + else + blendmode = HWR_GetBlendModeFlag(gl_linedef->blendmode); + } + else if (gl_linedef->alpha >= 0 && gl_linedef->alpha < FRACUNIT) blendmode = HWR_TranstableToAlpha(R_GetLinedefTransTable(gl_linedef->alpha), &Surf); else blendmode = PF_Masked; @@ -1481,11 +1492,9 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (gl_frontsector->numlights) { if (!(blendmode & PF_Masked)) - HWR_SplitWall(gl_frontsector, wallVerts, gl_midtexture, &Surf, FF_TRANSLUCENT, NULL, PF_Decal); + HWR_SplitWall(gl_frontsector, wallVerts, gl_midtexture, &Surf, FF_TRANSLUCENT, NULL, blendmode); else - { - HWR_SplitWall(gl_frontsector, wallVerts, gl_midtexture, &Surf, FF_CUTLEVEL, NULL, PF_Decal); - } + HWR_SplitWall(gl_frontsector, wallVerts, gl_midtexture, &Surf, FF_CUTLEVEL, NULL, blendmode); } else if (!(blendmode & PF_Masked)) HWR_AddTransparentWall(wallVerts, &Surf, gl_midtexture, blendmode, false, lightnum, colormap); @@ -1745,7 +1754,7 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom Surf.PolyColor.s.alpha = HWR_FogBlockAlpha(rover->master->frontsector->lightlevel, rover->master->frontsector->extra_colormap); if (gl_frontsector->numlights) - HWR_SplitWall(gl_frontsector, wallVerts, 0, &Surf, rover->flags, rover, 0); + HWR_SplitWall(gl_frontsector, wallVerts, 0, &Surf, rover->flags, rover, blendmode); else HWR_AddTransparentWall(wallVerts, &Surf, 0, blendmode, true, lightnum, colormap); } @@ -1753,14 +1762,14 @@ 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 && rover->alpha < 256) || rover->blend) { - blendmode = PF_Translucent; + blendmode = rover->blend ? HWR_GetBlendModeFlag(rover->blend) : PF_Translucent; Surf.PolyColor.s.alpha = (UINT8)rover->alpha-1 > 255 ? 255 : rover->alpha-1; } if (gl_frontsector->numlights) - HWR_SplitWall(gl_frontsector, wallVerts, texnum, &Surf, rover->flags, rover, 0); + HWR_SplitWall(gl_frontsector, wallVerts, texnum, &Surf, rover->flags, rover, blendmode); else { if (blendmode != PF_Masked) @@ -1868,7 +1877,7 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom Surf.PolyColor.s.alpha = HWR_FogBlockAlpha(rover->master->frontsector->lightlevel, rover->master->frontsector->extra_colormap); if (gl_backsector->numlights) - HWR_SplitWall(gl_backsector, wallVerts, 0, &Surf, rover->flags, rover, 0); + HWR_SplitWall(gl_backsector, wallVerts, 0, &Surf, rover->flags, rover, blendmode); else HWR_AddTransparentWall(wallVerts, &Surf, 0, blendmode, true, lightnum, colormap); } @@ -1876,14 +1885,14 @@ 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 && rover->alpha < 256) || rover->blend) { - blendmode = PF_Translucent; + blendmode = rover->blend ? HWR_GetBlendModeFlag(rover->blend) : PF_Translucent; Surf.PolyColor.s.alpha = (UINT8)rover->alpha-1 > 255 ? 255 : rover->alpha-1; } if (gl_backsector->numlights) - HWR_SplitWall(gl_backsector, wallVerts, texnum, &Surf, rover->flags, rover, 0); + HWR_SplitWall(gl_backsector, wallVerts, texnum, &Surf, rover->flags, rover, blendmode); else { if (blendmode != PF_Masked) @@ -2960,6 +2969,13 @@ static void HWR_AddPolyObjectPlanes(void) } } +static FBITFIELD HWR_RippleBlend(sector_t *sector, ffloor_t *rover, boolean ceiling) +{ + (void)sector; + (void)ceiling; + return /*R_IsRipplePlane(sector, rover, ceiling)*/ (rover->flags & FF_RIPPLE) ? PF_Ripple : 0; +} + // -----------------+ // HWR_Subsector : Determine floor/ceiling planes. // : Add sprites of things in sector. @@ -3150,7 +3166,7 @@ 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->blend) // SoM: Flags are more efficient { light = R_GetPlaneLight(gl_frontsector, centerHeight, dup_viewz < cullHeight ? true : false); @@ -3159,14 +3175,15 @@ 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, + HWR_RippleBlend(gl_frontsector, rover, false) | (rover->blend ? HWR_GetBlendModeFlag(rover->blend) : PF_Translucent), false, *gl_frontsector->lightlist[light].extra_colormap); } else { HWR_GetLevelFlat(&levelflats[*rover->bottompic]); light = R_GetPlaneLight(gl_frontsector, centerHeight, dup_viewz < cullHeight ? true : false); - HWR_RenderPlane(sub, &extrasubsectors[num], false, *rover->bottomheight, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Occlude, *gl_frontsector->lightlist[light].lightlevel, &levelflats[*rover->bottompic], + HWR_RenderPlane(sub, &extrasubsectors[num], false, *rover->bottomheight, HWR_RippleBlend(gl_frontsector, rover, false)|PF_Occlude, *gl_frontsector->lightlist[light].lightlevel, &levelflats[*rover->bottompic], rover->master->frontsector, 255, *gl_frontsector->lightlist[light].extra_colormap); } } @@ -3195,7 +3212,7 @@ 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->blend) { light = R_GetPlaneLight(gl_frontsector, centerHeight, dup_viewz < cullHeight ? true : false); @@ -3204,14 +3221,15 @@ 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, + HWR_RippleBlend(gl_frontsector, rover, false) | (rover->blend ? HWR_GetBlendModeFlag(rover->blend) : PF_Translucent), false, *gl_frontsector->lightlist[light].extra_colormap); } else { HWR_GetLevelFlat(&levelflats[*rover->toppic]); light = R_GetPlaneLight(gl_frontsector, centerHeight, dup_viewz < cullHeight ? true : false); - HWR_RenderPlane(sub, &extrasubsectors[num], true, *rover->topheight, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Occlude, *gl_frontsector->lightlist[light].lightlevel, &levelflats[*rover->toppic], + HWR_RenderPlane(sub, &extrasubsectors[num], true, *rover->topheight, HWR_RippleBlend(gl_frontsector, rover, false)|PF_Occlude, *gl_frontsector->lightlist[light].lightlevel, &levelflats[*rover->toppic], rover->master->frontsector, 255, *gl_frontsector->lightlist[light].extra_colormap); } } diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 9031c99f1..04e6fde8d 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 @@ -1807,6 +1809,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; } @@ -1885,6 +1890,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 588815aee..6320edc22 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1350,8 +1350,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 @@ -3314,22 +3317,30 @@ static void P_ConvertBinaryMap(void) lines[i].args[4] |= TMSC_BACKTOFRONTCEILING; lines[i].special = 720; break; - - case 900: //Translucent wall (10%) - case 901: //Translucent wall (20%) - case 902: //Translucent wall (30%) - case 903: //Translucent wall (40%) - case 904: //Translucent wall (50%) - case 905: //Translucent wall (60%) - case 906: //Translucent wall (70%) - case 907: //Translucent wall (80%) - case 908: //Translucent wall (90%) - lines[i].alpha = ((909 - lines[i].special) << FRACBITS)/10; - break; default: break; } + // Set alpha for translucent walls + if (lines[i].special >= 900 && lines[i].special < 909) + lines[i].alpha = ((909 - lines[i].special) << FRACBITS)/10; + + // Set alpha for additive/subtractive/reverse subtractive walls + if (lines[i].special >= 910 && lines[i].special <= 939) + lines[i].alpha = ((10 - lines[i].special % 10) << FRACBITS)/10; + + if (lines[i].special >= 910 && lines[i].special <= 919) // additive + lines[i].blendmode = AST_ADD; + + if (lines[i].special >= 920 && lines[i].special <= 929) // subtractive + lines[i].blendmode = AST_SUBTRACT; + + if (lines[i].special >= 930 && lines[i].special <= 939) // reverse subtractive + lines[i].blendmode = AST_REVERSESUBTRACT; + + if (lines[i].special == 940) // modulate + lines[i].blendmode = AST_MODULATE; + //Linedef executor delay if (lines[i].special >= 400 && lines[i].special < 500) { diff --git a/src/p_spec.c b/src/p_spec.c index 07410efa2..ebabe6a79 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -5601,7 +5601,16 @@ 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 >= 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 f4ab58295..3c2178937 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -184,6 +184,7 @@ typedef struct ffloor_s INT32 lastlight; INT32 alpha; + UINT8 blend; // blendmode tic_t norender; // for culling // these are saved for netgames, so do not let Lua touch these! @@ -397,6 +398,7 @@ typedef struct line_s // Visual appearance: sidedefs. UINT16 sidenum[2]; // sidenum[1] will be 0xffff if one-sided fixed_t alpha; // translucency + UINT8 blendmode; // blendmode INT32 executordelay; fixed_t bbox[4]; // bounding box for the extent of the linedef diff --git a/src/r_draw.c b/src/r_draw.c index f0a19a462..65bb87bfb 100644 --- a/src/r_draw.c +++ b/src/r_draw.c @@ -248,6 +248,9 @@ static void BlendTab_Subtractive(UINT8 *table, int style, UINT8 blendamt) result.s.green = max(0, result.s.green - blendamt); result.s.blue = max(0, result.s.blue - blendamt); + //probably incorrect, but does look better at lower opacity... + //result.rgba = ASTBlendPixel(result, frontrgba, AST_TRANSLUCENT, blendamt); + table[((bg * 0x100) + fg)] = GetColorLUT(&transtab_lut, result.s.red, result.s.green, result.s.blue); } } diff --git a/src/r_plane.c b/src/r_plane.c index 45719ce58..d854c2342 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -855,28 +855,16 @@ 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 // Opaque, but allow transparent flat pixels - spanfunctype = SPANDRAWFUNC_SPLAT; + // ...unhacked by toaster 04-01-2021, re-hacked a little by sphere 19-11-2021 + { + INT32 trans = (10*((256+12) - pl->ffloor->alpha))/255; + if (trans >= 10) + return; // Don't even draw it + if (pl->ffloor->blend) // additive, (reverse) subtractive, modulative + ds_transmap = R_GetBlendTable(pl->ffloor->blend, trans); + else if (!(ds_transmap = R_GetTranslucencyTable(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 a8c85ec33..4460f9f90 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -155,11 +155,18 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) if (!ldef->alpha) return; - if (ldef->alpha > 0 && ldef->alpha < FRACUNIT) + if (ldef->blendmode) + { + if (ldef->alpha == NUMTRANSMAPS || ldef->blendmode == AST_MODULATE) + dc_transmap = R_GetBlendTable(ldef->blendmode, 0); + else + dc_transmap = R_GetBlendTable(ldef->blendmode, R_GetLinedefTransTable(ldef->alpha)); + colfunc = colfuncs[COLDRAWFUNC_FUZZY]; + } + else if (ldef->alpha > 0 && ldef->alpha < FRACUNIT) { dc_transmap = R_GetTranslucencyTable(R_GetLinedefTransTable(ldef->alpha)); colfunc = colfuncs[COLDRAWFUNC_FUZZY]; - } else if (ldef->special == 909) { @@ -600,28 +607,16 @@ 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 - fuzzy = false; // Opaque + // ...unhacked by toaster 04-01-2021, re-hacked a little by sphere 19-11-2021 + { + INT32 trans = (10*((256+12) - pfloor->alpha))/255; + if (trans >= 10) + return; // Don't even draw it + if (pfloor->blend) // additive, (reverse) subtractive, modulative + dc_transmap = R_GetBlendTable(pfloor->blend, trans); + else if (!(dc_transmap = R_GetTranslucencyTable(trans))) + fuzzy = false; // Opaque + } if (fuzzy) colfunc = colfuncs[COLDRAWFUNC_FUZZY];