- cleanup of 2D code.

This commit is contained in:
Christoph Oelckers 2020-04-11 19:49:09 +02:00
commit def123823b
10 changed files with 229 additions and 229 deletions

View file

@ -45,7 +45,10 @@
#include "g_levellocals.h"
#include "vm.h"
#include "v_palette.h"
#include "r_utility.h"
#include "hwrenderer/utility/hw_cvars.h"
CVAR(Float, underwater_fade_scalar, 1.0f, CVAR_ARCHIVE) // [Nash] user-settable underwater blend intensity
CVAR( Float, blood_fade_scalar, 1.0f, CVAR_ARCHIVE ) // [SP] Pulled from Skulltag - changed default from 0.5 to 1.0
CVAR( Float, pickup_fade_scalar, 1.0f, CVAR_ARCHIVE ) // [SP] Uses same logic as blood_fade_scalar except for pickups
@ -208,3 +211,167 @@ void V_AddPlayerBlend (player_t *CPlayer, float blend[4], float maxinvalpha, int
// cap opacity if desired
if (blend[3] > maxinvalpha) blend[3] = maxinvalpha;
}
//==========================================================================
//
// Draws a blend over the entire view
//
//==========================================================================
FVector4 V_CalcBlend(sector_t* viewsector, PalEntry* modulateColor)
{
float blend[4] = { 0,0,0,0 };
PalEntry blendv = 0;
float extra_red;
float extra_green;
float extra_blue;
player_t* player = nullptr;
bool fullbright = false;
if (modulateColor) *modulateColor = 0xffffffff;
if (players[consoleplayer].camera != nullptr)
{
player = players[consoleplayer].camera->player;
if (player)
fullbright = (player->fixedcolormap != NOFIXEDCOLORMAP || player->extralight == INT_MIN || player->fixedlightlevel != -1);
}
// don't draw sector based blends when any fullbright screen effect is active.
if (!fullbright)
{
const auto& vpp = r_viewpoint.Pos;
if (!viewsector->e->XFloor.ffloors.Size())
{
if (viewsector->GetHeightSec())
{
auto s = viewsector->heightsec;
blendv = s->floorplane.PointOnSide(vpp) < 0 ? s->bottommap : s->ceilingplane.PointOnSide(vpp) < 0 ? s->topmap : s->midmap;
}
}
else
{
TArray<lightlist_t>& lightlist = viewsector->e->XFloor.lightlist;
for (unsigned int i = 0; i < lightlist.Size(); i++)
{
double lightbottom;
if (i < lightlist.Size() - 1)
lightbottom = lightlist[i + 1].plane.ZatPoint(vpp);
else
lightbottom = viewsector->floorplane.ZatPoint(vpp);
if (lightbottom < vpp.Z && (!lightlist[i].caster || !(lightlist[i].caster->flags & FF_FADEWALLS)))
{
// 3d floor 'fog' is rendered as a blending value
blendv = lightlist[i].blend;
// If this is the same as the sector's it doesn't apply!
if (blendv == viewsector->Colormap.FadeColor) blendv = 0;
// a little hack to make this work for Legacy maps.
if (blendv.a == 0 && blendv != 0) blendv.a = 128;
break;
}
}
}
if (blendv.a == 0 && V_IsTrueColor()) // The paletted software renderer uses the original colormap as this frame's palette, but in true color that isn't doable.
{
blendv = R_BlendForColormap(blendv);
}
if (blendv.a == 255)
{
extra_red = blendv.r / 255.0f;
extra_green = blendv.g / 255.0f;
extra_blue = blendv.b / 255.0f;
// If this is a multiplicative blend do it separately and add the additive ones on top of it.
// black multiplicative blends are ignored
if (extra_red || extra_green || extra_blue)
{
if (modulateColor) *modulateColor = blendv;
}
blendv = 0;
}
else if (blendv.a)
{
// [Nash] allow user to set blend intensity
int cnt = blendv.a;
cnt = (int)(cnt * underwater_fade_scalar);
V_AddBlend(blendv.r / 255.f, blendv.g / 255.f, blendv.b / 255.f, cnt / 255.0f, blend);
}
}
else if (player && player->fixedlightlevel != -1 && player->fixedcolormap == NOFIXEDCOLORMAP)
{
// Draw fixedlightlevel effects as a 2D overlay. The hardware renderer just processes such a scene fullbright without any lighting.
auto torchtype = PClass::FindActor(NAME_PowerTorch);
auto litetype = PClass::FindActor(NAME_PowerLightAmp);
PalEntry color = 0xffffffff;
for (AActor* in = player->mo->Inventory; in; in = in->Inventory)
{
// Need special handling for light amplifiers
if (in->IsKindOf(torchtype))
{
// The software renderer already bakes the torch flickering into its output, so this must be omitted here.
float r = vid_rendermode < 4 ? 1.f : (0.8f + (7 - player->fixedlightlevel) / 70.0f);
if (r > 1.0f) r = 1.0f;
int rr = (int)(r * 255);
int b = rr;
if (gl_enhanced_nightvision) b = b * 3 / 4;
color = PalEntry(255, rr, rr, b);
}
else if (in->IsKindOf(litetype))
{
if (gl_enhanced_nightvision)
{
color = PalEntry(255, 104, 255, 104);
}
}
}
if (modulateColor)
{
*modulateColor = color;
}
}
if (player)
{
V_AddPlayerBlend(player, blend, 0.5, 175);
}
if (players[consoleplayer].camera != NULL)
{
// except for fadeto effects
player_t* player = (players[consoleplayer].camera->player != NULL) ? players[consoleplayer].camera->player : &players[consoleplayer];
V_AddBlend(player->BlendR, player->BlendG, player->BlendB, player->BlendA, blend);
}
const float br = clamp(blend[0] * 255.f, 0.f, 255.f);
const float bg = clamp(blend[1] * 255.f, 0.f, 255.f);
const float bb = clamp(blend[2] * 255.f, 0.f, 255.f);
return { br, bg, bb, blend[3] };
}
//==========================================================================
//
// Draws a blend over the entire view
//
//==========================================================================
void V_DrawBlend(sector_t* viewsector)
{
auto drawer = twod;
PalEntry modulateColor;
auto blend = V_CalcBlend(viewsector, &modulateColor);
if (modulateColor != 0xffffffff)
{
Dim(twod, modulateColor, 1, 0, 0, drawer->GetWidth(), drawer->GetHeight(), &LegacyRenderStyles[STYLE_Multiply]);
}
const PalEntry bcolor(255, uint8_t(blend.X), uint8_t(blend.Y), uint8_t(blend.Z));
Dim(drawer, bcolor, blend.W, 0, 0, drawer->GetWidth(), drawer->GetHeight());
}