From a092a03c6dce483c67900310effdd622b8f19e80 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Tue, 15 Nov 2016 23:30:42 +0100 Subject: [PATCH] Some basic fixed light support --- .../fixedfunction/drawtrianglecodegen.cpp | 6 ++++-- src/r_compiler/fixedfunction/drawtrianglecodegen.h | 3 ++- src/r_compiler/llvmdrawers.h | 2 +- src/r_poly_plane.cpp | 4 +--- src/r_poly_sprite.cpp | 14 ++++++++++++-- src/r_poly_wall.cpp | 2 +- 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/r_compiler/fixedfunction/drawtrianglecodegen.cpp b/src/r_compiler/fixedfunction/drawtrianglecodegen.cpp index 77076b072..11bdad7e4 100644 --- a/src/r_compiler/fixedfunction/drawtrianglecodegen.cpp +++ b/src/r_compiler/fixedfunction/drawtrianglecodegen.cpp @@ -254,7 +254,8 @@ void DrawTriangleCodegen::LoopBlockX(TriDrawVariant variant, bool truecolor) SSAFloat vis = globVis / rcpWTL; SSAFloat shade = 64.0f - (SSAFloat(light * 255 / 256) + 12.0f) * 32.0f / 128.0f; SSAFloat lightscale = SSAFloat::clamp((shade - SSAFloat::MIN(SSAFloat(24.0f), vis)) / 32.0f, SSAFloat(0.0f), SSAFloat(31.0f / 32.0f)); - diminishedlight = SSAInt(SSAFloat::clamp((1.0f - lightscale) * 256.0f + 0.5f, SSAFloat(0.0f), SSAFloat(256.0f)), false); + SSAInt diminishedlight = SSAInt(SSAFloat::clamp((1.0f - lightscale) * 256.0f + 0.5f, SSAFloat(0.0f), SSAFloat(256.0f)), false); + currentlight = is_fixed_light.select(light, diminishedlight); SetStencilBlock(x / 8 + y / 8 * stencilPitch); @@ -473,7 +474,7 @@ void DrawTriangleCodegen::ProcessPixel(SSAUBytePtr buffer, SSAIntPtr subsectorbu { SSAVec4i fg = texturePixels[uvoffset * 4].load_vec4ub(true); SSAInt fg_alpha = fg[3]; - fg = (fg * diminishedlight) >> 8; + fg = (fg * currentlight) >> 8; fg.insert(3, fg_alpha); if (variant == TriDrawVariant::DrawMasked || variant == TriDrawVariant::DrawSubsector) @@ -625,4 +626,5 @@ void DrawTriangleCodegen::LoadUniforms(SSAValue uniforms) is_simple_shade = (flags & TriUniforms::simple_shade) == SSAInt(TriUniforms::simple_shade); is_nearest_filter = (flags & TriUniforms::nearest_filter) == SSAInt(TriUniforms::nearest_filter); + is_fixed_light = (flags & TriUniforms::fixed_light) == SSAInt(TriUniforms::fixed_light); } diff --git a/src/r_compiler/fixedfunction/drawtrianglecodegen.h b/src/r_compiler/fixedfunction/drawtrianglecodegen.h index c9fb61e67..8452b250f 100644 --- a/src/r_compiler/fixedfunction/drawtrianglecodegen.h +++ b/src/r_compiler/fixedfunction/drawtrianglecodegen.h @@ -89,6 +89,7 @@ private: SSAShadeConstants shade_constants; SSABool is_simple_shade; SSABool is_nearest_filter; + SSABool is_fixed_light; SSAUBytePtr stencilValues; SSAIntPtr stencilMasks; @@ -115,7 +116,7 @@ private: SSAInt x, y; SSAInt x0, x1, y0, y1; - SSAInt diminishedlight; + SSAInt currentlight; SSAInt varyingPos[TriVertex::NumVarying]; SSAInt varyingStepPos[TriVertex::NumVarying]; SSAInt varyingStartStepX[TriVertex::NumVarying]; diff --git a/src/r_compiler/llvmdrawers.h b/src/r_compiler/llvmdrawers.h index b68c23fe1..38f0f82d1 100644 --- a/src/r_compiler/llvmdrawers.h +++ b/src/r_compiler/llvmdrawers.h @@ -230,7 +230,7 @@ struct TriUniforms { simple_shade = 1, nearest_filter = 2, - diminishing_lighting = 4 + fixed_light = 4 }; TriMatrix objectToClip; diff --git a/src/r_poly_plane.cpp b/src/r_poly_plane.cpp index 3052ebfbc..4ca6f4990 100644 --- a/src/r_poly_plane.cpp +++ b/src/r_poly_plane.cpp @@ -82,9 +82,7 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, subsector_t *sub, uin TriUniforms uniforms; uniforms.objectToClip = worldToClip; uniforms.light = (uint32_t)(frontsector->lightlevel / 255.0f * 256.0f); - if (fixedlightlev >= 0) - uniforms.light = (uint32_t)(fixedlightlev / 255.0f * 256.0f); - else if (fixedcolormap) + if (fixedlightlev >= 0 || fixedcolormap) uniforms.light = 256; uniforms.flags = 0; uniforms.subsectorDepth = isSky ? RenderPolyScene::SkySubsectorDepth : subsectorDepth; diff --git a/src/r_poly_sprite.cpp b/src/r_poly_sprite.cpp index b3a57ec47..1701b24ef 100644 --- a/src/r_poly_sprite.cpp +++ b/src/r_poly_sprite.cpp @@ -111,10 +111,20 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, AActor *thing, subse vertices[i].varying[0] = 1.0f - vertices[i].varying[0]; } + bool fullbrightSprite = ((thing->renderflags & RF_FULLBRIGHT) || (thing->flags5 & MF5_BRIGHT)); + TriUniforms uniforms; uniforms.objectToClip = worldToClip; - uniforms.light = (uint32_t)((thing->Sector->lightlevel + actualextralight) / 255.0f * 256.0f); - uniforms.flags = 0; + if (fullbrightSprite || fixedlightlev >= 0 || fixedcolormap) + { + uniforms.light = 256; + uniforms.flags = TriUniforms::fixed_light; + } + else + { + uniforms.light = (uint32_t)((thing->Sector->lightlevel + actualextralight) / 255.0f * 256.0f); + uniforms.flags = 0; + } uniforms.subsectorDepth = subsectorDepth; PolyDrawArgs args; diff --git a/src/r_poly_wall.cpp b/src/r_poly_wall.cpp index aeb6985da..cd932214d 100644 --- a/src/r_poly_wall.cpp +++ b/src/r_poly_wall.cpp @@ -244,7 +244,7 @@ int RenderPolyWall::GetLightLevel() { bool foggy = false; int actualextralight = foggy ? 0 : extralight << 4; - return Line->sidedef->GetLightLevel(foggy, Line->frontsector->lightlevel) + actualextralight; + return clamp(Line->sidedef->GetLightLevel(foggy, Line->frontsector->lightlevel) + actualextralight, 0, 255); } }