From 1a116574b986c06860daacb2fb2d3bfe41ef33ac Mon Sep 17 00:00:00 2001
From: biwa <6475593+biwa@users.noreply.github.com>
Date: Sat, 12 Aug 2023 11:15:13 +0200
Subject: [PATCH] Visual Mode: fixed a problem where things directly touching
 the top of 3D floors were rendered with the incorrect brightness. Fixes #940

---
 .../BuilderModes/VisualModes/BaseVisualThing.cs        | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs
index bc8ad645..42577fbf 100755
--- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs
+++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs
@@ -217,10 +217,16 @@ namespace CodeImp.DoomBuilder.BuilderModes
 				if(!info.Bright)
 				{
 					Vector3D thingpos = new Vector3D(Thing.Position.x, Thing.Position.y, Thing.Position.z + sd.Floor.plane.GetZ(Thing.Position));
-					SectorLevel level = sd.GetLevelAboveOrAt(thingpos);
+
+					// If is thing's height is flush to a 3D floor top it's not rendered at the brightness of the 3D floor, so take the level above that.
+					// It's actually a bit more intricate, since GZDoom can render multiple vertical brightness levels for each thing, which UDB can't,
+					// so this is more of a workaround than a real solution
+					// See https://github.com/jewalky/UltimateDoomBuilder/issues/940
+					//SectorLevel level = sd.GetLevelAboveOrAt(thingpos);
+					SectorLevel level = sd.GetLevelAbove(thingpos);
 
 					//mxd. Let's use point on floor plane instead of Thing.Sector.FloorHeight;
-					if(nointeraction && level == null && sd.LightLevels.Count > 0) level = sd.LightLevels[sd.LightLevels.Count - 1];
+					if (nointeraction && level == null && sd.LightLevels.Count > 0) level = sd.LightLevels[sd.LightLevels.Count - 1];
 
 					//mxd. Use the light level of the highest surface when a thing is above highest sector level.
 					if(level != null)