From 50bee3da41a9d4e30f1a65915d958590729e3bd5 Mon Sep 17 00:00:00 2001 From: Regalis Date: Wed, 1 Jun 2016 20:58:03 +0300 Subject: [PATCH] Wall convexhulls are split every 5 sections, convexhull edges that overlap with another convexhull are ignored (i.e. unneccessarys shadows aren't drawn where two walls meet) --- Subsurface/Source/Map/Lights/ConvexHull.cs | 40 ++++++++++++++++++++-- Subsurface/Source/Map/Structure.cs | 7 ++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/Subsurface/Source/Map/Lights/ConvexHull.cs b/Subsurface/Source/Map/Lights/ConvexHull.cs index be5443e8e..7453f2246 100644 --- a/Subsurface/Source/Map/Lights/ConvexHull.cs +++ b/Subsurface/Source/Map/Lights/ConvexHull.cs @@ -55,6 +55,7 @@ namespace Barotrauma.Lights private int primitiveCount; private bool[] backFacing; + private bool[] ignoreEdge; private VertexPositionColor[] shadowVertices; private VertexPositionTexture[] penumbraVertices; @@ -111,10 +112,37 @@ namespace Barotrauma.Lights //CalculateDimensions(); backFacing = new bool[primitiveCount]; - + ignoreEdge = new bool[primitiveCount]; + Enabled = true; + foreach (ConvexHull ch in list) + { + UpdateIgnoredEdges(ch); + ch.UpdateIgnoredEdges(this); + } + + list.Add(this); + + } + + private void UpdateIgnoredEdges(ConvexHull ch) + { + for (int i = 0; i < vertices.Length; i++) + { + if (vertices[i].X >= ch.boundingBox.X && vertices[i].X <= ch.boundingBox.Right && + vertices[i].Y >= ch.boundingBox.Y && vertices[i].Y <= ch.boundingBox.Bottom) + { + Vector2 p = vertices[(i + 1) % vertices.Length]; + + if (p.X >= ch.boundingBox.X && p.X <= ch.boundingBox.Right && + p.Y >= ch.boundingBox.Y && p.Y <= ch.boundingBox.Bottom) + { + ignoreEdge[i] = true; + } + } + } } private void CalculateDimensions() @@ -199,8 +227,8 @@ namespace Barotrauma.Lights public bool Intersects(Rectangle rect) { - if (!Enabled) - return false; + if (!Enabled) return false; + Rectangle transformedBounds = boundingBox; if (parentEntity != null && parentEntity.Submarine != null) { @@ -219,6 +247,12 @@ namespace Barotrauma.Lights //compute facing of each edge, using N*L for (int i = 0; i < primitiveCount; i++) { + if (ignoreEdge[i]) + { + backFacing[i] = false; + continue; + } + Vector2 firstVertex = new Vector2(vertices[i].X, vertices[i].Y); int secondIndex = (i + 1) % primitiveCount; Vector2 secondVertex = new Vector2(vertices[secondIndex].X, vertices[secondIndex].Y); diff --git a/Subsurface/Source/Map/Structure.cs b/Subsurface/Source/Map/Structure.cs index af87f2973..6298baf60 100644 --- a/Subsurface/Source/Map/Structure.cs +++ b/Subsurface/Source/Map/Structure.cs @@ -257,6 +257,13 @@ namespace Barotrauma var mergedSections = new List(); foreach (var section in sections) { + if (mergedSections.Count > 5) + { + mergedSections.Add(section); + GenerateMergedHull(mergedSections); + continue; + } + // if there is a gap and we have sections to merge, do it. if (section.gap != null) {