- fix softpoly light visibility bug

This commit is contained in:
Magnus Norddahl 2017-03-26 05:28:27 +02:00
parent 3e67a8bafa
commit 7b58eab332
12 changed files with 30 additions and 20 deletions

View file

@ -108,8 +108,9 @@ public:
// Light // Light
uint32_t light = args->uniforms->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); float globVis = args->uniforms->globvis * (1.0f / 32.0f);
light += (light >> 7); // 255 -> 256
// Sampling stuff // Sampling stuff
uint32_t color = args->uniforms->color; uint32_t color = args->uniforms->color;

View file

@ -69,8 +69,9 @@ public:
// Light // Light
uint32_t light = args->uniforms->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); float globVis = args->uniforms->globvis * (1.0f / 32.0f);
light += light >> 7; // 255 -> 256
// Sampling stuff // Sampling stuff
uint32_t color = args->uniforms->color; uint32_t color = args->uniforms->color;

View file

@ -140,12 +140,12 @@ void RenderPolyDecal::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan
args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy); args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy);
if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap()) if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap())
{ {
args.uniforms.light = 256; args.uniforms.light = 255;
args.uniforms.flags |= TriUniforms::fixed_light; args.uniforms.flags |= TriUniforms::fixed_light;
} }
else else
{ {
args.uniforms.light = (uint32_t)((front->lightlevel + actualextralight) / 255.0f * 256.0f); args.uniforms.light = front->lightlevel + actualextralight;
} }
args.uniforms.subsectorDepth = subsectorDepth; args.uniforms.subsectorDepth = subsectorDepth;

View file

@ -25,6 +25,7 @@
#include "doomdef.h" #include "doomdef.h"
#include "sbar.h" #include "sbar.h"
#include "poly_light.h" #include "poly_light.h"
#include "polyrenderer/poly_renderer.h"
fixed_t PolyLightVisibility::LightLevelToShade(int lightlevel, bool foggy) 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)); return (NUMCOLORMAPS * 2 * FRACUNIT) - ((lightlevel + 12) * (FRACUNIT*NUMCOLORMAPS / 128));
} }
} }
double PolyLightVisibility::FocalTangent()
{
return PolyRenderer::Instance()->Viewwindow.FocalTangent;
}

View file

@ -31,9 +31,9 @@ typedef swrenderer::CameraLight PolyCameraLight;
class PolyLightVisibility class PolyLightVisibility
{ {
public: public:
double WallGlobVis(bool foggy) const { return (NoLightFade && !foggy) ? 0.0f : WallVisibility; } double WallGlobVis(bool foggy) const { return (NoLightFade && !foggy) ? 0.0 : WallVisibility / FocalTangent(); }
double SpriteGlobVis(bool foggy) const { return (NoLightFade && !foggy) ? 0.0f : WallVisibility; } double SpriteGlobVis(bool foggy) const { return (NoLightFade && !foggy) ? 0.0 : WallVisibility / FocalTangent(); }
double ParticleGlobVis(bool foggy) const { return (NoLightFade && !foggy) ? 0.0f : (WallVisibility * 0.5); } 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 // The vis value to pass into the GETPALOOKUP or LIGHTSCALE macros
double WallVis(double screenZ, bool foggy) const { return WallGlobVis(foggy) / screenZ; } double WallVis(double screenZ, bool foggy) const { return WallGlobVis(foggy) / screenZ; }
@ -43,6 +43,8 @@ public:
static fixed_t LightLevelToShade(int lightlevel, bool foggy); static fixed_t LightLevelToShade(int lightlevel, bool foggy);
private: private:
static double FocalTangent();
// 1706 is the value for walls on 1080p 16:9 displays. // 1706 is the value for walls on 1080p 16:9 displays.
double WallVisibility = 1706.0; double WallVisibility = 1706.0;
bool NoLightFade = false; bool NoLightFade = false;

View file

@ -78,12 +78,12 @@ void RenderPolyParticle::Render(const TriMatrix &worldToClip, const Vec4f &clipP
if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap()) if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap())
{ {
args.uniforms.light = 256; args.uniforms.light = 255;
args.uniforms.flags = TriUniforms::fixed_light | TriUniforms::nearest_filter; args.uniforms.flags = TriUniforms::fixed_light | TriUniforms::nearest_filter;
} }
else 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.flags = TriUniforms::nearest_filter;
} }
args.uniforms.subsectorDepth = subsectorDepth; args.uniforms.subsectorDepth = subsectorDepth;

View file

@ -113,9 +113,9 @@ void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, const Vec4f &c
PolyDrawArgs args; PolyDrawArgs args;
args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy); // .SlopePlaneGlobVis(foggy) * 48.0f; 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()) if (cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap())
args.uniforms.light = 256; args.uniforms.light = 255;
args.uniforms.flags = TriUniforms::nearest_filter; args.uniforms.flags = TriUniforms::nearest_filter;
args.uniforms.subsectorDepth = subsectorDepth; args.uniforms.subsectorDepth = subsectorDepth;
@ -295,9 +295,9 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan
PolyDrawArgs args; PolyDrawArgs args;
args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy);// ->SlopePlaneGlobVis(foggy) * 48.0f; 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()) if (cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap())
args.uniforms.light = 256; args.uniforms.light = 255;
args.uniforms.flags = TriUniforms::nearest_filter; args.uniforms.flags = TriUniforms::nearest_filter;
args.uniforms.subsectorDepth = isSky ? RenderPolyScene::SkySubsectorDepth : subsectorDepth; args.uniforms.subsectorDepth = isSky ? RenderPolyScene::SkySubsectorDepth : subsectorDepth;

View file

@ -253,7 +253,7 @@ void RenderPolyScene::RenderPortals(int portalDepth)
args.mode = TriangleDrawMode::Fan; args.mode = TriangleDrawMode::Fan;
args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy); args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy);
args.uniforms.color = 0; args.uniforms.color = 0;
args.uniforms.light = 256; args.uniforms.light = 255;
args.uniforms.flags = TriUniforms::fixed_light; args.uniforms.flags = TriUniforms::fixed_light;
args.SetClipPlane(PortalPlane.x, PortalPlane.y, PortalPlane.z, PortalPlane.w); args.SetClipPlane(PortalPlane.x, PortalPlane.y, PortalPlane.z, PortalPlane.w);

View file

@ -58,7 +58,7 @@ void PolySkyDome::Render(const TriMatrix &worldToClip)
PolyDrawArgs args; PolyDrawArgs args;
args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy); 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.flags = TriUniforms::nearest_filter;
args.uniforms.subsectorDepth = RenderPolyScene::SkySubsectorDepth; args.uniforms.subsectorDepth = RenderPolyScene::SkySubsectorDepth;
args.objectToClip = &objectToClip; args.objectToClip = &objectToClip;

View file

@ -143,12 +143,12 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, const Vec4f &clipPla
args.uniforms.flags = TriUniforms::nearest_filter; args.uniforms.flags = TriUniforms::nearest_filter;
if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap()) if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap())
{ {
args.uniforms.light = 256; args.uniforms.light = 255;
args.uniforms.flags |= TriUniforms::fixed_light; args.uniforms.flags |= TriUniforms::fixed_light;
} }
else 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; args.uniforms.subsectorDepth = subsectorDepth;

View file

@ -249,7 +249,7 @@ void RenderPolyWall::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane
PolyDrawArgs args; PolyDrawArgs args;
args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy); 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.flags = TriUniforms::nearest_filter;
args.uniforms.subsectorDepth = SubsectorDepth; args.uniforms.subsectorDepth = SubsectorDepth;
args.objectToClip = &worldToClip; args.objectToClip = &worldToClip;

View file

@ -103,12 +103,12 @@ void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, const Vec4f &cli
args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy); args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy);
if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap()) if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap())
{ {
args.uniforms.light = 256; args.uniforms.light = 255;
args.uniforms.flags = TriUniforms::fixed_light | TriUniforms::nearest_filter; args.uniforms.flags = TriUniforms::fixed_light | TriUniforms::nearest_filter;
} }
else 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.flags = TriUniforms::nearest_filter;
} }
args.uniforms.subsectorDepth = subsectorDepth; args.uniforms.subsectorDepth = subsectorDepth;