Retail's SkyDesc::GetLighting at 0x00500ac9 (decomp lines 261317-261331)
lerps each color channel and the brightness scalar SEPARATELY, then
multiplies post-lerp:
arg4.r = lerp(k1.amb_color.r, k2.amb_color.r, u)
arg4.g = lerp(k1.amb_color.g, k2.amb_color.g, u)
arg4.b = lerp(k1.amb_color.b, k2.amb_color.b, u)
arg3 = lerp(k1.amb_bright, k2.amb_bright, u)
final = (arg4.rgb * arg3, ...)
acdream pre-multiplied (color × bright) at LOAD time
(`SkyDescLoader.cs:558-559`) and then lerped the product. For any
keyframe pair where both color and brightness change, the two are
mathematically distinct. Example, k1=(white, b=0.5) k2=(black, b=1.0)
at u=0.5:
- retail: color=gray(0.5), bright=0.75 → final = (0.375, 0.375, 0.375)
- acdream: lerp((0.5,0.5,0.5), (0,0,0), 0.5) = (0.25, 0.25, 0.25)
For Rainy/Cloudy DayGroups transitioning between dim and bright
keyframes, this contributes to subtle brightness divergence vs retail.
Refactor:
SkyKeyframe stores DirColor / DirBright / AmbColor / AmbBright
SEPARATELY (raw, not pre-multiplied).
Computed properties SunColor and AmbientColor return the
post-multiplied product, keeping the shader uniform interface
(uSunColor / uAmbientColor) unchanged.
SkyStateProvider.Interpolate lerps each raw channel, then constructs
a new SkyKeyframe whose computed properties yield the correct
post-lerp multiply.
SkyDescLoader now stores raw values without pre-multiplying.
GameWindow comment updated; no functional change there.
Default factory + tests updated to use the new constructor parameters
with DirBright=AmbBright=1.0 (preserving exact existing behavior).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
71 lines
2.6 KiB
C#
71 lines
2.6 KiB
C#
using System;
|
|
using AcDream.Core.World;
|
|
using Xunit;
|
|
|
|
namespace AcDream.Core.Tests.World;
|
|
|
|
public sealed class WorldTimeDebugTests
|
|
{
|
|
[Fact]
|
|
public void SetDebugTime_OverridesDayFraction()
|
|
{
|
|
var service = new WorldTimeService(SkyStateProvider.Default());
|
|
service.SyncFromServer(0); // server tick 0 (= Morntide-and-Half)
|
|
|
|
service.SetDebugTime(0.5f); // force noon (Midsong-and-Half)
|
|
Assert.InRange(service.DayFraction, 0.499, 0.501);
|
|
}
|
|
|
|
[Fact]
|
|
public void ClearDebugTime_RestoresServerTime()
|
|
{
|
|
// Post tick-0-offset fix: DayFraction(tick) = ((tick + 7/16 * DayTicks) % DayTicks) / DayTicks.
|
|
// Pick a server tick whose real-world meaning is straightforward to verify.
|
|
// Sync to (0.25 - 7/16) * DayTicks negative means "3 slots before midnight
|
|
// past Morntide-and-Half", which in positive terms is 13/16 of the day
|
|
// past Morntide-and-Half, but simpler: sync to "1/16 past midnight" =
|
|
// ticks giving fraction 1/16. Required tick offset from 0 to land at
|
|
// fraction 1/16: solve (t + 7/16*D) mod D = 1/16*D
|
|
// → t = (1/16 - 7/16) * D mod D = -6/16 * D mod D = 10/16 * D.
|
|
double targetFraction = 1.0 / 16.0; // Darktide-and-Half
|
|
double syncTick = (targetFraction - (7.0 / 16.0) + 1.0) * DerethDateTime.DayTicks;
|
|
|
|
var service = new WorldTimeService(SkyStateProvider.Default());
|
|
service.SyncFromServer(syncTick);
|
|
service.SetDebugTime(0.5f);
|
|
service.ClearDebugTime();
|
|
|
|
Assert.InRange(service.DayFraction, targetFraction - 0.01, targetFraction + 0.01);
|
|
}
|
|
|
|
[Fact]
|
|
public void SyncFromServer_ClearsDebugOverride()
|
|
{
|
|
var service = new WorldTimeService(SkyStateProvider.Default());
|
|
service.SetDebugTime(0.75f);
|
|
service.SyncFromServer(0); // tick 0 = Morntide-and-Half → fraction 7/16
|
|
|
|
Assert.InRange(service.DayFraction, 7.0 / 16.0 - 0.01, 7.0 / 16.0 + 0.01);
|
|
}
|
|
|
|
[Fact]
|
|
public void SetProvider_AcceptsNewKeyframes()
|
|
{
|
|
var service = new WorldTimeService(SkyStateProvider.Default());
|
|
var custom = new SkyStateProvider(new[]
|
|
{
|
|
new SkyKeyframe(
|
|
Begin: 0f,
|
|
SunHeadingDeg: 0f,
|
|
SunPitchDeg: 90f,
|
|
DirColor: System.Numerics.Vector3.One,
|
|
DirBright: 1f,
|
|
AmbColor: System.Numerics.Vector3.One,
|
|
AmbBright: 1f,
|
|
FogColor: System.Numerics.Vector3.Zero,
|
|
FogDensity: 0f),
|
|
});
|
|
service.SetProvider(custom);
|
|
Assert.Equal(1, custom.KeyframeCount);
|
|
}
|
|
}
|