Compare commits

..

No commits in common. "9fd33efeed95c3d275fe9df5d8f442ebf3e55fa0" and "df9b21de46afcd854d70b28e6dd11c44447bc13b" have entirely different histories.

1 changed files with 17 additions and 53 deletions

View File

@ -88,7 +88,7 @@ public class LightMapper
};
Timing.TimeStage("Gather Lights", BuildLightList);
Timing.TimeStage("Set Light Indices", () => SetCellLightIndices(settings));
Timing.TimeStage("Set Light Indices", SetCellLightIndices);
Timing.TimeStage("Trace Scene", () => TraceScene(settings));
Timing.TimeStage("Update AnimLight Cell Mapping", SetAnimLightCellMaps);
@ -159,8 +159,6 @@ public class LightMapper
worldRep.LightingTable.Reset();
// TODO: Calculate the actual effective radius of infinite lights
// potentially do the same for all lights and lower their radius if necessary?
foreach (var brush in brList.Brushes)
{
switch (brush.media)
@ -173,12 +171,6 @@ public class LightMapper
break;
}
}
var infinite = _lights.Count(light => light.Radius == float.MaxValue);
if (infinite > 0)
{
Console.WriteLine($"WARNING: Infinite radius lights found: {infinite}/{_lights.Count}");
}
}
// TODO: Check if this works (brush is a record type)
@ -225,12 +217,6 @@ public class LightMapper
SpotlightDir = -Vector3.UnitZ,
SpotlightInnerAngle = -1.0f,
};
// TODO: Also apply scale?
var rot = Matrix4x4.Identity;
rot *= Matrix4x4.CreateRotationX(float.DegreesToRadians(brush.angle.X));
rot *= Matrix4x4.CreateRotationY(float.DegreesToRadians(brush.angle.Y));
rot *= Matrix4x4.CreateRotationZ(float.DegreesToRadians(brush.angle.Z));
if (propModelName != null)
{
@ -242,12 +228,11 @@ public class LightMapper
var model = new ModelFile(modelPath);
if (model.TryGetVhot(ModelFile.VhotId.LightPosition, out var vhot))
{
baseLight.Position += Vector3.Transform(vhot.Position - model.Header.Center, rot);
baseLight.Position += vhot.Position;
}
if (model.TryGetVhot(ModelFile.VhotId.LightDirection, out vhot))
{
baseLight.SpotlightDir = Vector3.Transform(vhot.Position - model.Header.Center, rot);
baseLight.SpotlightDir = vhot.Position;
}
}
@ -255,7 +240,13 @@ public class LightMapper
if (propSpotlight != null)
{
var rot = Matrix4x4.Identity;
rot *= Matrix4x4.CreateRotationX(float.DegreesToRadians(brush.angle.X));
rot *= Matrix4x4.CreateRotationY(float.DegreesToRadians(brush.angle.Y));
rot *= Matrix4x4.CreateRotationZ(float.DegreesToRadians(brush.angle.Z));
baseLight.Spotlight = true;
baseLight.SpotlightDir = Vector3.Transform(baseLight.SpotlightDir, rot);
baseLight.SpotlightInnerAngle = (float)Math.Cos(float.DegreesToRadians(propSpotlight.InnerAngle));
baseLight.SpotlightOuterAngle = (float)Math.Cos(float.DegreesToRadians(propSpotlight.OuterAngle));
}
@ -264,7 +255,7 @@ public class LightMapper
{
var light = new Light
{
Position = baseLight.Position + Vector3.Transform(propLight.Offset, rot),
Position = baseLight.Position + propLight.Offset,
Color = Utils.HsbToRgb(propLightColor.Hue, propLightColor.Saturation, propLight.Brightness),
InnerRadius = propLight.InnerRadius,
Radius = propLight.Radius,
@ -293,7 +284,7 @@ public class LightMapper
var light = new Light
{
Position = baseLight.Position + Vector3.Transform(propAnimLight.Offset, rot),
Position = baseLight.Position + propAnimLight.Offset,
Color = Utils.HsbToRgb(propLightColor.Hue, propLightColor.Saturation, propAnimLight.MaxBrightness),
InnerRadius = propAnimLight.InnerRadius,
Radius = propAnimLight.Radius,
@ -318,7 +309,7 @@ public class LightMapper
}
}
private void SetCellLightIndices(Settings settings)
private void SetCellLightIndices()
{
// TODO: Doors aren't blocking lights. Need to do some cell traversal to remove light indices :(
@ -339,15 +330,10 @@ public class LightMapper
cell.LightIndexCount++;
cell.LightIndices.Add(0);
// If we have sunlight, then we just assume the sun has the potential to reach everything (ew)
// The sun enabled option doesn't actually seem to do anything at runtime, it's purely about if
// the cell has the sunlight idx on it.
if (settings.Sunlight.Enabled)
{
cell.LightIndexCount++;
cell.LightIndices.Add(0);
cell.LightIndices[0]++;
}
// Additionally we'll add the sun to everything (yucky)
cell.LightIndexCount++;
cell.LightIndices.Add(0);
cell.LightIndices[0]++;
// 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
@ -369,31 +355,9 @@ public class LightMapper
if (cell.LightIndexCount > 97)
{
Console.WriteLine($"WARNING: Too many lights in cell at ({cell.SphereCenter}): {cell.LightIndexCount - 1} / 96");
Console.WriteLine($"Too many lights in cell at ({cell.SphereCenter}): {cell.LightIndexCount - 1} / 96");
}
});
{
var overLit = 0;
var maxLights = 0;
foreach (var cell in worldRep.Cells)
{
if (cell.LightIndexCount > 97)
{
overLit++;
}
if (cell.LightIndexCount > maxLights)
{
maxLights = cell.LightIndexCount - 1;
}
}
if (overLit > 0)
{
Console.WriteLine($"WARNING: Overlit cells detected: {overLit}/{worldRep.Cells.Length}, MaxLights: {maxLights} / 96");
}
}
}
private void TraceScene(Settings settings)