Compare commits

..

No commits in common. "e48393b856c58e0259b0ce302f1b04e9f8ab9200" and "392c7b24b59cd1e23bcdf2b063f92f2e0a0e258f" have entirely different histories.

3 changed files with 63 additions and 74 deletions

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<Version>0.5</Version> <Version>0.4.1</Version>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>

View File

@ -27,7 +27,6 @@ public class LightMapper
public bool LightmappedWater; public bool LightmappedWater;
public SunSettings Sunlight; public SunSettings Sunlight;
public uint AnimLightCutoff; public uint AnimLightCutoff;
public bool UsePvs;
} }
private ResourcePathManager.CampaignResources _campaign; private ResourcePathManager.CampaignResources _campaign;
@ -76,7 +75,7 @@ public class LightMapper
}); });
} }
public void Light(bool pvs) public void Light()
{ {
// TODO: Throw? // TODO: Throw?
if (!_mission.TryGetChunk<RendParams>("RENDPARAMS", out var rendParams) || if (!_mission.TryGetChunk<RendParams>("RENDPARAMS", out var rendParams) ||
@ -111,7 +110,6 @@ public class LightMapper
LightmappedWater = lmParams.LightmappedWater, LightmappedWater = lmParams.LightmappedWater,
Sunlight = sunlightSettings, Sunlight = sunlightSettings,
AnimLightCutoff = lmParams.AnimLightCutoff, AnimLightCutoff = lmParams.AnimLightCutoff,
UsePvs = pvs,
}; };
Timing.TimeStage("Gather Lights", BuildLightList); Timing.TimeStage("Gather Lights", BuildLightList);
@ -439,67 +437,61 @@ public class LightMapper
if (!_mission.TryGetChunk<WorldRep>("WREXT", out var worldRep)) if (!_mission.TryGetChunk<WorldRep>("WREXT", out var worldRep))
return; return;
// var lightVisibleCells = Timing.TimeStage("Light PVS", () =>
var lightVisibleCells = new List<int[]>(); // {
if (settings.UsePvs) // var cellCount = worldRep.Cells.Length;
{ // var aabbs = new MathUtils.Aabb[worldRep.Cells.Length];
lightVisibleCells = Timing.TimeStage("Light PVS", () => // Parallel.For(0, cellCount, i => aabbs[i] = new MathUtils.Aabb(worldRep.Cells[i].Vertices));
{ //
var cellCount = worldRep.Cells.Length; // var lightCellMap = new int[_lights.Count];
var aabbs = new MathUtils.Aabb[worldRep.Cells.Length]; // Parallel.For(0, _lights.Count, i =>
Parallel.For(0, cellCount, i => aabbs[i] = new MathUtils.Aabb(worldRep.Cells[i].Vertices)); // {
// lightCellMap[i] = -1;
var lightCellMap = new int[_lights.Count]; // var light = _lights[i];
Parallel.For(0, _lights.Count, i => // for (var j = 0; j < cellCount; j++)
{ // {
lightCellMap[i] = -1; // if (!MathUtils.Intersects(aabbs[j], light.Position))
var light = _lights[i]; // {
for (var j = 0; j < cellCount; j++) // continue;
{ // }
if (!MathUtils.Intersects(aabbs[j], light.Position)) //
{ // // Half-space contained
continue; // var cell = worldRep.Cells[j];
} // var contained = true;
// for (var k = 0; k < cell.PlaneCount; k++)
// Half-space contained // {
var cell = worldRep.Cells[j]; // var plane = cell.Planes[k];
var contained = true; // if (MathUtils.DistanceFromPlane(plane, light.Position) < -MathUtils.Epsilon)
for (var k = 0; k < cell.PlaneCount; k++) // {
{ // contained = false;
var plane = cell.Planes[k]; // break;
if (MathUtils.DistanceFromPlane(plane, light.Position) < -MathUtils.Epsilon) // }
{ // }
contained = false; //
break; // if (contained)
} // {
} // lightCellMap[i] = j;
// break;
if (contained) // }
{ // }
lightCellMap[i] = j; // });
break; //
} // var lightVisibleCells = new List<int[]>(_lights.Count);
} // var pvs = new PotentiallyVisibleSet(worldRep.Cells);
}); // for (var i = 0; i < _lights.Count; i++)
// {
var visibleCellMap = new List<int[]>(_lights.Count); // var cellIdx = lightCellMap[i];
var pvs = new PotentiallyVisibleSet(worldRep.Cells); // if (cellIdx == -1)
for (var i = 0; i < _lights.Count; i++) // {
{ // lightVisibleCells.Add([]);
var cellIdx = lightCellMap[i]; // continue;
if (cellIdx == -1) // }
{ // var visibleSet = pvs.GetVisible(lightCellMap[i]);
visibleCellMap.Add([]); // lightVisibleCells.Add(visibleSet);
continue; // }
} //
// return lightVisibleCells;
var visibleSet = pvs.GetVisible(lightCellMap[i]); // });
visibleCellMap.Add(visibleSet);
}
return visibleCellMap;
});
}
// TODO: Move this functionality to the LGS library // TODO: Move this functionality to the LGS library
// We set up light indices in separately from lighting because the actual // We set up light indices in separately from lighting because the actual
@ -543,10 +535,10 @@ public class LightMapper
continue; continue;
} }
if (settings.UsePvs && !lightVisibleCells[j].Contains(i)) // if (!lightVisibleCells[j].Contains(i))
{ // {
continue; // continue;
} // }
cell.LightIndexCount++; cell.LightIndexCount++;
cell.LightIndices.Add((ushort)light.LightTableIndex); cell.LightIndices.Add((ushort)light.LightTableIndex);
@ -577,7 +569,7 @@ public class LightMapper
if (overLit > 0) if (overLit > 0)
{ {
Log.Warning("{Count}/{CellCount} cells are overlit. Overlit cells can cause Object/Light Gem lighting issues. Try running with the --pvs flag.", overLit, worldRep.Cells.Length); Log.Warning("{Count}/{CellCount} cells are overlit. Overlit cells can cause Object/Light Gem lighting issues.", overLit, worldRep.Cells.Length);
} }
Log.Information("Max cell lights found ({Count}/96)", maxLights); Log.Information("Max cell lights found ({Count}/96)", maxLights);

View File

@ -40,9 +40,6 @@ public class LightCommand
[CliArgument(Description = "The name of the mission file including extension.")] [CliArgument(Description = "The name of the mission file including extension.")]
public required string MissionName { get; set; } public required string MissionName { get; set; }
[CliOption(Description = "Use a coarse PVS for tighter cell light indices.")]
public bool Pvs { get; set; } = false;
[CliOption(Description = "Name of output file excluding extension.")] [CliOption(Description = "Name of output file excluding extension.")]
public string OutputName { get; set; } = "kc_lit"; public string OutputName { get; set; } = "kc_lit";
@ -51,7 +48,7 @@ public class LightCommand
Timing.Reset(); Timing.Reset();
var lightMapper = new LightMapper(InstallPath, CampaignName, MissionName); var lightMapper = new LightMapper(InstallPath, CampaignName, MissionName);
lightMapper.Light(Pvs); lightMapper.Light();
lightMapper.Save(OutputName); lightMapper.Save(OutputName);
Timing.LogAll(); Timing.LogAll();