From 28abc96aef14dd39af83b6c050c3ca283b8fe350 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Mon, 6 Mar 2017 16:14:54 -0500 Subject: [PATCH] - fully implemented "nolightfade" to turn off diminishing lights in the software renderer. - unfortunately, LIGHT2SHADE had to be transformed into a namespaced function. --- src/gl/system/gl_swframebuffer.cpp | 2 +- src/polyrenderer/scene/poly_decal.cpp | 2 +- src/polyrenderer/scene/poly_particle.cpp | 2 +- src/polyrenderer/scene/poly_plane.cpp | 6 ++-- src/polyrenderer/scene/poly_playersprite.cpp | 4 +-- src/polyrenderer/scene/poly_scene.cpp | 3 +- src/polyrenderer/scene/poly_sprite.cpp | 2 +- src/polyrenderer/scene/poly_wall.cpp | 3 +- src/polyrenderer/scene/poly_wallsprite.cpp | 2 +- src/swrenderer/line/r_line.cpp | 6 ++-- src/swrenderer/line/r_walldraw.cpp | 2 +- src/swrenderer/plane/r_flatplane.cpp | 9 +++-- src/swrenderer/plane/r_slopeplane.cpp | 10 ++++-- src/swrenderer/r_swcanvas.cpp | 2 +- src/swrenderer/scene/r_light.cpp | 18 +++++++--- src/swrenderer/scene/r_light.h | 37 ++++++++++++-------- src/swrenderer/scene/r_opaque_pass.cpp | 6 ++-- src/swrenderer/things/r_particle.cpp | 2 +- src/swrenderer/things/r_playersprite.cpp | 2 +- src/swrenderer/things/r_sprite.cpp | 2 +- src/swrenderer/things/r_visiblesprite.cpp | 4 +-- src/swrenderer/things/r_voxel.cpp | 2 +- src/swrenderer/things/r_wallsprite.cpp | 6 ++-- src/win32/fb_d3d9.cpp | 2 +- 24 files changed, 84 insertions(+), 52 deletions(-) diff --git a/src/gl/system/gl_swframebuffer.cpp b/src/gl/system/gl_swframebuffer.cpp index 04c2b7eb7..c883c662f 100644 --- a/src/gl/system/gl_swframebuffer.cpp +++ b/src/gl/system/gl_swframebuffer.cpp @@ -2951,7 +2951,7 @@ void OpenGLSWFrameBuffer::FillSimplePoly(FTexture *texture, FVector2 *points, in DAngle rotation, FDynamicColormap *colormap, PalEntry flatcolor, int lightlevel, int bottomclip) { // Use an equation similar to player sprites to determine shade - double fadelevel = clamp((LIGHT2SHADE(lightlevel) / 65536. - 12) / NUMCOLORMAPS, 0.0, 1.0); + double fadelevel = clamp((swrenderer::LIGHT2SHADE(lightlevel, true) / 65536. - 12) / NUMCOLORMAPS, 0.0, 1.0); BufferedTris *quad; FBVERTEX *verts; diff --git a/src/polyrenderer/scene/poly_decal.cpp b/src/polyrenderer/scene/poly_decal.cpp index fad44862f..0812f3a79 100644 --- a/src/polyrenderer/scene/poly_decal.cpp +++ b/src/polyrenderer/scene/poly_decal.cpp @@ -139,7 +139,7 @@ void RenderPolyDecal::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan args.uniforms.flags = 0; args.SetColormap(front->ColorMap); args.SetTexture(tex, decal->Translation, true); - args.uniforms.globvis = (float)swrenderer::LightVisibility::Instance()->WallGlobVis(); + args.uniforms.globvis = (float)swrenderer::LightVisibility::Instance()->WallGlobVis(foggy); if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap()) { args.uniforms.light = 256; diff --git a/src/polyrenderer/scene/poly_particle.cpp b/src/polyrenderer/scene/poly_particle.cpp index 39f5514f4..fd9ee5c88 100644 --- a/src/polyrenderer/scene/poly_particle.cpp +++ b/src/polyrenderer/scene/poly_particle.cpp @@ -74,7 +74,7 @@ void RenderPolyParticle::Render(const TriMatrix &worldToClip, const Vec4f &clipP PolyDrawArgs args; - args.uniforms.globvis = (float)swrenderer::LightVisibility::Instance()->ParticleGlobVis(); + args.uniforms.globvis = (float)swrenderer::LightVisibility::Instance()->ParticleGlobVis(foggy); if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap()) { diff --git a/src/polyrenderer/scene/poly_plane.cpp b/src/polyrenderer/scene/poly_plane.cpp index 2aec6b08d..00a283b0a 100644 --- a/src/polyrenderer/scene/poly_plane.cpp +++ b/src/polyrenderer/scene/poly_plane.cpp @@ -99,6 +99,7 @@ void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, const Vec4f &c swrenderer::CameraLight *cameraLight = swrenderer::CameraLight::Instance(); int lightlevel = 255; + bool foggy = false; if (cameraLight->FixedLightLevel() < 0 && sub->sector->e->XFloor.lightlist.Size()) { lightlist_t *light = P_GetPlaneLight(sub->sector, &sub->sector->ceilingplane, false); @@ -109,7 +110,7 @@ void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, const Vec4f &c UVTransform xform(ceiling ? fakeFloor->top.model->planes[sector_t::ceiling].xform : fakeFloor->top.model->planes[sector_t::floor].xform, tex); PolyDrawArgs args; - args.uniforms.globvis = (float)swrenderer::LightVisibility::Instance()->SlopePlaneGlobVis() * 48.0f; + args.uniforms.globvis = (float)swrenderer::LightVisibility::Instance()->SlopePlaneGlobVis(foggy) * 48.0f; args.uniforms.light = (uint32_t)(lightlevel / 255.0f * 256.0f); if (cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap()) args.uniforms.light = 256; @@ -155,6 +156,7 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan { std::vector portalSegments; FSectorPortal *portal = nullptr;// sub->sector->ValidatePortal(ceiling ? sector_t::ceiling : sector_t::floor); + bool foggy = false; PolyDrawSectorPortal *polyportal = nullptr; if (portal && (portal->mFlags & PORTSF_INSKYBOX) == PORTSF_INSKYBOX) // Do not recurse into portals we already recursed into portal = nullptr; @@ -305,7 +307,7 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan swrenderer::CameraLight *cameraLight = swrenderer::CameraLight::Instance(); PolyDrawArgs args; - args.uniforms.globvis = (float)swrenderer::LightVisibility::Instance()->SlopePlaneGlobVis() * 48.0f; + args.uniforms.globvis = (float)swrenderer::LightVisibility::Instance()->SlopePlaneGlobVis(foggy) * 48.0f; args.uniforms.light = (uint32_t)(frontsector->lightlevel / 255.0f * 256.0f); if (cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap()) args.uniforms.light = 256; diff --git a/src/polyrenderer/scene/poly_playersprite.cpp b/src/polyrenderer/scene/poly_playersprite.cpp index 339d3051a..d55ecb9e7 100644 --- a/src/polyrenderer/scene/poly_playersprite.cpp +++ b/src/polyrenderer/scene/poly_playersprite.cpp @@ -223,9 +223,9 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa bool foggy = false; int actualextralight = foggy ? 0 : extralight << 4; - int spriteshade = LIGHT2SHADE(owner->Sector->lightlevel + actualextralight); + int spriteshade = swrenderer::LIGHT2SHADE(owner->Sector->lightlevel + actualextralight, foggy); double minz = double((2048 * 4) / double(1 << 20)); - ColormapNum = GETPALOOKUP(swrenderer::LightVisibility::Instance()->SpriteGlobVis() / minz, spriteshade); + ColormapNum = GETPALOOKUP(swrenderer::LightVisibility::Instance()->SpriteGlobVis(foggy) / minz, spriteshade); if (sprite->GetID() < PSP_TARGETCENTER) { diff --git a/src/polyrenderer/scene/poly_scene.cpp b/src/polyrenderer/scene/poly_scene.cpp index 9685c4241..125537678 100644 --- a/src/polyrenderer/scene/poly_scene.cpp +++ b/src/polyrenderer/scene/poly_scene.cpp @@ -228,6 +228,7 @@ void RenderPolyScene::RenderLine(subsector_t *sub, seg_t *line, sector_t *fronts void RenderPolyScene::RenderPortals(int portalDepth) { + bool foggy = false; if (portalDepth < r_portal_recursions) { for (auto &portal : SectorPortals) @@ -241,7 +242,7 @@ void RenderPolyScene::RenderPortals(int portalDepth) PolyDrawArgs args; args.objectToClip = &WorldToClip; args.mode = TriangleDrawMode::Fan; - args.uniforms.globvis = (float)swrenderer::LightVisibility::Instance()->WallGlobVis(); + args.uniforms.globvis = (float)swrenderer::LightVisibility::Instance()->WallGlobVis(foggy); args.uniforms.color = 0; args.uniforms.light = 256; args.uniforms.flags = TriUniforms::fixed_light; diff --git a/src/polyrenderer/scene/poly_sprite.cpp b/src/polyrenderer/scene/poly_sprite.cpp index 0599a4b20..e2ca59b24 100644 --- a/src/polyrenderer/scene/poly_sprite.cpp +++ b/src/polyrenderer/scene/poly_sprite.cpp @@ -139,7 +139,7 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, const Vec4f &clipPla swrenderer::CameraLight *cameraLight = swrenderer::CameraLight::Instance(); PolyDrawArgs args; - args.uniforms.globvis = (float)swrenderer::LightVisibility::Instance()->SpriteGlobVis(); + args.uniforms.globvis = (float)swrenderer::LightVisibility::Instance()->SpriteGlobVis(foggy); args.uniforms.flags = 0; if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap()) { diff --git a/src/polyrenderer/scene/poly_wall.cpp b/src/polyrenderer/scene/poly_wall.cpp index d8fb2a7ae..e64d1f6c6 100644 --- a/src/polyrenderer/scene/poly_wall.cpp +++ b/src/polyrenderer/scene/poly_wall.cpp @@ -198,6 +198,7 @@ void RenderPolyWall::SetCoords(const DVector2 &v1, const DVector2 &v2, double ce void RenderPolyWall::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane, PolyCull &cull) { + bool foggy = false; FTexture *tex = GetTexture(); if (!tex && !Polyportal) return; @@ -247,7 +248,7 @@ void RenderPolyWall::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane } PolyDrawArgs args; - args.uniforms.globvis = (float)swrenderer::LightVisibility::Instance()->WallGlobVis(); + args.uniforms.globvis = (float)swrenderer::LightVisibility::Instance()->WallGlobVis(foggy); args.uniforms.light = (uint32_t)(GetLightLevel() / 255.0f * 256.0f); args.uniforms.flags = 0; args.uniforms.subsectorDepth = SubsectorDepth; diff --git a/src/polyrenderer/scene/poly_wallsprite.cpp b/src/polyrenderer/scene/poly_wallsprite.cpp index 31aded9ac..a563f026d 100644 --- a/src/polyrenderer/scene/poly_wallsprite.cpp +++ b/src/polyrenderer/scene/poly_wallsprite.cpp @@ -101,7 +101,7 @@ void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, const Vec4f &cli swrenderer::CameraLight *cameraLight = swrenderer::CameraLight::Instance(); PolyDrawArgs args; - args.uniforms.globvis = (float)swrenderer::LightVisibility::Instance()->WallGlobVis(); + args.uniforms.globvis = (float)swrenderer::LightVisibility::Instance()->WallGlobVis(foggy); if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap()) { args.uniforms.light = 256; diff --git a/src/swrenderer/line/r_line.cpp b/src/swrenderer/line/r_line.cpp index 94b1cfc4b..33006c8c6 100644 --- a/src/swrenderer/line/r_line.cpp +++ b/src/swrenderer/line/r_line.cpp @@ -496,7 +496,7 @@ namespace swrenderer } else { - draw_segment->shade = LIGHT2SHADE(mLineSegment->sidedef->GetLightLevel(foggy, mLineSegment->frontsector->lightlevel) + R_ActualExtraLight(foggy)); + draw_segment->shade = LIGHT2SHADE(mLineSegment->sidedef->GetLightLevel(foggy, mLineSegment->frontsector->lightlevel) + R_ActualExtraLight(foggy), foggy); } if (draw_segment->bFogBoundary || draw_segment->maskedtexturecol != nullptr) @@ -781,8 +781,8 @@ namespace swrenderer CameraLight *cameraLight = CameraLight::Instance(); if (cameraLight->FixedColormap() == nullptr && cameraLight->FixedLightLevel() < 0) { - wallshade = LIGHT2SHADE(mLineSegment->sidedef->GetLightLevel(foggy, mFrontSector->lightlevel) + R_ActualExtraLight(foggy)); - double GlobVis = LightVisibility::Instance()->WallGlobVis(); + wallshade = LIGHT2SHADE(mLineSegment->sidedef->GetLightLevel(foggy, mFrontSector->lightlevel) + R_ActualExtraLight(foggy), foggy); + double GlobVis = LightVisibility::Instance()->WallGlobVis(foggy); rw_lightleft = float(GlobVis / WallC.sz1); rw_lightstep = float((GlobVis / WallC.sz2 - rw_lightleft) / (WallC.sx2 - WallC.sx1)); } diff --git a/src/swrenderer/line/r_walldraw.cpp b/src/swrenderer/line/r_walldraw.cpp index 5f4cd8485..9b2a4f7ce 100644 --- a/src/swrenderer/line/r_walldraw.cpp +++ b/src/swrenderer/line/r_walldraw.cpp @@ -401,7 +401,7 @@ namespace swrenderer lightlist_t *lit = &frontsector->e->XFloor.lightlist[i]; basecolormap = lit->extra_colormap; - wallshade = LIGHT2SHADE(curline->sidedef->GetLightLevel(foggy, *lit->p_lightlevel, lit->lightsource != NULL) + R_ActualExtraLight(foggy)); + wallshade = LIGHT2SHADE(curline->sidedef->GetLightLevel(foggy, *lit->p_lightlevel, lit->lightsource != NULL) + R_ActualExtraLight(foggy), foggy); } ProcessNormalWall(up, dwal, texturemid, swal, lwal); diff --git a/src/swrenderer/plane/r_flatplane.cpp b/src/swrenderer/plane/r_flatplane.cpp index 28961baad..725dd4616 100644 --- a/src/swrenderer/plane/r_flatplane.cpp +++ b/src/swrenderer/plane/r_flatplane.cpp @@ -26,6 +26,7 @@ #include "cmdlib.h" #include "d_net.h" #include "g_level.h" +#include "g_levellocals.h" #include "swrenderer/scene/r_opaque_pass.h" #include "r_flatplane.h" #include "swrenderer/scene/r_3dfloors.h" @@ -115,7 +116,11 @@ namespace swrenderer planeheight = fabs(pl->height.Zat0() - ViewPos.Z); basecolormap = colormap; - GlobVis = LightVisibility::Instance()->FlatPlaneGlobVis() / planeheight; + + // [RH] set foggy flag + bool foggy = (level.fadeto || basecolormap->Fade || (level.flags & LEVEL_HASFADETABLE)); + + GlobVis = LightVisibility::Instance()->FlatPlaneGlobVis(foggy) / planeheight; CameraLight *cameraLight = CameraLight::Instance(); if (cameraLight->FixedLightLevel() >= 0) @@ -131,7 +136,7 @@ namespace swrenderer else { plane_shade = true; - planeshade = LIGHT2SHADE(pl->lightlevel); + planeshade = LIGHT2SHADE(pl->lightlevel, foggy); } drawerargs.SetStyle(masked, additive, alpha); diff --git a/src/swrenderer/plane/r_slopeplane.cpp b/src/swrenderer/plane/r_slopeplane.cpp index 6be3b1a7b..033c5257d 100644 --- a/src/swrenderer/plane/r_slopeplane.cpp +++ b/src/swrenderer/plane/r_slopeplane.cpp @@ -26,6 +26,7 @@ #include "cmdlib.h" #include "d_net.h" #include "g_level.h" +#include "g_levellocals.h" #include "swrenderer/scene/r_opaque_pass.h" #include "r_slopeplane.h" #include "swrenderer/scene/r_3dfloors.h" @@ -152,12 +153,15 @@ namespace swrenderer plane_sz[0] = -plane_sz[0]; } - planelightfloat = (LightVisibility::Instance()->SlopePlaneGlobVis() * lxscale * lyscale) / (fabs(pl->height.ZatPoint(ViewPos) - ViewPos.Z)) / 65536.f; + // [RH] set foggy flag + basecolormap = colormap; + bool foggy = level.fadeto || basecolormap->Fade || (level.flags & LEVEL_HASFADETABLE);; + + planelightfloat = (LightVisibility::Instance()->SlopePlaneGlobVis(foggy) * lxscale * lyscale) / (fabs(pl->height.ZatPoint(ViewPos) - ViewPos.Z)) / 65536.f; if (pl->height.fC() > 0) planelightfloat = -planelightfloat; - basecolormap = colormap; CameraLight *cameraLight = CameraLight::Instance(); if (cameraLight->FixedLightLevel() >= 0) @@ -174,7 +178,7 @@ namespace swrenderer { drawerargs.SetLight(basecolormap, 0, 0); plane_shade = true; - planeshade = LIGHT2SHADE(pl->lightlevel); + planeshade = LIGHT2SHADE(pl->lightlevel, foggy); } // Hack in support for 1 x Z and Z x 1 texture sizes diff --git a/src/swrenderer/r_swcanvas.cpp b/src/swrenderer/r_swcanvas.cpp index c728dd315..4866ac0cd 100644 --- a/src/swrenderer/r_swcanvas.cpp +++ b/src/swrenderer/r_swcanvas.cpp @@ -198,7 +198,7 @@ void SWCanvas::FillSimplePoly(DCanvas *canvas, FTexture *tex, FVector2 *points, FDynamicColormap *colormap, PalEntry flatcolor, int lightlevel, int bottomclip) { // Use an equation similar to player sprites to determine shade - fixed_t shade = LIGHT2SHADE(lightlevel) - 12 * FRACUNIT; + fixed_t shade = LIGHT2SHADE(lightlevel, true) - 12 * FRACUNIT; float topy, boty, leftx, rightx; int toppt, botpt, pt1, pt2; int i; diff --git a/src/swrenderer/scene/r_light.cpp b/src/swrenderer/scene/r_light.cpp index fa9ae27f9..686cfc524 100644 --- a/src/swrenderer/scene/r_light.cpp +++ b/src/swrenderer/scene/r_light.cpp @@ -32,12 +32,20 @@ #include "d_player.h" #include "swrenderer/scene/r_light.h" #include "swrenderer/viewport/r_viewport.h" +#include "gl/data/gl_data.h" CVAR(Bool, r_shadercolormaps, true, CVAR_ARCHIVE) EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor) namespace swrenderer { + fixed_t LIGHT2SHADE(int l, bool foggy) + { + return (!foggy && (glset.nolightfade) ? + ((MAX(255 - l, 0) * NUMCOLORMAPS) << (FRACBITS - 8)) : + ((NUMCOLORMAPS*2*FRACUNIT)-(((l)+12)*(FRACUNIT*NUMCOLORMAPS/128)))); + } + CameraLight *CameraLight::Instance() { static CameraLight instance; @@ -146,10 +154,12 @@ namespace swrenderer TiltVisibility = float(vis * FocalTangent * (16.f * 320.f) / viewwidth); - // Disable diminishing light (To do: make a cvar control this) - WallVisibility = 0.0; - FloorVisibility = 0.0; - TiltVisibility = 0.0f; + NoLightFade = glset.nolightfade; + + // Disable diminishing light + // WallVisibility = 0.0; + // FloorVisibility = 0.0; + // TiltVisibility = 0.0f; } // Controls how quickly light ramps across a 1/z range. Set this, and it diff --git a/src/swrenderer/scene/r_light.h b/src/swrenderer/scene/r_light.h index 7b127acb2..1219a06c1 100644 --- a/src/swrenderer/scene/r_light.h +++ b/src/swrenderer/scene/r_light.h @@ -29,13 +29,18 @@ // The size of a single colormap, in bits #define COLORMAPSHIFT 8 -// Convert a light level into an unbounded colormap index (shade). Result is -// fixed point. Why the +12? I wish I knew, but experimentation indicates it -// is necessary in order to best reproduce Doom's original lighting. +// Convert a light level into an unbounded colormap index (shade). Result is +// fixed point. Why the +12? I wish I knew, but experimentation indicates it +// is necessary in order to best reproduce Doom's original lighting. //#define LIGHT2SHADE(l) ((NUMCOLORMAPS*2*FRACUNIT)-(((l)+12)*(FRACUNIT*NUMCOLORMAPS/128))) -// Disable diminishing light (To do: merge with LIGHT2SHADE and let a cvar control it, maybe by converting this to a function, like R_ActualExtraLight) -#define LIGHT2SHADE(lightlev) ((MAX(255 - lightlev, 0) * NUMCOLORMAPS) << (FRACBITS - 8)) +// Disable diminishing light (To do: merge with LIGHT2SHADE and let a cvar control it, maybe by converting this to a function, like R_ActualExtraLight) +//#define LIGHT2SHADE(lightlev) ((MAX(255 - lightlev, 0) * NUMCOLORMAPS) << (FRACBITS - 8)) + +// combined! +//#define LIGHT2SHADE(l) ((glset.nolightfade)? \ +// ((MAX(255 - l, 0) * NUMCOLORMAPS) << (FRACBITS - 8)) : \ +// ((NUMCOLORMAPS*2*FRACUNIT)-(((l)+12)*(FRACUNIT*NUMCOLORMAPS/128)))) // MAXLIGHTSCALE from original DOOM, divided by 2. #define MAXLIGHTVIS (24.0) @@ -57,6 +62,8 @@ struct FSWColormap; namespace swrenderer { + fixed_t LIGHT2SHADE(int lightlevel, bool foggy); + class CameraLight { public: @@ -83,17 +90,17 @@ namespace swrenderer void SetVisibility(double visibility); double GetVisibility() const { return CurrentVisibility; } - double WallGlobVis() const { return WallVisibility; } - double SpriteGlobVis() const { return WallVisibility; } - double ParticleGlobVis() const { return WallVisibility * 0.5; } - double FlatPlaneGlobVis() const { return FloorVisibility; } - double SlopePlaneGlobVis() const { return TiltVisibility; } + double WallGlobVis(bool foggy) const { return (NoLightFade && !foggy) ? 0.0f : WallVisibility; } + double SpriteGlobVis(bool foggy) const { return (NoLightFade && !foggy) ? 0.0f : WallVisibility; } + double ParticleGlobVis(bool foggy) const { return (NoLightFade && !foggy) ? 0.0f : (WallVisibility * 0.5); } + double FlatPlaneGlobVis(bool foggy) const { return (NoLightFade && !foggy) ? 0.0f : FloorVisibility; } + double SlopePlaneGlobVis(bool foggy) const { return (NoLightFade && !foggy) ? 0.0f : TiltVisibility; } // The vis value to pass into the GETPALOOKUP or LIGHTSCALE macros - double WallVis(double screenZ) const { return WallGlobVis() / screenZ; } - double SpriteVis(double screenZ) const { return SpriteGlobVis() / screenZ; } - double ParticleVis(double screenZ) const { return ParticleGlobVis() / screenZ; } - double FlatPlaneVis(int screenY, double planeZ) const { return FlatPlaneGlobVis() / fabs(planeZ - ViewPos.Z) * fabs(RenderViewport::Instance()->CenterY - screenY); } + double WallVis(double screenZ, bool foggy) const { return WallGlobVis(foggy) / screenZ; } + double SpriteVis(double screenZ, bool foggy) const { return SpriteGlobVis(foggy) / screenZ; } + double ParticleVis(double screenZ, bool foggy) const { return ParticleGlobVis(foggy) / screenZ; } + double FlatPlaneVis(int screenY, double planeZ, bool foggy) const { return FlatPlaneGlobVis(foggy) / fabs(planeZ - ViewPos.Z) * fabs(RenderViewport::Instance()->CenterY - screenY); } private: double BaseVisibility = 0.0; @@ -101,6 +108,8 @@ namespace swrenderer double FloorVisibility = 0.0; float TiltVisibility = 0.0f; + bool NoLightFade = false; + double CurrentVisibility = 8.f; double MaxVisForWall = 0.0; double MaxVisForFloor = 0.0; diff --git a/src/swrenderer/scene/r_opaque_pass.cpp b/src/swrenderer/scene/r_opaque_pass.cpp index ac8505dd2..29063ed6f 100644 --- a/src/swrenderer/scene/r_opaque_pass.cpp +++ b/src/swrenderer/scene/r_opaque_pass.cpp @@ -717,7 +717,7 @@ namespace swrenderer // [RH] Add particles if ((unsigned int)(sub - subsectors) < (unsigned int)numsubsectors) { // Only do it for the main BSP. - int shade = LIGHT2SHADE((floorlightlevel + ceilinglightlevel) / 2 + R_ActualExtraLight(foggy)); + int shade = LIGHT2SHADE((floorlightlevel + ceilinglightlevel) / 2 + R_ActualExtraLight(foggy), foggy); for (WORD i = ParticlesInSubsec[(unsigned int)(sub - subsectors)]; i != NO_PARTICLE; i = Particles[i].snext) { RenderParticle::Project(Thread, Particles + i, subsectors[sub - subsectors].sector, shade, FakeSide, foggy); @@ -834,7 +834,7 @@ namespace swrenderer //sec->validcount = validcount; SeenSpriteSectors.insert(sec); - int spriteshade = LIGHT2SHADE(lightlevel + R_ActualExtraLight(foggy)); + int spriteshade = LIGHT2SHADE(lightlevel + R_ActualExtraLight(foggy), foggy); // Handle all things in sector. for (auto p = sec->touching_renderthings; p != nullptr; p = p->m_snext) @@ -886,7 +886,7 @@ namespace swrenderer if (sec->sectornum != thing->Sector->sectornum) // compare sectornums to account for R_FakeFlat copies. { int lightlevel = thing->Sector->GetTexture(sector_t::ceiling) == skyflatnum ? thing->Sector->GetCeilingLight() : thing->Sector->GetFloorLight(); - thingShade = LIGHT2SHADE(lightlevel + R_ActualExtraLight(foggy)); + thingShade = LIGHT2SHADE(lightlevel + R_ActualExtraLight(foggy), foggy); thingColormap = thing->Sector->ColorMap; } diff --git a/src/swrenderer/things/r_particle.cpp b/src/swrenderer/things/r_particle.cpp index 9212004e6..17656d69c 100644 --- a/src/swrenderer/things/r_particle.cpp +++ b/src/swrenderer/things/r_particle.cpp @@ -204,7 +204,7 @@ namespace swrenderer vis->floorclip = 0; vis->foggy = foggy; - vis->Light.SetColormap(tiz * LightVisibility::Instance()->ParticleGlobVis(), shade, map, particle->bright != 0, false, false); + vis->Light.SetColormap(tiz * LightVisibility::Instance()->ParticleGlobVis(foggy), shade, map, particle->bright != 0, false, false); thread->SpriteList->Push(vis); } diff --git a/src/swrenderer/things/r_playersprite.cpp b/src/swrenderer/things/r_playersprite.cpp index 929acab53..98243def9 100644 --- a/src/swrenderer/things/r_playersprite.cpp +++ b/src/swrenderer/things/r_playersprite.cpp @@ -131,7 +131,7 @@ namespace swrenderer // get light level lightnum = ((floorlight + ceilinglight) >> 1) + R_ActualExtraLight(foggy); - int spriteshade = LIGHT2SHADE(lightnum) - 24 * FRACUNIT; + int spriteshade = LIGHT2SHADE(lightnum, foggy) - 24 * FRACUNIT; if (camera->player != NULL) { diff --git a/src/swrenderer/things/r_sprite.cpp b/src/swrenderer/things/r_sprite.cpp index 2ebf1fd57..097929197 100644 --- a/src/swrenderer/things/r_sprite.cpp +++ b/src/swrenderer/things/r_sprite.cpp @@ -280,7 +280,7 @@ namespace swrenderer vis->dynlightcolor = 0; } - vis->Light.SetColormap(LightVisibility::Instance()->SpriteGlobVis() / MAX(tz, MINZ), spriteshade, basecolormap, fullbright, invertcolormap, fadeToBlack); + vis->Light.SetColormap(LightVisibility::Instance()->SpriteGlobVis(foggy) / MAX(tz, MINZ), spriteshade, basecolormap, fullbright, invertcolormap, fadeToBlack); thread->SpriteList->Push(vis); } diff --git a/src/swrenderer/things/r_visiblesprite.cpp b/src/swrenderer/things/r_visiblesprite.cpp index 1f402de81..6a0d9bc3f 100644 --- a/src/swrenderer/things/r_visiblesprite.cpp +++ b/src/swrenderer/things/r_visiblesprite.cpp @@ -138,9 +138,9 @@ namespace swrenderer bool isFullBright = !foggy && (renderflags & RF_FULLBRIGHT); bool fadeToBlack = spr->RenderStyle == LegacyRenderStyles[STYLE_Add] && mybasecolormap->Fade != 0; - int spriteshade = LIGHT2SHADE(sec->lightlevel + R_ActualExtraLight(spr->foggy)); + int spriteshade = LIGHT2SHADE(sec->lightlevel + R_ActualExtraLight(spr->foggy), foggy); - Light.SetColormap(LightVisibility::Instance()->SpriteGlobVis() / MAX(MINZ, (double)spr->depth), spriteshade, mybasecolormap, isFullBright, invertcolormap, fadeToBlack); + Light.SetColormap(LightVisibility::Instance()->SpriteGlobVis(foggy) / MAX(MINZ, (double)spr->depth), spriteshade, mybasecolormap, isFullBright, invertcolormap, fadeToBlack); } } diff --git a/src/swrenderer/things/r_voxel.cpp b/src/swrenderer/things/r_voxel.cpp index 33e889c3f..b337cd857 100644 --- a/src/swrenderer/things/r_voxel.cpp +++ b/src/swrenderer/things/r_voxel.cpp @@ -178,7 +178,7 @@ namespace swrenderer bool fullbright = !vis->foggy && ((renderflags & RF_FULLBRIGHT) || (thing->flags5 & MF5_BRIGHT)); bool fadeToBlack = (vis->RenderStyle.Flags & STYLEF_FadeToBlack) != 0; - vis->Light.SetColormap(LightVisibility::Instance()->SpriteGlobVis() / MAX(tz, MINZ), spriteshade, basecolormap, fullbright, invertcolormap, fadeToBlack); + vis->Light.SetColormap(LightVisibility::Instance()->SpriteGlobVis(foggy) / MAX(tz, MINZ), spriteshade, basecolormap, fullbright, invertcolormap, fadeToBlack); thread->SpriteList->Push(vis, true); } diff --git a/src/swrenderer/things/r_wallsprite.cpp b/src/swrenderer/things/r_wallsprite.cpp index 38a26aab1..6db6c746d 100644 --- a/src/swrenderer/things/r_wallsprite.cpp +++ b/src/swrenderer/things/r_wallsprite.cpp @@ -133,7 +133,7 @@ namespace swrenderer vis->wallc = wallc; vis->foggy = foggy; - vis->Light.SetColormap(LightVisibility::Instance()->SpriteGlobVis() / MAX(tz, MINZ), spriteshade, basecolormap, false, false, false); + vis->Light.SetColormap(LightVisibility::Instance()->SpriteGlobVis(foggy) / MAX(tz, MINZ), spriteshade, basecolormap, false, false, false); thread->SpriteList->Push(vis); } @@ -182,8 +182,8 @@ namespace swrenderer SpriteDrawerArgs drawerargs; - int shade = LIGHT2SHADE(spr->sector->lightlevel + R_ActualExtraLight(spr->foggy)); - double GlobVis = LightVisibility::Instance()->WallGlobVis(); + int shade = LIGHT2SHADE(spr->sector->lightlevel + R_ActualExtraLight(spr->foggy), spr->foggy); + double GlobVis = LightVisibility::Instance()->WallGlobVis(foggy); float lightleft = float(GlobVis / spr->wallc.sz1); float lightstep = float((GlobVis / spr->wallc.sz2 - lightleft) / (spr->wallc.sx2 - spr->wallc.sx1)); float light = lightleft + (x1 - spr->wallc.sx1) * lightstep; diff --git a/src/win32/fb_d3d9.cpp b/src/win32/fb_d3d9.cpp index e0f79f51d..254725b26 100644 --- a/src/win32/fb_d3d9.cpp +++ b/src/win32/fb_d3d9.cpp @@ -3130,7 +3130,7 @@ void D3DFB::FillSimplePoly(FTexture *texture, FVector2 *points, int npoints, DAngle rotation, FDynamicColormap *colormap, PalEntry flatcolor, int lightlevel, int bottomclip) { // Use an equation similar to player sprites to determine shade - double fadelevel = clamp((LIGHT2SHADE(lightlevel)/65536. - 12) / NUMCOLORMAPS, 0.0, 1.0); + double fadelevel = clamp((swrenderer::LIGHT2SHADE(lightlevel, true)/65536. - 12) / NUMCOLORMAPS, 0.0, 1.0); BufferedTris *quad; FBVERTEX *verts;