fix(render): shadow-gated-off receiver frames light from the authored sun again (Campaign VM VM6 review 5)
Round 4 (eec95535) fixed wind but introduced a new lighting bug: the
receiver VERTEX shaders source the sun direction from the shadow block,
not only the shadow visibility term. mesh_atmospheric.vert's
accumulateLights read uShadowLightDirectionAndSource unconditionally for
every directional light; terrain_atmospheric.vert did the same for its
single sun term. Round 4's PublishDisabledReceiverBinding writes
direction (0,0,1) into that block on every shadow-gated-off frame (user
sun-shadow-strength 0 in daylight, indoor/portal cover, night), so every
such frame was lighting outdoor terrain and objects from straight
overhead instead of the authored sun. Publishing the environment's real
direction would not have restored parity either -- the celestial shadow
source direction (sun/moon disc) is not the authored light direction.
F1 (BLOCKER): fixed in the shaders themselves, exact parity with the
plain pipeline. Both receiver verts now branch on the same flag bit
acdreamDirectionalShadowVisibility already reads
((uShadowTextureAndFlags.w & 1u) == 0u) and, when clear, use the EXACT
plain-pipeline expression instead of the shadow block's direction:
-uLights[i].dirAndRange.xyz in mesh_atmospheric.vert (matching
mesh_modern.vert, hoisted out of the light loop as a uniform branch);
-uLights[0].dirAndRange.xyz in terrain_atmospheric.vert (matching
terrain_modern.vert's sunDir/-sunDir form). The (0,0,1) word in the
disabled block stays as the documented normalize()-cannot-NaN guard; its
comment now says so explicitly since it is no longer read as a light
direction when the flag is clear.
F2: RenderPrepared's cascadeCount == 0 return is a third bufferless-
disabled path reachable from a frame that already passed Render's own
two gates (the cascade fitter can still find zero usable cascades) --
publishes the same disabled binding now, via the same
PublishDisabledReceiverBinding helper (re-signatured to take a bare
AtmosphericFrameBufferBinding so all three call sites -- Render's two
early-outs plus this one -- share it).
F3: removed a stray duplicated " -- Closeout and merge" fragment under
the plan's VM7 heading.
F4: corrected the false "the flag bit makes it numerically the plain
lighting sum" claim in the plan's round-4 paragraph and in
WbDrawDispatcher.DirectionalShadowReceivers.cs -- the flag bit alone
only fixed the shadow VISIBILITY term (already correct before round 4);
it took both that AND round 5's light-DIRECTION fallback to actually
match the plain pipeline.
T1: extracted Render's gate prologue (environment evaluate -> two
early-outs -> PublishDisabledReceiverBinding) into internal
EvaluateGateAndPublishDisabledBinding(frame, in input, out environment,
out environmentGateTicks), behaviour-preserving, called by Render before
it touches world/terrain -- the ArgumentNullException.ThrowIfNull(world)/
ThrowIfNull(terrain) calls keep their exact position relative to the
gate. No test in this suite constructs a real WbDrawDispatcher +
TerrainModernRenderer pair (still true), so this extraction is what
makes the gate itself testable; two new tests drive it directly with
PlayerInsideCell: true and with ResidentMaximumReachMeters <=
CameraNearMeters, asserting TryGetCurrentFrameBinding true / IsValidFor
false for both.
T2: proves the actual composition WbDrawDispatcher.PipelinesFor and
TerrainModernRenderer both use -- TryGetCurrentFrameBinding feeding
ShouldSelectReceiverPipeline -- selects the receiver pipeline for the
atmospheric world pass once a disabled binding is published, and still
refuses a non-atmospheric pass name.
T3: shader-source guard (same style as AtmosphericPostProcessGraphTests'
existing shader-text tests) pinning that both receiver verts contain the
flag-gated fallback and reference the same uLights expression the plain
verts use, so a future edit that drops the fallback fails this test
instead of only showing up in a pixel capture.
T4: the (0,0,1) test's doc comment and an inline assertion comment now
say the value is a NaN guard, not a light direction.
Regenerated SPIR-V: mesh_atmospheric.vert and terrain_atmospheric.vert
recompiled to different bytes this time (a real code change, not a
comment); manifest updated to match.
Verify: Release build 0 warnings/0 errors. App hermetic-lane filter
6,054/0 failed. Core.Tests 4,695/0 failed. RenderPackValidator 30/30.
Full hermetic-filtered solution: 15,282/0 failed across 15 projects.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
eec9553582
commit
754d59d949
10 changed files with 360 additions and 51 deletions
|
|
@ -6,6 +6,7 @@ using AcDream.App.Rendering.Packs;
|
|||
using AcDream.App.Rendering.Scene;
|
||||
using AcDream.App.Rendering.Wb;
|
||||
using AcDream.App.Tests.Rendering.Gpu;
|
||||
using AcDream.Core.World;
|
||||
using DatReaderWriter.Enums;
|
||||
|
||||
namespace AcDream.App.Tests.Rendering;
|
||||
|
|
@ -550,8 +551,14 @@ public sealed class DirectionalShadowGpuTests
|
|||
/// bindable (TryGetCurrentFrameBinding true) but is NOT a valid shadow
|
||||
/// (IsValidFor false, Enabled false), and the written block's flags
|
||||
/// word is exactly 0 (directional_shadow_receiver.glsl's bit-0-clear
|
||||
/// "full visibility" contract) with a unit light direction (0,0,1) —
|
||||
/// never the zero vector a shader's normalize() could turn into NaN.
|
||||
/// "full visibility" contract). Round 5 correction: the written
|
||||
/// direction (0,0,1) is asserted below purely as the documented
|
||||
/// normalize()-cannot-NaN GUARD value it is — round 4 mistakenly
|
||||
/// treated writing a plausible-looking direction as sufficient; round
|
||||
/// 5 fixed the receiver vertex shaders (mesh_atmospheric.vert,
|
||||
/// terrain_atmospheric.vert) to ignore this value entirely and fall
|
||||
/// back to the authored uLights direction whenever the flags bit is
|
||||
/// clear, so (0,0,1) is never read as a real light direction.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void PublishDisabledReceiverBinding_IsBindableButNotValidWithZeroFlagsAndUnitDirection()
|
||||
|
|
@ -563,16 +570,10 @@ public sealed class DirectionalShadowGpuTests
|
|||
atmosphericBuffer,
|
||||
OffsetBytes: 0u,
|
||||
SizeBytes: 192u);
|
||||
var input = new DirectionalSunShadowRenderInput(
|
||||
default,
|
||||
Matrix4x4.Identity,
|
||||
Matrix4x4.Identity,
|
||||
new DirectionalShadowCasterFrame(),
|
||||
AtmosphericFrame: atmosphericFrame);
|
||||
device.Clear();
|
||||
using IGpuFrame frame = device.BeginFrame();
|
||||
|
||||
renderer.PublishDisabledReceiverBinding(frame, in input);
|
||||
renderer.PublishDisabledReceiverBinding(frame, atmosphericFrame);
|
||||
|
||||
Assert.True(renderer.TryGetCurrentFrameBinding(frame, out DirectionalShadowFrameBinding binding));
|
||||
Assert.True(binding.IsBindableFor(frame));
|
||||
|
|
@ -588,6 +589,8 @@ public sealed class DirectionalShadowGpuTests
|
|||
(int)binding.OffsetBytes,
|
||||
DirectionalShadowUniforms.SizeInBytes));
|
||||
Assert.Equal(0u, written.TextureAndFlags.W);
|
||||
// (0,0,1) is the NaN guard, not a light direction — see the doc
|
||||
// comment above and PublishDisabledReceiverBinding's own comment.
|
||||
Assert.Equal(new Vector4(0f, 0f, 1f, 0f), written.LightDirectionAndSource);
|
||||
}
|
||||
|
||||
|
|
@ -602,20 +605,157 @@ public sealed class DirectionalShadowGpuTests
|
|||
// binding 5) is unaffected.
|
||||
using var device = new RecordingGpuDevice();
|
||||
using var renderer = new DirectionalSunShadowRenderer(device, DirectionalShadowPreset.Low);
|
||||
var input = new DirectionalSunShadowRenderInput(
|
||||
default,
|
||||
Matrix4x4.Identity,
|
||||
Matrix4x4.Identity,
|
||||
new DirectionalShadowCasterFrame());
|
||||
device.Clear();
|
||||
using IGpuFrame frame = device.BeginFrame();
|
||||
|
||||
renderer.PublishDisabledReceiverBinding(frame, in input);
|
||||
renderer.PublishDisabledReceiverBinding(frame, default);
|
||||
|
||||
Assert.False(renderer.TryGetCurrentFrameBinding(frame, out _));
|
||||
Assert.Empty(device.OfKind<GpuRecordedRingAllocation>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Campaign VM VM6 review fix round 5, test T1 (indoor early-out):
|
||||
/// no test calls DirectionalSunShadowRenderer.Render because it needs
|
||||
/// a real WbDrawDispatcher + TerrainModernRenderer to construct (still
|
||||
/// true — nothing in this suite stands either up), so the gate
|
||||
/// prologue Render runs before touching either is extracted into
|
||||
/// EvaluateGateAndPublishDisabledBinding (behaviour-preserving; see
|
||||
/// its own doc comment) and tested directly here. PlayerInsideCell is
|
||||
/// the simplest trigger for Render's FIRST early-out
|
||||
/// (!environment.ShouldRender).
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void EvaluateGateAndPublishDisabledBinding_PlayerInsideCellPublishesBindableNotValidBinding()
|
||||
{
|
||||
using var device = new RecordingGpuDevice();
|
||||
using var renderer = new DirectionalSunShadowRenderer(device, DirectionalShadowPreset.Low);
|
||||
using IGpuBuffer atmosphericBuffer = Buffer(device, "gate-indoor-frame", GpuBufferUsage.Uniform);
|
||||
var atmosphericFrame = new AtmosphericFrameBufferBinding(atmosphericBuffer, 0u, 192u);
|
||||
var input = new DirectionalSunShadowRenderInput(
|
||||
new DirectionalShadowEnvironmentInput(
|
||||
PackEnabled: true,
|
||||
PortalOrLoginCoverVisible: false,
|
||||
PlayerInsideCell: true,
|
||||
Source: AuthoredCelestialShadowSource.None(),
|
||||
Atmosphere: default),
|
||||
Matrix4x4.Identity,
|
||||
Matrix4x4.Identity,
|
||||
new DirectionalShadowCasterFrame(),
|
||||
AtmosphericFrame: atmosphericFrame);
|
||||
device.Clear();
|
||||
using IGpuFrame frame = device.BeginFrame();
|
||||
|
||||
DirectionalSunShadowDiagnostics? gated = renderer.EvaluateGateAndPublishDisabledBinding(
|
||||
frame,
|
||||
in input,
|
||||
out DirectionalShadowEnvironmentState environment,
|
||||
out long environmentGateTicks);
|
||||
|
||||
Assert.NotNull(gated);
|
||||
Assert.Equal(DirectionalShadowGateReason.Indoor, gated.Value.GateReason);
|
||||
Assert.Equal(DirectionalShadowGateReason.Indoor, environment.Reason);
|
||||
Assert.True(renderer.TryGetCurrentFrameBinding(frame, out DirectionalShadowFrameBinding binding));
|
||||
Assert.True(binding.IsBindableFor(frame));
|
||||
Assert.False(binding.IsValidFor(frame));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Campaign VM VM6 review fix round 5, test T1 (resident-window
|
||||
/// early-out): Render's SECOND early-out. Reaching it needs a fully
|
||||
/// valid environment (ShouldRender true), so the environment input
|
||||
/// below constructs a real celestial source above the horizon with
|
||||
/// energy, and a fully-progressed atmosphere snapshot — anything less
|
||||
/// would gate off at the FIRST check instead of reaching
|
||||
/// ResidentMaximumReachMeters.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void EvaluateGateAndPublishDisabledBinding_ResidentWindowUnavailablePublishesBindableNotValidBinding()
|
||||
{
|
||||
using var device = new RecordingGpuDevice();
|
||||
using var renderer = new DirectionalSunShadowRenderer(device, DirectionalShadowPreset.Low);
|
||||
using IGpuBuffer atmosphericBuffer = Buffer(device, "gate-resident-frame", GpuBufferUsage.Uniform);
|
||||
var atmosphericFrame = new AtmosphericFrameBufferBinding(atmosphericBuffer, 0u, 192u);
|
||||
var validSource = new AuthoredCelestialShadowSource(
|
||||
AuthoredCelestialShadowSourceKind.Sun,
|
||||
ObjectIndex: 0,
|
||||
GfxObjId: 1u,
|
||||
SurfaceToLightDirection: Vector3.UnitZ,
|
||||
ElevationSin: 0.5f,
|
||||
AuthoredEnergy: 1f);
|
||||
var validAtmosphere = new AtmosphereSnapshot(
|
||||
WeatherKind.Clear,
|
||||
Intensity: 1f,
|
||||
FogColor: Vector3.Zero,
|
||||
FogStart: 0f,
|
||||
FogEnd: 0f,
|
||||
FogMode: default,
|
||||
LightningFlash: 0f,
|
||||
Override: default);
|
||||
var input = new DirectionalSunShadowRenderInput(
|
||||
new DirectionalShadowEnvironmentInput(
|
||||
PackEnabled: true,
|
||||
PortalOrLoginCoverVisible: false,
|
||||
PlayerInsideCell: false,
|
||||
Source: validSource,
|
||||
Atmosphere: validAtmosphere,
|
||||
ActiveDayGroupMultiplier: 1f),
|
||||
Matrix4x4.Identity,
|
||||
Matrix4x4.Identity,
|
||||
new DirectionalShadowCasterFrame(),
|
||||
CameraNearMeters: 0.1f,
|
||||
ResidentMaximumReachMeters: 0.05f, // <= CameraNearMeters
|
||||
AtmosphericFrame: atmosphericFrame);
|
||||
device.Clear();
|
||||
using IGpuFrame frame = device.BeginFrame();
|
||||
|
||||
DirectionalSunShadowDiagnostics? gated = renderer.EvaluateGateAndPublishDisabledBinding(
|
||||
frame,
|
||||
in input,
|
||||
out DirectionalShadowEnvironmentState environment,
|
||||
out long environmentGateTicks);
|
||||
|
||||
Assert.NotNull(gated);
|
||||
Assert.Equal(DirectionalShadowGateReason.ResidentWindowUnavailable, gated.Value.GateReason);
|
||||
Assert.Equal(DirectionalShadowGateReason.ResidentWindowUnavailable, environment.Reason);
|
||||
Assert.True(renderer.TryGetCurrentFrameBinding(frame, out DirectionalShadowFrameBinding binding));
|
||||
Assert.True(binding.IsBindableFor(frame));
|
||||
Assert.False(binding.IsValidFor(frame));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShouldSelectReceiverPipelineComposesWithTheRealBindingSourceAfterADisabledPublish()
|
||||
{
|
||||
// Campaign VM VM6 review fix round 5, test T2: proves the ACTUAL
|
||||
// composition WbDrawDispatcher.PipelinesFor and
|
||||
// TerrainModernRenderer both use — TryGetCurrentFrameBinding
|
||||
// feeding ShouldSelectReceiverPipeline — selects the receiver
|
||||
// pipeline for the atmospheric world pass once a disabled binding
|
||||
// is published, and still refuses a non-atmospheric pass name.
|
||||
// ShouldSelectReceiverPipeline itself is unchanged this round;
|
||||
// this is the composition its own DirectionalShadowReceiverTests
|
||||
// parametrized coverage does not exercise.
|
||||
using var device = new RecordingGpuDevice();
|
||||
using var renderer = new DirectionalSunShadowRenderer(device, DirectionalShadowPreset.Low);
|
||||
using IGpuBuffer atmosphericBuffer = Buffer(device, "gate-pipeline-frame", GpuBufferUsage.Uniform);
|
||||
var atmosphericFrame = new AtmosphericFrameBufferBinding(atmosphericBuffer, 0u, 192u);
|
||||
device.Clear();
|
||||
using IGpuFrame frame = device.BeginFrame();
|
||||
|
||||
renderer.PublishDisabledReceiverBinding(frame, atmosphericFrame);
|
||||
bool bindingValid = renderer.TryGetCurrentFrameBinding(frame, out _);
|
||||
|
||||
Assert.True(bindingValid);
|
||||
Assert.True(DirectionalShadowReceiverPolicy.ShouldSelectReceiverPipeline(
|
||||
DirectionalShadowReceiverPolicy.AtmosphericWorldPassName,
|
||||
sourcePresent: true,
|
||||
bindingValid));
|
||||
Assert.False(DirectionalShadowReceiverPolicy.ShouldSelectReceiverPipeline(
|
||||
"vk-world",
|
||||
sourcePresent: true,
|
||||
bindingValid));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BindDirectionalShadowReceiver_WithADisabledBindingEmitsBothShadowAndAtmosphericBinds()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1222,6 +1222,55 @@ public sealed class AtmosphericPostProcessGraphTests
|
|||
|
||||
// ── Campaign VM VM6: foliage wind ────────────────────────────────────
|
||||
|
||||
[Fact]
|
||||
public void ReceiverVertexShadersFallBackToThePlainLightDirectionWhenTheShadowFlagIsClear()
|
||||
{
|
||||
// Campaign VM VM6 review fix round 5 (F1 BLOCKER, test T3): pins
|
||||
// the shader SOURCE TEXT so a future edit that removes the
|
||||
// flag-gated fallback (reintroducing "a shadow-gated-off frame
|
||||
// lights outdoor terrain/objects from the disabled block's
|
||||
// (0,0,1) placeholder instead of the authored sun") fails this
|
||||
// test instead of only showing up in a pixel capture. Both
|
||||
// receiver vertex shaders must (1) test the SAME flags bit
|
||||
// acdreamDirectionalShadowVisibility already tests, and (2)
|
||||
// reference the SAME uLights-derived expression the corresponding
|
||||
// plain (mesh_modern.vert / terrain_modern.vert) pipeline uses,
|
||||
// proving the fallback branch is not some other, unverified
|
||||
// direction.
|
||||
string shaderRoot = Path.Combine(
|
||||
RepositoryRoot(),
|
||||
"src",
|
||||
"AcDream.App",
|
||||
"Rendering",
|
||||
"Shaders");
|
||||
string meshAtmospheric = File.ReadAllText(Path.Combine(shaderRoot, "mesh_atmospheric.vert"));
|
||||
string meshModern = File.ReadAllText(Path.Combine(shaderRoot, "mesh_modern.vert"));
|
||||
string terrainAtmospheric = File.ReadAllText(Path.Combine(shaderRoot, "terrain_atmospheric.vert"));
|
||||
string terrainModern = File.ReadAllText(Path.Combine(shaderRoot, "terrain_modern.vert"));
|
||||
|
||||
const string flagTest = "(uShadowTextureAndFlags.w & 1u) == 0u";
|
||||
Assert.Contains(flagTest, meshAtmospheric, StringComparison.Ordinal);
|
||||
Assert.Contains(flagTest, terrainAtmospheric, StringComparison.Ordinal);
|
||||
|
||||
// mesh: both files negate the per-light uniform inline (no
|
||||
// intermediate variable), so the literal expression matches
|
||||
// string-for-string.
|
||||
const string meshPlainDirection = "-uLights[i].dirAndRange.xyz";
|
||||
Assert.Contains(meshPlainDirection, meshModern, StringComparison.Ordinal);
|
||||
Assert.Contains(meshPlainDirection, meshAtmospheric, StringComparison.Ordinal);
|
||||
|
||||
// terrain: terrain_modern.vert reads the uniform into `sunDir`
|
||||
// then negates that variable two lines later, so only the
|
||||
// shared uniform-access substring (not the exact negation
|
||||
// placement) is asserted identical between the two files.
|
||||
const string terrainLightUniform = "uLights[0].dirAndRange.xyz";
|
||||
Assert.Contains(terrainLightUniform, terrainModern, StringComparison.Ordinal);
|
||||
Assert.Contains(
|
||||
"-" + terrainLightUniform,
|
||||
terrainAtmospheric,
|
||||
StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FirstAdvanceSnapsExactlyToTheWeatherTargetInsteadOfEasingFromZero()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue