- added per pixel lighting for decals.

This commit is contained in:
Christoph Oelckers 2020-06-06 15:18:07 +02:00
parent 16e64a19ae
commit d643a42c4f
4 changed files with 28 additions and 14 deletions

View File

@ -47,23 +47,13 @@
void HWDecal::DrawDecal(HWDrawInfo *di, FRenderState &state)
{
// calculate dynamic light effect.
if (di->Level->HasDynamicLights && !di->isFullbrightScene() && gl_light_sprites)
{
// Note: This should be replaced with proper shader based lighting.
double x, y;
float out[3];
decal->GetXY(decal->Side, x, y);
di->GetDynSpriteLight(nullptr, x, y, zcenter, decal->Side->lighthead, decal->Side->sector->PortalGroup, out);
state.SetDynLight(out[0], out[1], out[2]);
}
// alpha color only has an effect when using an alpha texture.
if (decal->RenderStyle.Flags & (STYLEF_RedIsAlpha | STYLEF_ColorIsFixed))
{
state.SetObjectColor(decal->AlphaColor | 0xff000000);
}
state.SetLightIndex(dynlightindex);
state.SetTextureMode(decal->RenderStyle);
state.SetRenderStyle(decal->RenderStyle);
state.SetMaterial(texture, UF_Sprite, 0, CLAMP_XY, decal->Translation, -1);
@ -133,7 +123,6 @@ void HWDrawInfo::DrawDecals(FRenderState &state, TArray<HWDecal *> &decals)
side_t *wall = nullptr;
state.SetDepthMask(false);
state.SetDepthBias(-1, -128);
state.SetLightIndex(-1);
for (auto gldecal : decals)
{
if (gldecal->decal->Side != wall)
@ -167,7 +156,6 @@ void HWWall::DrawDecalsForMirror(HWDrawInfo *di, FRenderState &state, TArray<HWD
{
state.SetDepthMask(false);
state.SetDepthBias(-1, -128);
state.SetLightIndex(-1);
di->SetFog(state, lightlevel, rellight + getExtraLight(), di->isFullbrightScene(), &Colormap, false);
for (auto gldecal : decals)
{
@ -389,11 +377,13 @@ void HWWall::ProcessDecal(HWDrawInfo *di, DBaseDecal *decal, const FVector3 &nor
{
gldecal->lightlevel = 255;
gldecal->rellight = 0;
gldecal->dynlightindex = -1;
}
else
{
gldecal->lightlevel = lightlevel;
gldecal->rellight = rellight + getExtraLight();
gldecal->dynlightindex = dynlightindex;
}
gldecal->Colormap = Colormap;

View File

@ -27,6 +27,7 @@
#include "hwrenderer/scene/hw_drawinfo.h"
#include "hw_material.h"
#include "actor.h"
#include "g_levellocals.h"
EXTERN_CVAR(Bool, gl_seamless)
@ -81,7 +82,14 @@ void HWDrawInfo::AddMirrorSurface(HWWall *w)
tcs[HWWall::LOLFT].u = tcs[HWWall::LORGT].u = tcs[HWWall::UPLFT].u = tcs[HWWall::UPRGT].u = v.X;
tcs[HWWall::LOLFT].v = tcs[HWWall::LORGT].v = tcs[HWWall::UPLFT].v = tcs[HWWall::UPRGT].v = v.Z;
newwall->MakeVertices(this, false);
bool hasDecals = newwall->seg->sidedef && newwall->seg->sidedef->AttachedDecals;
if (hasDecals && Level->HasDynamicLights && !isFullbrightScene())
{
newwall->SetupLights(this, lightdata);
}
newwall->ProcessDecals(this);
newwall->dynlightindex = -1; // the environment map should not be affected by lights - only the decals.
}
//==========================================================================

View File

@ -414,6 +414,7 @@ struct HWDecal
int rellight;
float alpha;
FColormap Colormap;
int dynlightindex;
sector_t *frontsector;
FVector3 Normal;

View File

@ -504,11 +504,26 @@ void HWWall::PutWall(HWDrawInfo *di, bool translucent)
}
bool solid;
if (passflag[type] == 1) solid = true;
else if (type == RENDERWALL_FFBLOCK) solid = texture && !texture->isMasked();
else solid = false;
if (solid) ProcessDecals(di);
bool hasDecals = solid && seg->sidedef && seg->sidedef->AttachedDecals;
if (hasDecals)
{
// If we want to use the light infos for the decal we cannot delay the creation until the render pass.
if (screen->BuffersArePersistent())
{
if (di->Level->HasDynamicLights && !di->isFullbrightScene() && texture != nullptr)
{
SetupLights(di, lightdata);
}
}
ProcessDecals(di);
}
di->AddWall(this);