feat(render): weather-driven foliage wind for procedural scenery, shadows follow (Campaign VM VM6b)
Procedural-scenery foliage (trees/bushes — entity ids in the ProceduralSceneryIdAllocator's 0x8XXYYIII namespace) sways with weather in mesh_atmospheric.vert and all four directional_shadow_world_* caster vertex shaders, both calling the identical new foliage_wind.glsl include so the shadow moves with the leaf by construction. Classification (FoliageWindClassification, AcDream.App.Rendering.Wb): two new BatchData.flags bits, computed once per (entity, subset) from four inputs — entity id (bit 31 for procedural scenery), the pack's declared FoliageExclusions membership, the subset's TranslucencyKind, and ObjectRenderData.HasCutoutSubset (computed once per mesh at build time, not per frame). Bit 1 marks an alpha-cutout leaf subset; bit 2 marks an opaque trunk subset (only when its own mesh also owns a cutout subset, so rocks stay still). WbDrawDispatcher.ClassifyBatches (world receiver) and AddDirectionalShadowBatches (caster) call this with the same four inputs, so casters and receivers classify identically without needing to share state. Retail's mesh_modern/terrain_modern/mesh_detail pipelines never read these bits, so pack-off output is unaffected. Motion model (foliage_wind.glsl, mirrored bit-for-bit in the new FoliageWindModel for hermetic CPU tests): height-squared-scaled slow lean for every foliage subset, plus branch swing and per-vertex-hash-decorrelated flutter for cutout subsets only. AtmosphericPostProcessGraph.ResolveFoliageWind resolves the wind block once per frame.Serial — advanced by whichever of RenderDirectionalShadows (which runs first) or RenderPostProcess is called first that frame, with the second reading the already-advanced state, which is what keeps the caster and receiver reading byte-identical clock/strength values. The per-day-group mean/gust target (AtmospherePolicyDeclaration. FoliageWindByDayGroup, keyed by the same day-group index convention ActiveDayGroupMultipliers already established: Clear/Cloudy/Overcast/Rainy) eases toward its target over WeatherSystem.TransitionSeconds (10s) so a weather change never snaps; wind-enabled off or indoor instead gates the OUTPUT to an exact zero (not an asymptotic approach) so a settings toggle or cell transition is immediate. The wind clock is a Stopwatch started at graph construction (monotonic, session-relative magnitude for GPU sin() accuracy), overridable by the same ACDREAM_SKY_PHASE_SECONDS pin SkyRenderer already uses, for deterministic offline gates. New settings: wind-enabled, wind-strength, wind-direction-degrees (225° default — no authored retail wind direction exists to read), wind-lean-metres, wind-branch-metres, wind-flutter-metres (0 on Low), wind-canopy-height-metres. Register row IA-25 files this as an intentional, strictly opt-in divergence: retail applies no per-vertex wind displacement to any geometry. Known, accepted limitation: classification is per mesh-subset (one BatchData.flags word per indirect-draw batch), not per entity instance, so the rare case of one mesh subset being reachable from both a procedural-scenery and a non-scenery placement would classify all of that subset's instances alike. Tests: FoliageWindClassificationTests (the full classification matrix), FoliageWindModelTests (identity on non-foliage/calm-wind/base-vertex, canopy-top displacement bound, z-never-increases, trunk has no flutter term), RenderPackAtmospherePolicyEvaluationTests (exact day-group lookup, no interpolation across day-group ids, easing convergence without overshoot or discontinuity), AtmosphericShaderAbiTests (each of the five shaders calls acdreamFoliageDisplace exactly once; mesh_modern/terrain/mesh_detail call it never), and four AtmosphericPostProcessGraphTests additions (indoor/disabled exact-zero gating, settings-to-UBO wiring, same-frame-Serial idempotency — the last proxies the caster/receiver agreement invariant without needing this hermetic harness's WbDrawDispatcher/TerrainModernRenderer dependency chain to exercise RenderDirectionalShadows directly). App hermetic filter: 6015/6017 (the same 2 pre-existing failures as VM6a, confirmed unrelated). Core.Tests hermetic: 4697/4697. RenderPackValidator.Tests: 30/30. Full solution Debug and Release builds green. Shader recompile touched exactly the 5 edited files' .spv (plus manifest); the retail oracle set and every other pack shader are byte-identical. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
0930c35d1d
commit
39e8408c7d
34 changed files with 1536 additions and 64 deletions
|
|
@ -1220,6 +1220,115 @@ public sealed class AtmosphericPostProcessGraphTests
|
|||
Assert.Equal(1f, AtmosphericPostProcessGraph.BloomThresholdLinear);
|
||||
}
|
||||
|
||||
// ── Campaign VM VM6: foliage wind ────────────────────────────────────
|
||||
|
||||
[Fact]
|
||||
public void IndoorGatesWindOutputToExactZeroRegardlessOfSmoothedState()
|
||||
{
|
||||
var device = new RecordingGpuDevice();
|
||||
using var graph = Graph(device, "medium", windClockSecondsOverride: 12f);
|
||||
graph.PrepareWorldTarget(640, 480, 1);
|
||||
// Rainy (index 3 in the built-in table) is the highest declared
|
||||
// mean/gust — the exact target does not matter here, only that the
|
||||
// gate still zeroes the output despite a nonzero smoothed target.
|
||||
AtmosphericFrameInputs indoors = Inputs(640, 480, activeDayGroup: 3) with
|
||||
{
|
||||
IsOutdoor = false,
|
||||
};
|
||||
|
||||
AtmosphericFrameUniforms atmospheric = RenderAndReadFrameBlock(device, graph, indoors);
|
||||
|
||||
Assert.Equal(0f, atmospheric.ClockWind.Y); // mean
|
||||
Assert.Equal(0f, atmospheric.ClockWind.Z); // gust
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WindEnabledFalseGatesWindOutputToExactZero()
|
||||
{
|
||||
var device = new RecordingGpuDevice();
|
||||
using var graph = Graph(
|
||||
device,
|
||||
"medium",
|
||||
windClockSecondsOverride: 12f,
|
||||
userSettingOverrides: new Dictionary<string, string> { ["wind-enabled"] = "false" });
|
||||
graph.PrepareWorldTarget(640, 480, 1);
|
||||
AtmosphericFrameInputs outdoors = Inputs(640, 480, activeDayGroup: 3);
|
||||
|
||||
AtmosphericFrameUniforms atmospheric = RenderAndReadFrameBlock(device, graph, outdoors);
|
||||
|
||||
Assert.Equal(0f, atmospheric.ClockWind.Y);
|
||||
Assert.Equal(0f, atmospheric.ClockWind.Z);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WindAmplitudeReflectsTheDeclaredSettingDefaults()
|
||||
{
|
||||
var device = new RecordingGpuDevice();
|
||||
using var graph = Graph(device, "medium", windClockSecondsOverride: 5f);
|
||||
graph.PrepareWorldTarget(640, 480, 1);
|
||||
AtmosphericFrameInputs outdoors = Inputs(640, 480);
|
||||
|
||||
AtmosphericFrameUniforms atmospheric = RenderAndReadFrameBlock(device, graph, outdoors);
|
||||
|
||||
Assert.Equal(new Vector4(0.25f, 0.15f, 0.05f, 8f), atmospheric.WindAmplitude);
|
||||
// 225 degrees, the declared default direction.
|
||||
Assert.Equal(225f * (MathF.PI / 180f), atmospheric.ClockWind.W, 5);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RepeatedCallsOnTheSameFrameSerialProduceIdenticalWindBytes()
|
||||
{
|
||||
// RenderDirectionalShadows and RenderPostProcess both resolve the
|
||||
// wind block for frame.Serial, and RenderDirectionalShadows runs
|
||||
// first each frame. This proves the "advance once per Serial, later
|
||||
// callers read the already-advanced state" invariant that makes the
|
||||
// caster and receiver agree — without needing this hermetic
|
||||
// harness's full WbDrawDispatcher/TerrainModernRenderer dependency
|
||||
// chain to exercise RenderDirectionalShadows itself.
|
||||
var device = new RecordingGpuDevice();
|
||||
using var graph = Graph(device, "medium"); // real clock: proves it's the Serial guard, not a frozen override
|
||||
IGpuRenderTarget world = graph.PrepareWorldTarget(640, 480, 1);
|
||||
using IGpuFrame frame = device.BeginFrame();
|
||||
RecordWorldPass(frame, world);
|
||||
AtmosphericFrameInputs inputs = Inputs(640, 480, activeDayGroup: 3);
|
||||
|
||||
graph.RenderPostProcess(frame, in inputs);
|
||||
AtmosphericFrameUniforms first = ReadLastFrameBlock(device);
|
||||
graph.RenderPostProcess(frame, in inputs);
|
||||
AtmosphericFrameUniforms second = ReadLastFrameBlock(device);
|
||||
frame.End();
|
||||
|
||||
Assert.Equal(first.ClockWind, second.ClockWind);
|
||||
Assert.Equal(first.WindAmplitude, second.WindAmplitude);
|
||||
}
|
||||
|
||||
private static AtmosphericFrameUniforms RenderAndReadFrameBlock(
|
||||
RecordingGpuDevice device,
|
||||
AtmosphericPostProcessGraph graph,
|
||||
in AtmosphericFrameInputs inputs)
|
||||
{
|
||||
IGpuRenderTarget world = graph.PrepareWorldTarget(
|
||||
inputs.ViewportWidth,
|
||||
inputs.ViewportHeight,
|
||||
1);
|
||||
using IGpuFrame frame = device.BeginFrame();
|
||||
RecordWorldPass(frame, world);
|
||||
graph.RenderPostProcess(frame, in inputs);
|
||||
frame.End();
|
||||
return ReadLastFrameBlock(device);
|
||||
}
|
||||
|
||||
private static AtmosphericFrameUniforms ReadLastFrameBlock(RecordingGpuDevice device)
|
||||
{
|
||||
GpuRecordedUniformBind frameBlock = device
|
||||
.OfKind<GpuRecordedUniformBind>()
|
||||
.Last(call => call.Binding == GpuBindingModel.UniformAtmosphericFrame);
|
||||
return MemoryMarshal.Read<AtmosphericFrameUniforms>(
|
||||
device.RingBytes.Slice(
|
||||
(int)frameBlock.OffsetBytes,
|
||||
AtmosphericFrameUniforms.SizeInBytes));
|
||||
}
|
||||
|
||||
private static int CountOccurrences(string haystack, string needle)
|
||||
{
|
||||
int count = 0;
|
||||
|
|
@ -1235,7 +1344,9 @@ public sealed class AtmosphericPostProcessGraphTests
|
|||
private static AtmosphericPostProcessGraph Graph(
|
||||
RecordingGpuDevice device,
|
||||
string presetId,
|
||||
AtmosphericPostProcessSettings? settings = null)
|
||||
AtmosphericPostProcessSettings? settings = null,
|
||||
float? windClockSecondsOverride = null,
|
||||
IReadOnlyDictionary<string, string>? userSettingOverrides = null)
|
||||
{
|
||||
RenderPackDescriptor descriptor = BuiltInAtmosphericRenderPack.Descriptor;
|
||||
RenderQualityPreset preset = Assert.Single(
|
||||
|
|
@ -1246,7 +1357,9 @@ public sealed class AtmosphericPostProcessGraphTests
|
|||
descriptor,
|
||||
BuiltInAssets(),
|
||||
preset,
|
||||
settings);
|
||||
settings,
|
||||
userSettingOverrides,
|
||||
windClockSecondsOverride);
|
||||
}
|
||||
|
||||
private static RenderPackDescriptor ExternalTierOneDescriptor(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue