From 7b58eab332b2877db0b92bb6ad2370f8b2d36490 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sun, 26 Mar 2017 05:28:27 +0200 Subject: [PATCH] - fix softpoly light visibility bug --- src/polyrenderer/drawers/poly_drawer32_sse2.h | 3 ++- src/polyrenderer/drawers/poly_drawer8.h | 3 ++- src/polyrenderer/scene/poly_decal.cpp | 4 ++-- src/polyrenderer/scene/poly_light.cpp | 6 ++++++ src/polyrenderer/scene/poly_light.h | 8 +++++--- src/polyrenderer/scene/poly_particle.cpp | 4 ++-- src/polyrenderer/scene/poly_plane.cpp | 8 ++++---- src/polyrenderer/scene/poly_scene.cpp | 2 +- src/polyrenderer/scene/poly_sky.cpp | 2 +- src/polyrenderer/scene/poly_sprite.cpp | 4 ++-- src/polyrenderer/scene/poly_wall.cpp | 2 +- src/polyrenderer/scene/poly_wallsprite.cpp | 4 ++-- 12 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/polyrenderer/drawers/poly_drawer32_sse2.h b/src/polyrenderer/drawers/poly_drawer32_sse2.h index c86d3bc93..0e7fe0b0e 100644 --- a/src/polyrenderer/drawers/poly_drawer32_sse2.h +++ b/src/polyrenderer/drawers/poly_drawer32_sse2.h @@ -108,8 +108,9 @@ public: // Light uint32_t light = args->uniforms->light; - float shade = (64.0f - (light * 255 / 256 + 12.0f) * 32.0f / 128.0f) / 32.0f; + float shade = 2.0f - (light + 12.0f) / 128.0f; float globVis = args->uniforms->globvis * (1.0f / 32.0f); + light += (light >> 7); // 255 -> 256 // Sampling stuff uint32_t color = args->uniforms->color; diff --git a/src/polyrenderer/drawers/poly_drawer8.h b/src/polyrenderer/drawers/poly_drawer8.h index 6535f4852..974a454ab 100644 --- a/src/polyrenderer/drawers/poly_drawer8.h +++ b/src/polyrenderer/drawers/poly_drawer8.h @@ -69,8 +69,9 @@ public: // Light uint32_t light = args->uniforms->light; - float shade = (64.0f - (light * 255 / 256 + 12.0f) * 32.0f / 128.0f) / 32.0f; + float shade = 2.0f - (light + 12.0f) / 128.0f; float globVis = args->uniforms->globvis * (1.0f / 32.0f); + light += light >> 7; // 255 -> 256 // Sampling stuff uint32_t color = args->uniforms->color; diff --git a/src/polyrenderer/scene/poly_decal.cpp b/src/polyrenderer/scene/poly_decal.cpp index 0759ac64d..21f7281d4 100644 --- a/src/polyrenderer/scene/poly_decal.cpp +++ b/src/polyrenderer/scene/poly_decal.cpp @@ -140,12 +140,12 @@ void RenderPolyDecal::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy); if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap()) { - args.uniforms.light = 256; + args.uniforms.light = 255; args.uniforms.flags |= TriUniforms::fixed_light; } else { - args.uniforms.light = (uint32_t)((front->lightlevel + actualextralight) / 255.0f * 256.0f); + args.uniforms.light = front->lightlevel + actualextralight; } args.uniforms.subsectorDepth = subsectorDepth; diff --git a/src/polyrenderer/scene/poly_light.cpp b/src/polyrenderer/scene/poly_light.cpp index 5de6756d7..92c74e469 100644 --- a/src/polyrenderer/scene/poly_light.cpp +++ b/src/polyrenderer/scene/poly_light.cpp @@ -25,6 +25,7 @@ #include "doomdef.h" #include "sbar.h" #include "poly_light.h" +#include "polyrenderer/poly_renderer.h" fixed_t PolyLightVisibility::LightLevelToShade(int lightlevel, bool foggy) { @@ -41,3 +42,8 @@ fixed_t PolyLightVisibility::LightLevelToShade(int lightlevel, bool foggy) return (NUMCOLORMAPS * 2 * FRACUNIT) - ((lightlevel + 12) * (FRACUNIT*NUMCOLORMAPS / 128)); } } + +double PolyLightVisibility::FocalTangent() +{ + return PolyRenderer::Instance()->Viewwindow.FocalTangent; +} diff --git a/src/polyrenderer/scene/poly_light.h b/src/polyrenderer/scene/poly_light.h index 9644387e7..dcb397cb8 100644 --- a/src/polyrenderer/scene/poly_light.h +++ b/src/polyrenderer/scene/poly_light.h @@ -31,9 +31,9 @@ typedef swrenderer::CameraLight PolyCameraLight; class PolyLightVisibility { public: - 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 WallGlobVis(bool foggy) const { return (NoLightFade && !foggy) ? 0.0 : WallVisibility / FocalTangent(); } + double SpriteGlobVis(bool foggy) const { return (NoLightFade && !foggy) ? 0.0 : WallVisibility / FocalTangent(); } + double ParticleGlobVis(bool foggy) const { return (NoLightFade && !foggy) ? 0.0 : WallVisibility * 0.5 / FocalTangent(); } // The vis value to pass into the GETPALOOKUP or LIGHTSCALE macros double WallVis(double screenZ, bool foggy) const { return WallGlobVis(foggy) / screenZ; } @@ -43,6 +43,8 @@ public: static fixed_t LightLevelToShade(int lightlevel, bool foggy); private: + static double FocalTangent(); + // 1706 is the value for walls on 1080p 16:9 displays. double WallVisibility = 1706.0; bool NoLightFade = false; diff --git a/src/polyrenderer/scene/poly_particle.cpp b/src/polyrenderer/scene/poly_particle.cpp index 8d09be467..37f978308 100644 --- a/src/polyrenderer/scene/poly_particle.cpp +++ b/src/polyrenderer/scene/poly_particle.cpp @@ -78,12 +78,12 @@ void RenderPolyParticle::Render(const TriMatrix &worldToClip, const Vec4f &clipP if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap()) { - args.uniforms.light = 256; + args.uniforms.light = 255; args.uniforms.flags = TriUniforms::fixed_light | TriUniforms::nearest_filter; } else { - args.uniforms.light = (uint32_t)((sub->sector->lightlevel + actualextralight) / 255.0f * 256.0f); + args.uniforms.light = sub->sector->lightlevel + actualextralight; args.uniforms.flags = TriUniforms::nearest_filter; } args.uniforms.subsectorDepth = subsectorDepth; diff --git a/src/polyrenderer/scene/poly_plane.cpp b/src/polyrenderer/scene/poly_plane.cpp index 03ea75b37..4b616910d 100644 --- a/src/polyrenderer/scene/poly_plane.cpp +++ b/src/polyrenderer/scene/poly_plane.cpp @@ -113,9 +113,9 @@ void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, const Vec4f &c PolyDrawArgs args; args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy); // .SlopePlaneGlobVis(foggy) * 48.0f; - args.uniforms.light = (uint32_t)(lightlevel / 255.0f * 256.0f); + args.uniforms.light = lightlevel; if (cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap()) - args.uniforms.light = 256; + args.uniforms.light = 255; args.uniforms.flags = TriUniforms::nearest_filter; args.uniforms.subsectorDepth = subsectorDepth; @@ -295,9 +295,9 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan PolyDrawArgs args; args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy);// ->SlopePlaneGlobVis(foggy) * 48.0f; - args.uniforms.light = (uint32_t)(frontsector->lightlevel / 255.0f * 256.0f); + args.uniforms.light = frontsector->lightlevel; if (cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap()) - args.uniforms.light = 256; + args.uniforms.light = 255; args.uniforms.flags = TriUniforms::nearest_filter; args.uniforms.subsectorDepth = isSky ? RenderPolyScene::SkySubsectorDepth : subsectorDepth; diff --git a/src/polyrenderer/scene/poly_scene.cpp b/src/polyrenderer/scene/poly_scene.cpp index f3a0b2887..79f7631cf 100644 --- a/src/polyrenderer/scene/poly_scene.cpp +++ b/src/polyrenderer/scene/poly_scene.cpp @@ -253,7 +253,7 @@ void RenderPolyScene::RenderPortals(int portalDepth) args.mode = TriangleDrawMode::Fan; args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy); args.uniforms.color = 0; - args.uniforms.light = 256; + args.uniforms.light = 255; args.uniforms.flags = TriUniforms::fixed_light; args.SetClipPlane(PortalPlane.x, PortalPlane.y, PortalPlane.z, PortalPlane.w); diff --git a/src/polyrenderer/scene/poly_sky.cpp b/src/polyrenderer/scene/poly_sky.cpp index 3be38e481..b30ba69a8 100644 --- a/src/polyrenderer/scene/poly_sky.cpp +++ b/src/polyrenderer/scene/poly_sky.cpp @@ -58,7 +58,7 @@ void PolySkyDome::Render(const TriMatrix &worldToClip) PolyDrawArgs args; args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy); - args.uniforms.light = 256; + args.uniforms.light = 255; args.uniforms.flags = TriUniforms::nearest_filter; args.uniforms.subsectorDepth = RenderPolyScene::SkySubsectorDepth; args.objectToClip = &objectToClip; diff --git a/src/polyrenderer/scene/poly_sprite.cpp b/src/polyrenderer/scene/poly_sprite.cpp index 6e3c8c86c..a2ead5d76 100644 --- a/src/polyrenderer/scene/poly_sprite.cpp +++ b/src/polyrenderer/scene/poly_sprite.cpp @@ -143,12 +143,12 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, const Vec4f &clipPla args.uniforms.flags = TriUniforms::nearest_filter; if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap()) { - args.uniforms.light = 256; + args.uniforms.light = 255; args.uniforms.flags |= TriUniforms::fixed_light; } else { - args.uniforms.light = (uint32_t)((thing->Sector->lightlevel + actualextralight) / 255.0f * 256.0f); + args.uniforms.light = thing->Sector->lightlevel + actualextralight; } args.uniforms.subsectorDepth = subsectorDepth; diff --git a/src/polyrenderer/scene/poly_wall.cpp b/src/polyrenderer/scene/poly_wall.cpp index abbfd15f8..96b3ecc62 100644 --- a/src/polyrenderer/scene/poly_wall.cpp +++ b/src/polyrenderer/scene/poly_wall.cpp @@ -249,7 +249,7 @@ void RenderPolyWall::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane PolyDrawArgs args; args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy); - args.uniforms.light = (uint32_t)(GetLightLevel() / 255.0f * 256.0f); + args.uniforms.light = GetLightLevel(); args.uniforms.flags = TriUniforms::nearest_filter; args.uniforms.subsectorDepth = SubsectorDepth; args.objectToClip = &worldToClip; diff --git a/src/polyrenderer/scene/poly_wallsprite.cpp b/src/polyrenderer/scene/poly_wallsprite.cpp index 75227c255..509a5e8da 100644 --- a/src/polyrenderer/scene/poly_wallsprite.cpp +++ b/src/polyrenderer/scene/poly_wallsprite.cpp @@ -103,12 +103,12 @@ void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, const Vec4f &cli args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy); if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap()) { - args.uniforms.light = 256; + args.uniforms.light = 255; args.uniforms.flags = TriUniforms::fixed_light | TriUniforms::nearest_filter; } else { - args.uniforms.light = (uint32_t)((thing->Sector->lightlevel + actualextralight) / 255.0f * 256.0f); + args.uniforms.light = thing->Sector->lightlevel + actualextralight; args.uniforms.flags = TriUniforms::nearest_filter; } args.uniforms.subsectorDepth = subsectorDepth;