Compare commits

...

6 Commits

3 changed files with 19 additions and 13 deletions

View File

@ -37,9 +37,9 @@ public class LmParams : IChunk
public DepthMode ShadowDepth { get; set; }
public bool LightmappedWater { get; set; }
public int LightmapScale { get; set; }
public uint AnimLightCutoff { get; set; }
private int _dataSize;
private uint _unknown;
public void ReadData(BinaryReader reader, DbFile.TableOfContents.Entry entry)
{
@ -53,7 +53,7 @@ public class LmParams : IChunk
LightmappedWater = reader.ReadBoolean();
reader.ReadBytes(3);
LightmapScale = reader.ReadInt32();
_unknown = reader.ReadUInt32();
AnimLightCutoff = reader.ReadUInt32();
}
public void WriteData(BinaryWriter writer)
@ -68,6 +68,6 @@ public class LmParams : IChunk
writer.Write(LightmappedWater);
writer.Write(new byte[3]);
writer.Write(LightmapScale);
writer.Write(_unknown);
writer.Write(AnimLightCutoff);
}
}

View File

@ -51,15 +51,11 @@ public class Light
Matrix4x4 rotate,
Matrix4x4 scale)
{
var transform = scale * rotate * translate;
vhotLightPos = Vector3.Transform(vhotLightPos, transform);
vhotLightDir = Vector3.Transform(vhotLightDir, transform);
Position = Vector3.Transform(Position, rotate) + vhotLightPos;
SpotlightDir = Vector3.Normalize(vhotLightDir - vhotLightPos);
Position = Vector3.Transform(Position, rotate) + Vector3.Transform(vhotLightPos, scale * rotate * translate);
SpotlightDir = Vector3.Normalize(Vector3.Transform(vhotLightDir, scale * rotate));
}
public float StrengthAtPoint(Vector3 point, Plane plane)
public float StrengthAtPoint(Vector3 point, Plane plane, uint lightCutoff)
{
// Calculate light strength at a given point. As far as I can tell
// this is exact to Dark (I'm a genius??). It's just an inverse distance
@ -76,6 +72,13 @@ public class Light
strength *= (Radius - len) / (Radius - InnerRadius);
}
// Anim lights have a (configurable) minimum light cutoff. This is checked before
// spotlight multipliers are applied so we don't cutoff the spot radius falloff.
if (Anim && strength * Brightness < lightCutoff)
{
return 0f;
}
// This is basically the same as how inner radius works. It just applies
// a linear falloff to 0 between the inner angle and outer angle.
if (Spotlight)

View File

@ -25,6 +25,7 @@ public class LightMapper
public float MultiSamplingCenterWeight;
public bool LightmappedWater;
public SunSettings Sunlight;
public uint AnimLightCutoff;
}
private ResourcePathManager.CampaignResources _campaign;
@ -85,6 +86,7 @@ public class LightMapper
MultiSamplingCenterWeight = lmParams.CenterWeight,
LightmappedWater = lmParams.LightmappedWater,
Sunlight = sunlightSettings,
AnimLightCutoff = lmParams.AnimLightCutoff,
};
Timing.TimeStage("Gather Lights", BuildLightList);
@ -258,7 +260,7 @@ public class LightMapper
}
if (model.TryGetVhot(ModelFile.VhotId.LightDirection, out vhot))
{
vhotLightDir = vhot.Position - model.Header.Center;
vhotLightDir = (vhot.Position - model.Header.Center) - vhotLightPos;
}
}
}
@ -272,7 +274,7 @@ public class LightMapper
{
Position = propAnimLight.Offset,
Color = Utils.HsbToRgb(propLightColor.Hue, propLightColor.Saturation, propAnimLight.MaxBrightness),
Brightness = propAnimLight.Brightness,
Brightness = propAnimLight.MaxBrightness,
InnerRadius = propAnimLight.InnerRadius,
Radius = propAnimLight.Radius,
R2 = propAnimLight.Radius * propAnimLight.Radius,
@ -317,6 +319,7 @@ public class LightMapper
{
Position = light.Position,
Color = Utils.HsbToRgb(propLightColor.Hue, propLightColor.Saturation, propSpotAmb.SpotBrightness),
Brightness = propSpotAmb.SpotBrightness,
InnerRadius = light.InnerRadius,
Radius = light.Radius,
R2 = light.R2,
@ -594,7 +597,7 @@ public class LightMapper
if (TraceRay(light.Position, point))
{
strength += targetWeights[idx] * light.StrengthAtPoint(point, plane);
strength += targetWeights[idx] * light.StrengthAtPoint(point, plane, settings.AnimLightCutoff);
}
}