Fixed horizontal split shadow casters breaking everything

This commit is contained in:
juanjp600
2018-01-23 22:43:25 -03:00
parent c47d428be2
commit 2acaee3c6d
@@ -312,7 +312,7 @@ namespace Barotrauma.Lights
hulls.AddRange(chList.List); hulls.AddRange(chList.List);
} }
float bounds = range*2; float bounds = range * 2;
//find convexhull segments that are close enough and facing towards the light source //find convexhull segments that are close enough and facing towards the light source
List<Segment> visibleSegments = new List<Segment>(); List<Segment> visibleSegments = new List<Segment>();
List<SegmentPoint> points = new List<SegmentPoint>(); List<SegmentPoint> points = new List<SegmentPoint>();
@@ -328,26 +328,24 @@ namespace Barotrauma.Lights
//This is necessary for the light volume to generate properly on some subs //This is necessary for the light volume to generate properly on some subs
for (int i = 0; i < visibleSegments.Count; i++) for (int i = 0; i < visibleSegments.Count; i++)
{ {
Vector2 p1a = visibleSegments[i].Start.WorldPos;
Vector2 p1b = visibleSegments[i].End.WorldPos;
for (int j = 0; j < visibleSegments.Count; j++) for (int j = 0; j < visibleSegments.Count; j++)
{ {
if (j == i) continue; if (j == i) continue;
Vector2 p1a = visibleSegments[i].Start.WorldPos;
Vector2 p1b = visibleSegments[i].End.WorldPos;
Vector2 p2a = visibleSegments[j].Start.WorldPos; Vector2 p2a = visibleSegments[j].Start.WorldPos;
Vector2 p2b = visibleSegments[j].End.WorldPos; Vector2 p2b = visibleSegments[j].End.WorldPos;
if (Vector2.DistanceSquared(p1a, p2a) < 5.0f || if (Vector2.DistanceSquared(p1a, p2a) < 25.0f ||
Vector2.DistanceSquared(p1a, p2b) < 5.0f || Vector2.DistanceSquared(p1a, p2b) < 25.0f ||
Vector2.DistanceSquared(p1b, p2a) < 5.0f || Vector2.DistanceSquared(p1b, p2a) < 25.0f ||
Vector2.DistanceSquared(p1b, p2b) < 5.0f) Vector2.DistanceSquared(p1b, p2b) < 25.0f)
{ {
continue; continue;
} }
Vector2? intersection = MathUtils.GetLineIntersection(visibleSegments[i].Start.WorldPos, Vector2? intersection = MathUtils.GetLineIntersection(p1a, p1b, p2a, p2b);
visibleSegments[i].End.WorldPos,
visibleSegments[j].Start.WorldPos,
visibleSegments[j].End.WorldPos);
if (intersection != null) if (intersection != null)
{ {
@@ -357,14 +355,16 @@ namespace Barotrauma.Lights
SegmentPoint end = visibleSegments[i].End; SegmentPoint end = visibleSegments[i].End;
SegmentPoint mid = new SegmentPoint(intersectionVal); SegmentPoint mid = new SegmentPoint(intersectionVal);
if (Vector2.DistanceSquared(start.WorldPos, mid.WorldPos) < 5.0f || if (Vector2.DistanceSquared(start.WorldPos, mid.WorldPos) < 25.0f ||
Vector2.DistanceSquared(end.WorldPos, mid.WorldPos) < 5.0f) Vector2.DistanceSquared(end.WorldPos, mid.WorldPos) < 25.0f)
{ {
continue; continue;
} }
visibleSegments[i] = new Segment(start, mid); Segment seg1 = new Segment(start, mid); seg1.IsHorizontal = visibleSegments[i].IsHorizontal;
visibleSegments.Insert(i + 1, new Segment(mid, end)); Segment seg2 = new Segment(mid, end); seg2.IsHorizontal = visibleSegments[i].IsHorizontal;
visibleSegments[i] = seg1;
visibleSegments.Insert(i+1,seg2);
i--; i--;
break; break;
} }