Use AABB for a tighter cull of cell light indices

This commit is contained in:
Jarrod Doyle 2024-11-29 17:24:03 +00:00
parent b3a71e6827
commit 84c54ce280
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 6 additions and 4 deletions

View File

@ -354,12 +354,14 @@ public class LightMapper
// The OG lightmapper uses the cell traversal to work out all the cells that // The OG lightmapper uses the cell traversal to work out all the cells that
// are actually visited. We're a lot more coarse and just say if a cell is // are actually visited. We're a lot more coarse and just say if a cell is
// in range then we potentially affect the lighting in the cell and add it // in range then we potentially affect the lighting in the cell and add it
// to the list. Cells already contain their sphere bounds so we just use // to the list.
// that for now, but a tighter AABB is another option. // There's a soft length limit here of 96 due to the runtime object shadow
var cellSphere = new MathUtils.Sphere(cell.SphereCenter, cell.SphereRadius); // cache, so we want this to be as minimal as possible. Additionally large
// lists actually cause performance issues!
var cellAabb = new MathUtils.Aabb(cell.Vertices);
foreach (var light in _lights) foreach (var light in _lights)
{ {
if (MathUtils.Intersects(cellSphere, new MathUtils.Sphere(light.Position, light.Radius))) if (MathUtils.Intersects(new MathUtils.Sphere(light.Position, light.Radius), cellAabb))
{ {
cell.LightIndexCount++; cell.LightIndexCount++;
cell.LightIndices.Add((ushort)light.LightTableIndex); cell.LightIndices.Add((ushort)light.LightTableIndex);