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)
This commit is contained in:
@@ -55,6 +55,7 @@ namespace Barotrauma.Lights
|
|||||||
private int primitiveCount;
|
private int primitiveCount;
|
||||||
|
|
||||||
private bool[] backFacing;
|
private bool[] backFacing;
|
||||||
|
private bool[] ignoreEdge;
|
||||||
|
|
||||||
private VertexPositionColor[] shadowVertices;
|
private VertexPositionColor[] shadowVertices;
|
||||||
private VertexPositionTexture[] penumbraVertices;
|
private VertexPositionTexture[] penumbraVertices;
|
||||||
@@ -111,10 +112,37 @@ namespace Barotrauma.Lights
|
|||||||
//CalculateDimensions();
|
//CalculateDimensions();
|
||||||
|
|
||||||
backFacing = new bool[primitiveCount];
|
backFacing = new bool[primitiveCount];
|
||||||
|
ignoreEdge = new bool[primitiveCount];
|
||||||
|
|
||||||
Enabled = true;
|
Enabled = true;
|
||||||
|
|
||||||
|
foreach (ConvexHull ch in list)
|
||||||
|
{
|
||||||
|
UpdateIgnoredEdges(ch);
|
||||||
|
ch.UpdateIgnoredEdges(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
list.Add(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()
|
private void CalculateDimensions()
|
||||||
@@ -199,8 +227,8 @@ namespace Barotrauma.Lights
|
|||||||
|
|
||||||
public bool Intersects(Rectangle rect)
|
public bool Intersects(Rectangle rect)
|
||||||
{
|
{
|
||||||
if (!Enabled)
|
if (!Enabled) return false;
|
||||||
return false;
|
|
||||||
Rectangle transformedBounds = boundingBox;
|
Rectangle transformedBounds = boundingBox;
|
||||||
if (parentEntity != null && parentEntity.Submarine != null)
|
if (parentEntity != null && parentEntity.Submarine != null)
|
||||||
{
|
{
|
||||||
@@ -219,6 +247,12 @@ namespace Barotrauma.Lights
|
|||||||
//compute facing of each edge, using N*L
|
//compute facing of each edge, using N*L
|
||||||
for (int i = 0; i < primitiveCount; i++)
|
for (int i = 0; i < primitiveCount; i++)
|
||||||
{
|
{
|
||||||
|
if (ignoreEdge[i])
|
||||||
|
{
|
||||||
|
backFacing[i] = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
Vector2 firstVertex = new Vector2(vertices[i].X, vertices[i].Y);
|
Vector2 firstVertex = new Vector2(vertices[i].X, vertices[i].Y);
|
||||||
int secondIndex = (i + 1) % primitiveCount;
|
int secondIndex = (i + 1) % primitiveCount;
|
||||||
Vector2 secondVertex = new Vector2(vertices[secondIndex].X, vertices[secondIndex].Y);
|
Vector2 secondVertex = new Vector2(vertices[secondIndex].X, vertices[secondIndex].Y);
|
||||||
|
|||||||
@@ -257,6 +257,13 @@ namespace Barotrauma
|
|||||||
var mergedSections = new List<WallSection>();
|
var mergedSections = new List<WallSection>();
|
||||||
foreach (var section in sections)
|
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 there is a gap and we have sections to merge, do it.
|
||||||
if (section.gap != null)
|
if (section.gap != null)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user