Early out on light vis max range

This commit is contained in:
Jarrod Doyle 2025-02-22 20:28:28 +00:00
parent 18abe30b03
commit 170ec83fb1
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
2 changed files with 12 additions and 7 deletions

View File

@ -536,10 +536,10 @@ public class LightMapper
var visibleSet = settings.FastPvs switch { var visibleSet = settings.FastPvs switch {
true => pvs.ComputeVisibilityFast(lightCellMap[i]), true => pvs.ComputeVisibilityFast(lightCellMap[i]),
false => pvs.ComputeVisibilityExact(_lights[i].Position, lightCellMap[i]) false => pvs.ComputeVisibilityExact(_lights[i].Position, lightCellMap[i], _lights[i].Radius)
}; };
// Log.Information("Light {i} sees {c} cells", i, visibleSet.Length); // Log.Information("Light {i} sees {c} cells", i, visibleSet.Count);
visibleCellMap[i] = visibleSet; visibleCellMap[i] = visibleSet;
}); });
@ -599,6 +599,7 @@ public class LightMapper
cell.LightIndices[0]++; cell.LightIndices[0]++;
} }
Log.Information("Cell {Id} sees ({Count}) lights.", i, cell.LightIndices[0]);
if (cell.LightIndexCount > 97) if (cell.LightIndexCount > 97)
{ {
Log.Warning("Cell {Id} sees too many lights ({Count})", i, cell.LightIndices[0]); Log.Warning("Cell {Id} sees too many lights ({Count})", i, cell.LightIndices[0]);

View File

@ -170,8 +170,7 @@ public class PotentiallyVisibleSet
return visibleCells; return visibleCells;
} }
// TODO: Max distance :) public HashSet<int> ComputeVisibilityExact(Vector3 pos, int cellIdx, float maxRange)
public HashSet<int> ComputeVisibilityExact(Vector3 pos, int cellIdx)
{ {
if (cellIdx >= _graph.Length) if (cellIdx >= _graph.Length)
{ {
@ -185,7 +184,7 @@ public class PotentiallyVisibleSet
foreach (var edgeIdx in _graph[cellIdx].EdgeIndices) foreach (var edgeIdx in _graph[cellIdx].EdgeIndices)
{ {
var edge = _edges[edgeIdx]; var edge = _edges[edgeIdx];
ComputeVisibilityExactRecursive(pos, visibleCells, visited, edge.Destination, edge.Poly); ComputeVisibilityExactRecursive(pos, maxRange, visibleCells, visited, edge.Destination, edge.Poly);
} }
return visibleCells; return visibleCells;
@ -193,6 +192,7 @@ public class PotentiallyVisibleSet
private void ComputeVisibilityExactRecursive( private void ComputeVisibilityExactRecursive(
Vector3 lightPos, Vector3 lightPos,
float maxRange,
HashSet<int> visibleCells, HashSet<int> visibleCells,
Stack<int> visited, Stack<int> visited,
int currentCellIdx, int currentCellIdx,
@ -222,8 +222,12 @@ public class PotentiallyVisibleSet
foreach (var targetEdgeIdx in _graph[currentCellIdx].EdgeIndices) foreach (var targetEdgeIdx in _graph[currentCellIdx].EdgeIndices)
{ {
// This only checks is there is a point on the plane in range.
// Could probably use poly center + radius to get an even better early out.
var targetEdge = _edges[targetEdgeIdx]; var targetEdge = _edges[targetEdgeIdx];
if (visited.Contains(targetEdge.Destination) || passPoly.IsCoplanar(targetEdge.Poly)) if (visited.Contains(targetEdge.Destination) ||
passPoly.IsCoplanar(targetEdge.Poly) ||
Math.Abs(MathUtils.DistanceFromNormalizedPlane(targetEdge.Poly.Plane, lightPos)) > maxRange)
{ {
continue; continue;
} }
@ -239,7 +243,7 @@ public class PotentiallyVisibleSet
continue; continue;
} }
ComputeVisibilityExactRecursive(lightPos, visibleCells, visited, targetEdge.Destination, poly); ComputeVisibilityExactRecursive(lightPos, maxRange, visibleCells, visited, targetEdge.Destination, poly);
} }
visited.Pop(); visited.Pop();