From 7fbff66f7b0befe2a364253bb70903c991efce3d Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 19 May 2026 13:40:52 +0100 Subject: [PATCH] Extract temporal spatial evidence reservoir --- docs/temporal-sdf-gaussian-field.md | 10 +- .../Temporal/TemporalGaussianAccumulator.cs | 159 ++++---------- .../TemporalSpatialEvidenceObservation.cs | 47 +++++ .../TemporalSpatialEvidenceReservoir.cs | 195 ++++++++++++++++++ state/evidence.jsonl | 1 + state/map.yaml | 1 + state/memory.json | 1 + .../FractalResourceBudgetPlannerTests.cs | 2 +- .../TemporalSpatialEvidenceReservoirTests.cs | 98 +++++++++ 9 files changed, 391 insertions(+), 123 deletions(-) create mode 100644 src/Aquarium.Engine.Fractal/Temporal/TemporalSpatialEvidenceObservation.cs create mode 100644 src/Aquarium.Engine.Fractal/Temporal/TemporalSpatialEvidenceReservoir.cs create mode 100644 tests/Aquarium.Engine.Fractal.Tests/TemporalSpatialEvidenceReservoirTests.cs diff --git a/docs/temporal-sdf-gaussian-field.md b/docs/temporal-sdf-gaussian-field.md index 984ee12..a3b6392 100644 --- a/docs/temporal-sdf-gaussian-field.md +++ b/docs/temporal-sdf-gaussian-field.md @@ -16,14 +16,22 @@ center, velocity, oriented radii, color/opacity, confidence, history weight, compact-kernel controls, and field id. `Aquarium.Engine.Fractal.Temporal.TemporalGaussianAccumulator` consumes -`TemporalGaussianObservation` rows and owns the live buffering policy: +`TemporalGaussianObservation` rows and lowers them through the shared +`TemporalSpatialEvidenceReservoir`. The reservoir owns the live buffering +policy: - stable keys identify tracks across camera/sensor frames - presentation delay lets late sensor data converge before rendering - accumulation window expires old tracks +- max-track budgets evict low-confidence stale tracks before renderer lowering - smoothed velocity predicts the presented center - history weight is confidence scaled by age inside the window +The Gaussian field is one backend for this reservoir, not the reservoir's +identity. Fractal SDF probes, visual point-cloud features, and future acoustic +constraints can all enter as stable keyed spatial evidence as long as each +producer declares confidence, time, bounds, and payload lowering rules. + The D3D12 renderer lowers the field into `D3D12TemporalGaussianPacket`, uploads the active packet span into a 1,048,576-entry structured buffer, and renders an instanced proxy-quad pass from diff --git a/src/Aquarium.Engine.Fractal/Temporal/TemporalGaussianAccumulator.cs b/src/Aquarium.Engine.Fractal/Temporal/TemporalGaussianAccumulator.cs index 1cbab51..10bc867 100644 --- a/src/Aquarium.Engine.Fractal/Temporal/TemporalGaussianAccumulator.cs +++ b/src/Aquarium.Engine.Fractal/Temporal/TemporalGaussianAccumulator.cs @@ -5,7 +5,7 @@ namespace Aquarium.Engine.Fractal.Temporal; public sealed class TemporalGaussianAccumulator { - private readonly Dictionary tracks = []; + private readonly TemporalSpatialEvidenceReservoir reservoir; public TemporalGaussianAccumulator( float accumulationWindowSeconds, @@ -27,145 +27,62 @@ public sealed class TemporalGaussianAccumulator throw new ArgumentOutOfRangeException(nameof(smoothing), smoothing, "Smoothing must be in (0, 1]."); } - AccumulationWindowSeconds = accumulationWindowSeconds; - PresentationDelaySeconds = presentationDelaySeconds; - Smoothing = smoothing; + reservoir = new TemporalSpatialEvidenceReservoir(accumulationWindowSeconds, presentationDelaySeconds, smoothing); } - public float AccumulationWindowSeconds { get; } + public float AccumulationWindowSeconds => reservoir.AccumulationWindowSeconds; - public float PresentationDelaySeconds { get; } + public float PresentationDelaySeconds => reservoir.PresentationDelaySeconds; - public float Smoothing { get; } + public float Smoothing => reservoir.Smoothing; public void Observe(IEnumerable observations) { - foreach (var observation in observations) - { - if (string.IsNullOrWhiteSpace(observation.StableKey)) - { - continue; - } - - if (tracks.TryGetValue(observation.StableKey, out var current)) - { - tracks[observation.StableKey] = current.Update(observation, Smoothing); - } - else - { - tracks[observation.StableKey] = TemporalGaussianTrack.Create(observation); - } - } + reservoir.Observe(observations.Select(observation => new TemporalSpatialEvidenceObservation( + observation.StableKey, + observation.Center, + observation.Radii, + observation.Orientation, + observation.ColorOpacity, + new Vector4( + MathF.Max(0.0001f, observation.Falloff), + MathF.Max(0.0001f, observation.ShapePower), + 0.0f, + 0.0f), + observation.Confidence, + observation.ObservedTimeSeconds, + observation.FieldId))); } public AquariumTemporalGaussianField BuildField(float renderTimeSeconds) { - var presentationTime = renderTimeSeconds - PresentationDelaySeconds; - var cutoff = presentationTime - AccumulationWindowSeconds; - var gaussians = new List(tracks.Count); - var expired = new List(); + var snapshot = reservoir.BuildSnapshot(renderTimeSeconds); + var gaussians = new AquariumTemporalSdfGaussian[snapshot.Samples.Count]; - foreach (var (key, track) in tracks) + for (var index = 0; index < snapshot.Samples.Count; index++) { - if (track.LastObservedTimeSeconds < cutoff) - { - expired.Add(key); - continue; - } - - var age = MathF.Max(0.0f, presentationTime - track.LastObservedTimeSeconds); - var historyWeight = Math.Clamp(1.0f - (age / AccumulationWindowSeconds), 0.0f, 1.0f) * track.Confidence; - var predictedCenter = track.Center + track.Velocity * (presentationTime - track.LastObservedTimeSeconds); - var previousCenter = predictedCenter - track.Velocity * (1.0f / 60.0f); - gaussians.Add(new AquariumTemporalSdfGaussian( - track.StableKey, - predictedCenter, - previousCenter, - track.Velocity, - track.Radii, - track.Orientation, - track.ColorOpacity, - track.Confidence, - historyWeight, - track.LastObservedTimeSeconds, - track.Falloff, - track.ShapePower, - track.FieldId)); - } - - foreach (var key in expired) - { - tracks.Remove(key); + var sample = snapshot.Samples[index]; + gaussians[index] = new AquariumTemporalSdfGaussian( + sample.StableKey, + sample.Center, + sample.PreviousCenter, + sample.Velocity, + sample.Radii, + sample.Orientation, + sample.Payload0, + sample.Confidence, + sample.HistoryWeight, + sample.LastObservedTimeSeconds, + sample.Payload1.X, + sample.Payload1.Y, + sample.FieldId); } return new AquariumTemporalGaussianField { - Gaussians = gaussians.OrderByDescending(item => item.HistoryWeight).ToArray(), + Gaussians = gaussians, AccumulationWindowSeconds = AccumulationWindowSeconds, PresentationDelaySeconds = PresentationDelaySeconds, }; } - - private readonly record struct TemporalGaussianTrack( - string StableKey, - Vector3 Center, - Vector3 Velocity, - Vector3 Radii, - Quaternion Orientation, - Vector4 ColorOpacity, - float Confidence, - float LastObservedTimeSeconds, - float Falloff, - float ShapePower, - int FieldId) - { - public static TemporalGaussianTrack Create(TemporalGaussianObservation observation) - { - return new TemporalGaussianTrack( - observation.StableKey, - observation.Center, - Vector3.Zero, - SanitizeRadii(observation.Radii), - SanitizeOrientation(observation.Orientation), - observation.ColorOpacity, - Math.Clamp(observation.Confidence, 0.0f, 1.0f), - observation.ObservedTimeSeconds, - MathF.Max(0.0001f, observation.Falloff), - MathF.Max(0.0001f, observation.ShapePower), - observation.FieldId); - } - - public TemporalGaussianTrack Update(TemporalGaussianObservation observation, float smoothing) - { - var dt = MathF.Max(0.0001f, observation.ObservedTimeSeconds - LastObservedTimeSeconds); - var measuredVelocity = (observation.Center - Center) / dt; - var alpha = smoothing * Math.Clamp(observation.Confidence, 0.0f, 1.0f); - var updatedCenter = Vector3.Lerp(Center, observation.Center, alpha); - return this with - { - Center = updatedCenter, - Velocity = Vector3.Lerp(Velocity, measuredVelocity, alpha), - Radii = Vector3.Lerp(Radii, SanitizeRadii(observation.Radii), alpha), - Orientation = SanitizeOrientation(Quaternion.Slerp(Orientation, SanitizeOrientation(observation.Orientation), alpha)), - ColorOpacity = Vector4.Lerp(ColorOpacity, observation.ColorOpacity, alpha), - Confidence = Math.Clamp((Confidence * 0.85f) + (observation.Confidence * 0.15f), 0.0f, 1.0f), - LastObservedTimeSeconds = observation.ObservedTimeSeconds, - Falloff = MathF.Max(0.0001f, observation.Falloff), - ShapePower = MathF.Max(0.0001f, observation.ShapePower), - FieldId = observation.FieldId, - }; - } - - private static Vector3 SanitizeRadii(Vector3 radii) - { - return Vector3.Max(radii, new Vector3(0.0001f)); - } - - private static Quaternion SanitizeOrientation(Quaternion orientation) - { - return orientation.LengthSquared() <= 0.000001f - ? Quaternion.Identity - : Quaternion.Normalize(orientation); - } - } } diff --git a/src/Aquarium.Engine.Fractal/Temporal/TemporalSpatialEvidenceObservation.cs b/src/Aquarium.Engine.Fractal/Temporal/TemporalSpatialEvidenceObservation.cs new file mode 100644 index 0000000..be13644 --- /dev/null +++ b/src/Aquarium.Engine.Fractal/Temporal/TemporalSpatialEvidenceObservation.cs @@ -0,0 +1,47 @@ +using System.Numerics; + +namespace Aquarium.Engine.Fractal.Temporal; + +public readonly record struct TemporalSpatialEvidenceObservation( + string StableKey, + Vector3 Center, + Vector3 Radii, + Quaternion Orientation, + Vector4 Payload0, + Vector4 Payload1, + float Confidence, + float ObservedTimeSeconds, + int FieldId = 0); + +public readonly record struct TemporalSpatialEvidenceSample( + string StableKey, + Vector3 Center, + Vector3 PreviousCenter, + Vector3 Velocity, + Vector3 Radii, + Quaternion Orientation, + Vector4 Payload0, + Vector4 Payload1, + float Confidence, + float HistoryWeight, + float LastObservedTimeSeconds, + int FieldId); + +public sealed class TemporalSpatialEvidenceSnapshot +{ + public TemporalSpatialEvidenceSnapshot( + IReadOnlyList samples, + float accumulationWindowSeconds, + float presentationDelaySeconds) + { + Samples = samples; + AccumulationWindowSeconds = accumulationWindowSeconds; + PresentationDelaySeconds = presentationDelaySeconds; + } + + public IReadOnlyList Samples { get; } + + public float AccumulationWindowSeconds { get; } + + public float PresentationDelaySeconds { get; } +} diff --git a/src/Aquarium.Engine.Fractal/Temporal/TemporalSpatialEvidenceReservoir.cs b/src/Aquarium.Engine.Fractal/Temporal/TemporalSpatialEvidenceReservoir.cs new file mode 100644 index 0000000..0812a27 --- /dev/null +++ b/src/Aquarium.Engine.Fractal/Temporal/TemporalSpatialEvidenceReservoir.cs @@ -0,0 +1,195 @@ +using System.Numerics; + +namespace Aquarium.Engine.Fractal.Temporal; + +public sealed class TemporalSpatialEvidenceReservoir +{ + private readonly Dictionary tracks = []; + + public TemporalSpatialEvidenceReservoir( + float accumulationWindowSeconds, + float presentationDelaySeconds, + float smoothing = 0.35f, + int maxTrackCount = int.MaxValue) + { + if (!float.IsFinite(accumulationWindowSeconds) || accumulationWindowSeconds <= 0.0f) + { + throw new ArgumentOutOfRangeException(nameof(accumulationWindowSeconds), accumulationWindowSeconds, "Accumulation window must be positive."); + } + + if (!float.IsFinite(presentationDelaySeconds) || presentationDelaySeconds < 0.0f) + { + throw new ArgumentOutOfRangeException(nameof(presentationDelaySeconds), presentationDelaySeconds, "Presentation delay must be non-negative."); + } + + if (!float.IsFinite(smoothing) || smoothing <= 0.0f || smoothing > 1.0f) + { + throw new ArgumentOutOfRangeException(nameof(smoothing), smoothing, "Smoothing must be in (0, 1]."); + } + + if (maxTrackCount <= 0) + { + throw new ArgumentOutOfRangeException(nameof(maxTrackCount), maxTrackCount, "Track budget must be positive."); + } + + AccumulationWindowSeconds = accumulationWindowSeconds; + PresentationDelaySeconds = presentationDelaySeconds; + Smoothing = smoothing; + MaxTrackCount = maxTrackCount; + } + + public float AccumulationWindowSeconds { get; } + + public float PresentationDelaySeconds { get; } + + public float Smoothing { get; } + + public int MaxTrackCount { get; } + + public void Observe(IEnumerable observations) + { + foreach (var observation in observations) + { + if (string.IsNullOrWhiteSpace(observation.StableKey)) + { + continue; + } + + if (tracks.TryGetValue(observation.StableKey, out var current)) + { + tracks[observation.StableKey] = current.Update(observation, Smoothing); + } + else + { + tracks[observation.StableKey] = TemporalSpatialEvidenceTrack.Create(observation); + } + } + + TrimToBudget(); + } + + public TemporalSpatialEvidenceSnapshot BuildSnapshot(float renderTimeSeconds) + { + var presentationTime = renderTimeSeconds - PresentationDelaySeconds; + var cutoff = presentationTime - AccumulationWindowSeconds; + var samples = new List(tracks.Count); + var expired = new List(); + + foreach (var (key, track) in tracks) + { + if (track.LastObservedTimeSeconds < cutoff) + { + expired.Add(key); + continue; + } + + var age = MathF.Max(0.0f, presentationTime - track.LastObservedTimeSeconds); + var historyWeight = Math.Clamp(1.0f - (age / AccumulationWindowSeconds), 0.0f, 1.0f) * track.Confidence; + var predictedCenter = track.Center + track.Velocity * (presentationTime - track.LastObservedTimeSeconds); + var previousCenter = predictedCenter - track.Velocity * (1.0f / 60.0f); + samples.Add(new TemporalSpatialEvidenceSample( + track.StableKey, + predictedCenter, + previousCenter, + track.Velocity, + track.Radii, + track.Orientation, + track.Payload0, + track.Payload1, + track.Confidence, + historyWeight, + track.LastObservedTimeSeconds, + track.FieldId)); + } + + foreach (var key in expired) + { + tracks.Remove(key); + } + + return new TemporalSpatialEvidenceSnapshot( + samples.OrderByDescending(item => item.HistoryWeight).ToArray(), + AccumulationWindowSeconds, + PresentationDelaySeconds); + } + + private void TrimToBudget() + { + if (tracks.Count <= MaxTrackCount) + { + return; + } + + var evict = tracks.Values + .OrderBy(track => track.Confidence) + .ThenBy(track => track.LastObservedTimeSeconds) + .Take(tracks.Count - MaxTrackCount) + .Select(track => track.StableKey) + .ToArray(); + + foreach (var key in evict) + { + tracks.Remove(key); + } + } + + private readonly record struct TemporalSpatialEvidenceTrack( + string StableKey, + Vector3 Center, + Vector3 Velocity, + Vector3 Radii, + Quaternion Orientation, + Vector4 Payload0, + Vector4 Payload1, + float Confidence, + float LastObservedTimeSeconds, + int FieldId) + { + public static TemporalSpatialEvidenceTrack Create(TemporalSpatialEvidenceObservation observation) + { + return new TemporalSpatialEvidenceTrack( + observation.StableKey, + observation.Center, + Vector3.Zero, + SanitizeRadii(observation.Radii), + SanitizeOrientation(observation.Orientation), + observation.Payload0, + observation.Payload1, + Math.Clamp(observation.Confidence, 0.0f, 1.0f), + observation.ObservedTimeSeconds, + observation.FieldId); + } + + public TemporalSpatialEvidenceTrack Update(TemporalSpatialEvidenceObservation observation, float smoothing) + { + var dt = MathF.Max(0.0001f, observation.ObservedTimeSeconds - LastObservedTimeSeconds); + var measuredVelocity = (observation.Center - Center) / dt; + var alpha = smoothing * Math.Clamp(observation.Confidence, 0.0f, 1.0f); + var updatedCenter = Vector3.Lerp(Center, observation.Center, alpha); + return this with + { + Center = updatedCenter, + Velocity = Vector3.Lerp(Velocity, measuredVelocity, alpha), + Radii = Vector3.Lerp(Radii, SanitizeRadii(observation.Radii), alpha), + Orientation = SanitizeOrientation(Quaternion.Slerp(Orientation, SanitizeOrientation(observation.Orientation), alpha)), + Payload0 = Vector4.Lerp(Payload0, observation.Payload0, alpha), + Payload1 = Vector4.Lerp(Payload1, observation.Payload1, alpha), + Confidence = Math.Clamp((Confidence * 0.85f) + (observation.Confidence * 0.15f), 0.0f, 1.0f), + LastObservedTimeSeconds = observation.ObservedTimeSeconds, + FieldId = observation.FieldId, + }; + } + + private static Vector3 SanitizeRadii(Vector3 radii) + { + return Vector3.Max(radii, new Vector3(0.0001f)); + } + + private static Quaternion SanitizeOrientation(Quaternion orientation) + { + return orientation.LengthSquared() <= 0.000001f + ? Quaternion.Identity + : Quaternion.Normalize(orientation); + } + } +} diff --git a/state/evidence.jsonl b/state/evidence.jsonl index abb992c..b61faa9 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -150,3 +150,4 @@ {"timestamp":"2026-05-18T12:22:00+01:00","topic":"fractal-temporal-detail-control","lesson":"Fractal cache influence now has a first TAA-facing lane. SdfSurface carries temporalDetail, SDF proxy writes it into scene-control.z, D3D12Post validates history continuity against the current and previous temporalDetail signal, and history-control.z preserves it across frames. Zyphos feeds this from authored cube-face brush material influence; other SDFs explicitly emit zero until they gain cache-owned detail.","files":["src/Aquarium.Engine/Render/Shaders/D3D12SdfCommon.hlsli","src/Aquarium.Engine/Render/Shaders/D3D12SdfProxy.hlsli","src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","src/Aquarium.Zyphos/Shaders/D3D12ZyphosPlanet.hlsl","src/Aquarium.Epiphany/Shaders"],"source":"user said to weave the stochastic fractal cache into TAA buffers"} {"timestamp":"2026-05-18T18:09:50+01:00","topic":"temporal-sdf-gaussian-renderer-boundary","lesson":"Live sensor-fusion splats now enter Aquarium through an engine-owned temporal SDF Gaussian field instead of client-side renderer folklore. The contract carries stable keyed world-space Gaussians; `TemporalGaussianAccumulator` buffers observations with presentation delay and history weights; D3D12 uploads structured packets and renders an instanced compact-kernel splat pass into the existing scene/metadata/control targets. Scaling beyond 4096 splats belongs to Aquarium residency/binning, not LocalCastBridge.","files":["src/Aquarium.Engine.Contracts/Render/AquariumRenderPlan.cs","src/Aquarium.Engine.Fractal/Temporal/TemporalGaussianAccumulator.cs","src/Aquarium.Engine/Render/Shaders/D3D12TemporalGaussian.hlsl","src/Aquarium.Engine/Render/D3D12Renderer.cs","docs/temporal-sdf-gaussian-field.md"],"source":"user directed the point-cloud/TAA renderer feature to be implemented on the Aquarium side for clean client consumption"} {"timestamp":"2026-05-19T13:38:00+01:00","topic":"fractal-resource-budget-and-flame-dsl","lesson":"The fractal DSL now has a compact `flame` primitive for deterministic curled recursive brush emission, and Zyphos exercises it in a leaf microdetail domain without exceeding the 64-brush stress table. Fractal render planning now coordinates CPU stochastic update count, GPU selected-cut estimated cost, RAM resident payload budget, and SSD request budget before packet compilation. This budget vocabulary should remain compatible with Mimir-style sensor fusion because both pipelines accumulate confidence-weighted spatial samples into temporal reservoirs before rendering a resolved field.","files":["src/Aquarium.Engine.Fractal/Grammar/FractalDslCompiler.cs","src/Aquarium.Engine.Fractal/Lod/FractalResourceBudget.cs","src/Aquarium.Engine.Fractal/Lod/FractalResourceBudgetPlanner.cs","src/Aquarium.Engine.Fractal/Lod/FractalResidencyPlanner.cs","src/Aquarium.Zyphos/ZyphosFractalTerrain.cs","src/Aquarium.Zyphos/Worlds/zyphos-first-fractal-terrain.aquageo","tests/Aquarium.Engine.Fractal.Tests/FractalResourceBudgetPlannerTests.cs"],"source":"user demanded full fractal SDF rendering and noted Mimir sensor fusion shares the same temporal spatial evidence shape"} +{"timestamp":"2026-05-19T14:04:00+01:00","topic":"temporal-spatial-evidence-reservoir","lesson":"Temporal Gaussian accumulation now uses `TemporalSpatialEvidenceReservoir`, which owns stable-keyed spatial tracks, smoothing, delayed presentation, velocity prediction, confidence-weighted history, expiry, and max-track eviction. This pulls the common reservoir shape out from under Gaussian rendering so fractal SDF probes and Mimir sensor-fusion features can converge through the same evidence machinery before backend lowering.","files":["src/Aquarium.Engine.Fractal/Temporal/TemporalSpatialEvidenceObservation.cs","src/Aquarium.Engine.Fractal/Temporal/TemporalSpatialEvidenceReservoir.cs","src/Aquarium.Engine.Fractal/Temporal/TemporalGaussianAccumulator.cs","tests/Aquarium.Engine.Fractal.Tests/TemporalSpatialEvidenceReservoirTests.cs","docs/temporal-sdf-gaussian-field.md"],"source":"user pointed out fractal rendering and Mimir sensor fusion both accumulate surface/volume confidence into temporal reservoirs"} diff --git a/state/map.yaml b/state/map.yaml index f422b03..6e5f4dc 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -111,6 +111,7 @@ renderer_state: - Global GraphicsSettings document feeding render debug, exposure, bloom intensity, and bloom veil. - Temporal resolve uses scene color, metadata, and control history only; dormant event history lanes are cut until a real producer and consumer contract exists. - Aquarium owns the temporal SDF Gaussian field renderer boundary: clients can publish `AquariumTemporalGaussianField`, `TemporalGaussianAccumulator` can buffer stable keyed observations in world space, and D3D12 lowers those packets into an instanced compact-kernel splat pass that writes normal scene color/travel/metadata/control targets. + - Temporal Gaussian accumulation now lowers through `TemporalSpatialEvidenceReservoir`, a renderer-agnostic stable-key reservoir for confidence-weighted spatial samples with presentation delay, smoothing, velocity prediction, expiry, and max-track eviction. Gaussian splats are one lowering; fractal SDF probe evidence and Mimir sensor-fusion features should use the same reservoir shape when they need delayed coherence solving. - Isolated Epiphany agent preview renders run through the real D3D12 renderer from src/Aquarium.Epiphany.AgentPreview; preview isolation is owned by a preview-only scene shader, while the engine exposes only final-frame PNG capture. - Zyphos is the first nontrivial non-Epiphany client: a planetary-scale demo with spherical-domain terrain, atmospheric rim lighting, night-side glints, fixed-sky Umbros, and first-pass eclipse cadence. - Zyphos/Umbros render-scale binary constants live in src/Aquarium.Zyphos/ZyphosUmbrosSystem.cs: Umbros is modeled as a 0.9-radius mutually tidally locked twin at 8 Zyphos radii, while the dim primary star phase moves through the Zyphos-local frame. diff --git a/state/memory.json b/state/memory.json index 6c490d7..ab47d0e 100644 --- a/state/memory.json +++ b/state/memory.json @@ -80,6 +80,7 @@ "IFS LOD should choose a stable hierarchy cut from cached node summaries, not blindly score every leaf. Each node needs bounds, max form/material error, coverage/normal or gradient bounds, estimated cost, online estimator state, residency, and summary/child payload handles. Children fade in when projected contribution exceeds threshold and resident budget allows; parent summaries remain renderable fallbacks.", "The IFS contribution cache must probabilistically refresh node weights under a per-frame update budget. Use online mean/variance/confidence/sample-age state with nonzero exploration for visible or near-threshold nodes so weights converge instead of freezing stale guesses. Learned scoring may later rank update and residency priority from observed high-quality probes, but conservative summaries remain the safety authority for SDF bounds and visibility.", "Aquarium's fractal renderer and Mimir-style sensor fusion share a deeper shape: both accumulate confidence-weighted spatial evidence into temporal reservoirs, then render a resolved surface/volume field. Keep the budget planner vocabulary general enough for CPU update work, GPU packet cost, RAM residency, and SSD request pressure; do not trap the future shared machinery inside renderer-only folklore.", + "Temporal Gaussian splats lower through TemporalSpatialEvidenceReservoir: stable keyed observations become delayed, smoothed, confidence-weighted tracks with velocity prediction, expiry, and max-track eviction before backend packet lowering. Treat Gaussian fields, fractal SDF probes, and Mimir sensor-fusion features as different evidence producers for this reservoir shape, not separate accumulator folklore.", "Zyphos fractal stress data should keep authored topology richer than the first renderer backend: both Zyphos and Umbros expose lat/long, surface, object-scale, and cube-tile domains in `.aquageo`, with explicit continent/forest/tree/leaf/coast/pebble and crater/boulder/pebble recursion. The current D3D12 height-field stress table uploads 64 shaped 2D brushes and the SDF planet shaders carry separate cheap bounded quadtree-style relief.", "The `.aquageo` compiler must preserve each tile declaration as its own ownership-tree node. Collapsing every claim under the final tile makes the authored multi-domain world a lie even if the brush count looks impressive.", "Zyphos passes cube-tile domain metadata through height brush packets and binds those packets into the SDF pass. The planet shader may use authored brush packets for post-hit material/detail evaluation; traced geometry must wait for selected-cut/resident packet policy so SDF distance loops do not evaluate every brush at every step.", diff --git a/tests/Aquarium.Engine.Fractal.Tests/FractalResourceBudgetPlannerTests.cs b/tests/Aquarium.Engine.Fractal.Tests/FractalResourceBudgetPlannerTests.cs index e9f4250..2cfda3d 100644 --- a/tests/Aquarium.Engine.Fractal.Tests/FractalResourceBudgetPlannerTests.cs +++ b/tests/Aquarium.Engine.Fractal.Tests/FractalResourceBudgetPlannerTests.cs @@ -40,7 +40,7 @@ public sealed class FractalResourceBudgetPlannerTests store, frameIndex: 10); - Assert.Equal(1, plan.UpdateNodes.Length); + Assert.Single(plan.UpdateNodes); Assert.True(plan.GpuEstimatedCost <= budget.MaxGpuEstimatedCost); Assert.True(plan.Residency.ResidentNodes.Count <= budget.MaxResidentPayloads); Assert.True(plan.Residency.RequestedNodes.Count <= budget.MaxSsdRequests); diff --git a/tests/Aquarium.Engine.Fractal.Tests/TemporalSpatialEvidenceReservoirTests.cs b/tests/Aquarium.Engine.Fractal.Tests/TemporalSpatialEvidenceReservoirTests.cs new file mode 100644 index 0000000..373765e --- /dev/null +++ b/tests/Aquarium.Engine.Fractal.Tests/TemporalSpatialEvidenceReservoirTests.cs @@ -0,0 +1,98 @@ +using System.Numerics; +using Aquarium.Engine.Fractal.Temporal; + +namespace Aquarium.Engine.Fractal.Tests; + +public sealed class TemporalSpatialEvidenceReservoirTests +{ + [Fact] + public void ReservoirPredictsDelayedMotionForStableSpatialEvidence() + { + var reservoir = new TemporalSpatialEvidenceReservoir( + accumulationWindowSeconds: 2.0f, + presentationDelaySeconds: 0.5f, + smoothing: 1.0f); + + reservoir.Observe([ + Observation("feature/a", Vector3.Zero, time: 0.0f), + Observation("feature/a", new Vector3(1.0f, 0.0f, 0.0f), time: 1.0f), + ]); + + var sample = Assert.Single(reservoir.BuildSnapshot(renderTimeSeconds: 1.5f).Samples); + + Assert.Equal(new Vector3(1.0f, 0.0f, 0.0f), sample.Center); + Assert.Equal(new Vector3(1.0f, 0.0f, 0.0f), sample.Velocity); + Assert.InRange(sample.HistoryWeight, 0.99f, 1.0f); + } + + [Fact] + public void ReservoirExpiresSamplesOutsideWindow() + { + var reservoir = new TemporalSpatialEvidenceReservoir( + accumulationWindowSeconds: 1.0f, + presentationDelaySeconds: 0.0f); + reservoir.Observe([Observation("feature/old", Vector3.Zero, time: 0.0f)]); + + var snapshot = reservoir.BuildSnapshot(renderTimeSeconds: 2.0f); + + Assert.Empty(snapshot.Samples); + } + + [Fact] + public void ReservoirEvictsLowestConfidenceTracksWhenOverBudget() + { + var reservoir = new TemporalSpatialEvidenceReservoir( + accumulationWindowSeconds: 5.0f, + presentationDelaySeconds: 0.0f, + smoothing: 1.0f, + maxTrackCount: 2); + + reservoir.Observe([ + Observation("weak", Vector3.Zero, time: 0.0f, confidence: 0.2f), + Observation("strong", Vector3.One, time: 0.0f, confidence: 1.0f), + Observation("middle", new Vector3(2.0f), time: 0.0f, confidence: 0.6f), + ]); + + var keys = reservoir.BuildSnapshot(renderTimeSeconds: 0.0f).Samples.Select(sample => sample.StableKey).ToArray(); + + Assert.DoesNotContain("weak", keys); + Assert.Contains("strong", keys); + Assert.Contains("middle", keys); + } + + [Fact] + public void ReservoirPreservesRendererSpecificPayloadsWithoutOwningThem() + { + var reservoir = new TemporalSpatialEvidenceReservoir( + accumulationWindowSeconds: 5.0f, + presentationDelaySeconds: 0.0f); + var payload0 = new Vector4(0.2f, 0.4f, 0.6f, 0.8f); + var payload1 = new Vector4(4.0f, 1.5f, 0.0f, 0.0f); + + reservoir.Observe([Observation("feature/payload", Vector3.Zero, time: 0.0f, payload0: payload0, payload1: payload1)]); + + var sample = Assert.Single(reservoir.BuildSnapshot(renderTimeSeconds: 0.0f).Samples); + Assert.Equal(payload0, sample.Payload0); + Assert.Equal(payload1, sample.Payload1); + } + + private static TemporalSpatialEvidenceObservation Observation( + string key, + Vector3 center, + float time, + float confidence = 1.0f, + Vector4? payload0 = null, + Vector4? payload1 = null) + { + return new TemporalSpatialEvidenceObservation( + key, + center, + new Vector3(0.1f), + Quaternion.Identity, + payload0 ?? Vector4.One, + payload1 ?? Vector4.Zero, + confidence, + time, + FieldId: 3); + } +}