Lighting: directional sun shadows from the day/night sun angle
DayNight.SunShadow returns a cell offset opposite the sun's east-west position, longest near sunrise/sunset (low sun) and zero at noon/night, tilted slightly south so shadows fall in front of occluders. LightmapBuilder gains a directional shadow pass (MaxShadowCells length cap, SunShadowStrength darkening); LightmapSystem feeds it the current sun shadow each rebuild. Tests cover SunShadow's day-arc behaviour and the builder's directional darkening.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using MrGameEng.Core;
|
||||
using MrGameEng.Lighting;
|
||||
using Xunit;
|
||||
@@ -39,6 +40,25 @@ public class DayNightTests
|
||||
Assert.True(dawn < mid && mid < noon, "daylight should rise from dawn to noon");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SunShadow_ZeroAtNight_PointsWestInMorning_EastInAfternoon_ShortAtNoon()
|
||||
{
|
||||
var (clock, dayNight) = Make(); // 1s = 1 in-game hour
|
||||
|
||||
Assert.Equal(Vector2.Zero, dayNight.SunShadow(8f)); // 00:00 — night, no sun
|
||||
|
||||
clock.Advance(7f); // 07:00 — low morning sun in the east
|
||||
var morning = dayNight.SunShadow(8f);
|
||||
Assert.True(morning.X < 0f, "morning shadow points west");
|
||||
Assert.True(morning.Length() > 2f, "low sun casts a long shadow");
|
||||
|
||||
clock.Advance(5f); // 12:00 — sun overhead
|
||||
Assert.True(dayNight.SunShadow(8f).Length() < 1f, "noon sun casts almost no shadow");
|
||||
|
||||
clock.Advance(5f); // 17:00 — afternoon sun in the west
|
||||
Assert.True(dayNight.SunShadow(8f).X > 0f, "afternoon shadow points east");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Ambient_DarkerAtNightThanAtNoon()
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using MrGameEng.Lighting;
|
||||
using Xunit;
|
||||
|
||||
@@ -54,6 +55,29 @@ public class LightmapBuilderTests
|
||||
Assert.Equal(0f, light[5], 5); // за препятствием — тень
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SunShadow_DarkensCellsInTheShadowDirection_FadingFromTheCaster()
|
||||
{
|
||||
var occ = new bool[7];
|
||||
occ[3] = true; // occluder in the middle
|
||||
var light = new float[7];
|
||||
LightmapBuilder.Build(
|
||||
light,
|
||||
7,
|
||||
1,
|
||||
1f,
|
||||
occ,
|
||||
[],
|
||||
sunShadow: new Vector2(3f, 0f),
|
||||
sunShadowStrength: 0.6f
|
||||
);
|
||||
|
||||
Assert.Equal(1f, light[2], 5); // toward the sun (opposite the shadow) — unshadowed
|
||||
Assert.Equal(LightmapBuilder.OccluderShade, light[3], 5); // occluder cell stays self-shaded
|
||||
Assert.True(light[4] < 1f); // in shadow
|
||||
Assert.True(light[4] < light[6]); // darker near the caster, fading along the shadow
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Values_StayWithinUnitRange()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user