Compare commits
3 Commits
df9b21de46
...
9fd33efeed
Author | SHA1 | Date |
---|---|---|
Jarrod Doyle | 9fd33efeed | |
Jarrod Doyle | ed1b95af35 | |
Jarrod Doyle | 16dddcb497 |
|
@ -88,7 +88,7 @@ public class LightMapper
|
||||||
};
|
};
|
||||||
|
|
||||||
Timing.TimeStage("Gather Lights", BuildLightList);
|
Timing.TimeStage("Gather Lights", BuildLightList);
|
||||||
Timing.TimeStage("Set Light Indices", SetCellLightIndices);
|
Timing.TimeStage("Set Light Indices", () => SetCellLightIndices(settings));
|
||||||
Timing.TimeStage("Trace Scene", () => TraceScene(settings));
|
Timing.TimeStage("Trace Scene", () => TraceScene(settings));
|
||||||
Timing.TimeStage("Update AnimLight Cell Mapping", SetAnimLightCellMaps);
|
Timing.TimeStage("Update AnimLight Cell Mapping", SetAnimLightCellMaps);
|
||||||
|
|
||||||
|
@ -159,6 +159,8 @@ public class LightMapper
|
||||||
|
|
||||||
worldRep.LightingTable.Reset();
|
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)
|
foreach (var brush in brList.Brushes)
|
||||||
{
|
{
|
||||||
switch (brush.media)
|
switch (brush.media)
|
||||||
|
@ -171,6 +173,12 @@ public class LightMapper
|
||||||
break;
|
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)
|
// TODO: Check if this works (brush is a record type)
|
||||||
|
@ -218,6 +226,12 @@ public class LightMapper
|
||||||
SpotlightInnerAngle = -1.0f,
|
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)
|
if (propModelName != null)
|
||||||
{
|
{
|
||||||
var resName = $"{propModelName.value.ToLower()}.bin";
|
var resName = $"{propModelName.value.ToLower()}.bin";
|
||||||
|
@ -228,11 +242,12 @@ public class LightMapper
|
||||||
var model = new ModelFile(modelPath);
|
var model = new ModelFile(modelPath);
|
||||||
if (model.TryGetVhot(ModelFile.VhotId.LightPosition, out var vhot))
|
if (model.TryGetVhot(ModelFile.VhotId.LightPosition, out var vhot))
|
||||||
{
|
{
|
||||||
baseLight.Position += vhot.Position;
|
baseLight.Position += Vector3.Transform(vhot.Position - model.Header.Center, rot);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (model.TryGetVhot(ModelFile.VhotId.LightDirection, out vhot))
|
if (model.TryGetVhot(ModelFile.VhotId.LightDirection, out vhot))
|
||||||
{
|
{
|
||||||
baseLight.SpotlightDir = vhot.Position;
|
baseLight.SpotlightDir = Vector3.Transform(vhot.Position - model.Header.Center, rot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,13 +255,7 @@ public class LightMapper
|
||||||
|
|
||||||
if (propSpotlight != null)
|
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.Spotlight = true;
|
||||||
baseLight.SpotlightDir = Vector3.Transform(baseLight.SpotlightDir, rot);
|
|
||||||
baseLight.SpotlightInnerAngle = (float)Math.Cos(float.DegreesToRadians(propSpotlight.InnerAngle));
|
baseLight.SpotlightInnerAngle = (float)Math.Cos(float.DegreesToRadians(propSpotlight.InnerAngle));
|
||||||
baseLight.SpotlightOuterAngle = (float)Math.Cos(float.DegreesToRadians(propSpotlight.OuterAngle));
|
baseLight.SpotlightOuterAngle = (float)Math.Cos(float.DegreesToRadians(propSpotlight.OuterAngle));
|
||||||
}
|
}
|
||||||
|
@ -255,7 +264,7 @@ public class LightMapper
|
||||||
{
|
{
|
||||||
var light = new Light
|
var light = new Light
|
||||||
{
|
{
|
||||||
Position = baseLight.Position + propLight.Offset,
|
Position = baseLight.Position + Vector3.Transform(propLight.Offset, rot),
|
||||||
Color = Utils.HsbToRgb(propLightColor.Hue, propLightColor.Saturation, propLight.Brightness),
|
Color = Utils.HsbToRgb(propLightColor.Hue, propLightColor.Saturation, propLight.Brightness),
|
||||||
InnerRadius = propLight.InnerRadius,
|
InnerRadius = propLight.InnerRadius,
|
||||||
Radius = propLight.Radius,
|
Radius = propLight.Radius,
|
||||||
|
@ -284,7 +293,7 @@ public class LightMapper
|
||||||
|
|
||||||
var light = new Light
|
var light = new Light
|
||||||
{
|
{
|
||||||
Position = baseLight.Position + propAnimLight.Offset,
|
Position = baseLight.Position + Vector3.Transform(propAnimLight.Offset, rot),
|
||||||
Color = Utils.HsbToRgb(propLightColor.Hue, propLightColor.Saturation, propAnimLight.MaxBrightness),
|
Color = Utils.HsbToRgb(propLightColor.Hue, propLightColor.Saturation, propAnimLight.MaxBrightness),
|
||||||
InnerRadius = propAnimLight.InnerRadius,
|
InnerRadius = propAnimLight.InnerRadius,
|
||||||
Radius = propAnimLight.Radius,
|
Radius = propAnimLight.Radius,
|
||||||
|
@ -309,7 +318,7 @@ public class LightMapper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetCellLightIndices()
|
private void SetCellLightIndices(Settings settings)
|
||||||
{
|
{
|
||||||
// TODO: Doors aren't blocking lights. Need to do some cell traversal to remove light indices :(
|
// TODO: Doors aren't blocking lights. Need to do some cell traversal to remove light indices :(
|
||||||
|
|
||||||
|
@ -330,10 +339,15 @@ public class LightMapper
|
||||||
cell.LightIndexCount++;
|
cell.LightIndexCount++;
|
||||||
cell.LightIndices.Add(0);
|
cell.LightIndices.Add(0);
|
||||||
|
|
||||||
// Additionally we'll add the sun to everything (yucky)
|
// If we have sunlight, then we just assume the sun has the potential to reach everything (ew)
|
||||||
cell.LightIndexCount++;
|
// The sun enabled option doesn't actually seem to do anything at runtime, it's purely about if
|
||||||
cell.LightIndices.Add(0);
|
// the cell has the sunlight idx on it.
|
||||||
cell.LightIndices[0]++;
|
if (settings.Sunlight.Enabled)
|
||||||
|
{
|
||||||
|
cell.LightIndexCount++;
|
||||||
|
cell.LightIndices.Add(0);
|
||||||
|
cell.LightIndices[0]++;
|
||||||
|
}
|
||||||
|
|
||||||
// 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
|
||||||
|
@ -355,9 +369,31 @@ public class LightMapper
|
||||||
|
|
||||||
if (cell.LightIndexCount > 97)
|
if (cell.LightIndexCount > 97)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Too many lights in cell at ({cell.SphereCenter}): {cell.LightIndexCount - 1} / 96");
|
Console.WriteLine($"WARNING: 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)
|
private void TraceScene(Settings settings)
|
||||||
|
|
Loading…
Reference in New Issue