diff --git a/src/rendering/hwrenderer/scene/hw_decal.cpp b/src/rendering/hwrenderer/scene/hw_decal.cpp index 88c78ceda..ec835c01c 100644 --- a/src/rendering/hwrenderer/scene/hw_decal.cpp +++ b/src/rendering/hwrenderer/scene/hw_decal.cpp @@ -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 &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, TArraySetFog(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; diff --git a/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp b/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp index a034276a4..9b2e9d57c 100644 --- a/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp @@ -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. } //========================================================================== diff --git a/src/rendering/hwrenderer/scene/hw_drawstructs.h b/src/rendering/hwrenderer/scene/hw_drawstructs.h index 1d20ced4a..113c0aaac 100644 --- a/src/rendering/hwrenderer/scene/hw_drawstructs.h +++ b/src/rendering/hwrenderer/scene/hw_drawstructs.h @@ -414,6 +414,7 @@ struct HWDecal int rellight; float alpha; FColormap Colormap; + int dynlightindex; sector_t *frontsector; FVector3 Normal; diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index 37ccd66bb..3137679be 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -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);