diff --git a/research/rendering/fractal-brush-implementation-roadmap.md b/research/rendering/fractal-brush-implementation-roadmap.md index fbe6e20..b1f8314 100644 --- a/research/rendering/fractal-brush-implementation-roadmap.md +++ b/research/rendering/fractal-brush-implementation-roadmap.md @@ -378,7 +378,8 @@ Tasks: - [x] Route Zyphos render-plan construction through the resource budget planner. - [x] Update Zyphos contribution cache every render-plan request while reusing compiled brush packets for equivalent selected cuts. -- [ ] Feed traced planet geometry from selected-cut/resident tile packets. +- [x] Feed traced planet geometry from a hard-budgeted top-influence subset of + selected tile packets. - [ ] Add face/tile/LOD/cache debug modes. - [ ] Remove or quarantine old spherical noise path as baseline fixture. diff --git a/src/Aquarium.Zyphos/Shaders/D3D12ZyphosPlanet.hlsl b/src/Aquarium.Zyphos/Shaders/D3D12ZyphosPlanet.hlsl index 999b21f..10faadf 100644 --- a/src/Aquarium.Zyphos/Shaders/D3D12ZyphosPlanet.hlsl +++ b/src/Aquarium.Zyphos/Shaders/D3D12ZyphosPlanet.hlsl @@ -1,4 +1,5 @@ static const int SDF_INDEX = 0; +static const int ZYPHOS_GEOMETRY_BRUSH_LIMIT = 4; #include "D3D12SdfCommon.hlsli" #include "D3D12SdfMath.hlsli" @@ -111,14 +112,15 @@ float2 zyTileBrushPlane(float2 faceUv, float level, float tileX, float tileY, ou return (local01 * 2.0 - 1.0) * 30.0; } -float zyAuthoredBrushTerrain(float3 dir, out float materialMask) +float zyAuthoredBrushTerrainLimited(float3 dir, int brushLimit, out float materialMask) { float face; float2 faceUv = zyCubeFaceUv(dir, face); float height = 0.0; materialMask = 0.0; - for (int index = 0; index < 64; index++) + [loop] + for (int index = 0; index < brushLimit; index++) { float4 centerRadius = brushCenterRadius[index]; float4 shape = brushShape[index]; @@ -144,6 +146,11 @@ float zyAuthoredBrushTerrain(float3 dir, out float materialMask) return height; } +float zyAuthoredBrushTerrain(float3 dir, out float materialMask) +{ + return zyAuthoredBrushTerrainLimited(dir, 64, materialMask); +} + float zyTileRelief(float2 uv, float level, float amplitude, float ridgeBias) { float scale = exp2(level); @@ -200,8 +207,10 @@ float zyTerrainOffset(float3 dir, SdfObject sdfObject) float land = smoothstep(seaLevel - 0.04, seaLevel + 0.08, field); float mountain = pow(saturate(field - seaLevel), 1.65); float polarCap = pow(abs(dir.z), 8.0) * 0.035; + float authoredMaterial; + float authoredGeometry = zyAuthoredBrushTerrainLimited(dir, ZYPHOS_GEOMETRY_BRUSH_LIMIT, authoredMaterial); float tileRelief = zyQuadtreeSdfRelief(dir) * land + zyLeafCluster(dir) * 0.018 + zyPebbleCluster(dir) * 0.010; - return (field - seaLevel) * 0.10 + mountain * 0.13 + polarCap * land + tileRelief; + return (field - seaLevel) * 0.10 + mountain * 0.13 + polarCap * land + tileRelief + authoredGeometry * 0.52; } float sdfDistance(float3 p, int sdfIndex) diff --git a/src/Aquarium.Zyphos/ZyphosFractalTerrain.cs b/src/Aquarium.Zyphos/ZyphosFractalTerrain.cs index 647989d..20204a6 100644 --- a/src/Aquarium.Zyphos/ZyphosFractalTerrain.cs +++ b/src/Aquarium.Zyphos/ZyphosFractalTerrain.cs @@ -60,7 +60,7 @@ public static class ZyphosFractalTerrain { if (!BrushCache.TryGetValue(cutKey, out brushes!)) { - brushes = FractalHeightBrushCompiler.CompileSelectedTree(Tree.Value, selectedCut); + brushes = OrderBrushesForGeometry(FractalHeightBrushCompiler.CompileSelectedTree(Tree.Value, selectedCut)); BrushCache[cutKey] = brushes; } } @@ -78,6 +78,17 @@ public static class ZyphosFractalTerrain return string.Join("|", selectedCut.Select(cut => cut.NodeKey.Value)); } + private static AquariumHeightFieldBrush[] OrderBrushesForGeometry(AquariumHeightFieldBrush[] brushes) + { + return brushes + .OrderByDescending(brush => MathF.Abs(brush.Amplitude) * MathF.Max(brush.Radius, brush.RadiusY)) + .ThenBy(brush => brush.DomainFace) + .ThenBy(brush => brush.DomainLevel) + .ThenBy(brush => brush.Center.X) + .ThenBy(brush => brush.Center.Y) + .ToArray(); + } + public static string Summary => $"{Path.GetFileName(PatchPath)} / {OwnershipTree.Claims.Count} DSL claims / {OwnershipTree.Nodes.Count} tile nodes / {SelectedCut.Value.Length} cuts / {HeightBrushes.Length} shaped brushes"; diff --git a/state/evidence.jsonl b/state/evidence.jsonl index e2fe357..dff7d2a 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -156,3 +156,4 @@ {"timestamp":"2026-05-19T15:12:00+01:00","topic":"localcast-shared-temporal-reservoir","lesson":"LocalCast fallback GPU fusion history now delegates to `TemporalSpatialEvidenceReservoir`. `LocalCastGpuFusionAccumulator` maps LocalCast GPU fusion seeds into shared evidence observations and lowers reservoir samples back into `AquariumGpuFusionSeed`; it no longer owns separate stable-key history, smoothing, expiry, or max-count logic. This is the first consumer-side takeover of duplicated temporal reservoir code.","files":["src/Aquarium.LocalCast/LocalCastGpuFusionAccumulator.cs","src/Aquarium.Engine.Fractal/Temporal/TemporalSpatialEvidenceReservoir.cs","docs/temporal-sdf-gaussian-field.md"],"source":"user made Aquarium responsible for resolving temporal reservoir sampling architecturally and taking over consumer half-versions"} {"timestamp":"2026-05-19T15:29:00+01:00","topic":"temporal-evidence-lowering-boundary","lesson":"Shared temporal evidence now has named lowering helpers. `TemporalSpatialEvidenceLowering` converts Gaussian observations and GPU fusion seeds to/from reservoir samples, so consumer adapters do not privately pack Payload0/Payload1 conventions. Keep new reservoir consumers on this lowering seam unless they need a genuinely new payload contract.","files":["src/Aquarium.Engine.Fractal/Temporal/TemporalSpatialEvidenceLowering.cs","src/Aquarium.Engine.Fractal/Temporal/TemporalGaussianAccumulator.cs","src/Aquarium.LocalCast/LocalCastGpuFusionAccumulator.cs","tests/Aquarium.Engine.Fractal.Tests/TemporalSpatialEvidenceLoweringTests.cs"],"source":"follow-up after moving LocalCast history onto the shared reservoir; adapter payload packing needed to become a tested engine boundary"} {"timestamp":"2026-05-19T15:46:00+01:00","topic":"temporal-reservoir-ownership-contract","lesson":"The temporal spatial evidence reservoir now has an explicit architecture contract. Raw sample reservoirs keep capture-time handles and ordering; Aquarium's `TemporalSpatialEvidenceReservoir` owns stable resolved spatial history; `TemporalSpatialEvidenceLowering` owns backend packet conversion; TAA owns pixel history. This prevents consumer repos from growing parallel half-reservoirs while preserving LocalCastBridge's lower-level raw rolling reservoir authority.","files":["docs/temporal-spatial-evidence-reservoir.md","state/map.yaml","state/memory.json"],"source":"user made Aquarium responsible for resolving temporal reservoir sampling architecturally across consumer repos"} +{"timestamp":"2026-05-19T16:11:00+01:00","topic":"zyphos-budgeted-fractal-geometry","lesson":"Authored fractal packets now affect Zyphos traced planet geometry, but only through a hard-budgeted top-influence subset. Selected height brushes are sorted by abs(amplitude)*max(radius), `sdfDistance` samples the first four, and `sdfSurface` still evaluates the full selected packet table for material/detail. A 12-brush geometry loop was tested and cut after pushing the live frame to about 33 ms; the four-brush budget returns the live view to about 16.4 ms after shader pipelines are ready.","files":["src/Aquarium.Zyphos/ZyphosFractalTerrain.cs","src/Aquarium.Zyphos/Shaders/D3D12ZyphosPlanet.hlsl","tests/Aquarium.Engine.Fractal.Tests/ZyphosFractalTerrainTests.cs"],"source":"runtime proof after moving authored fractal packet evaluation into the hot SDF distance path"} diff --git a/state/memory.json b/state/memory.json index 6bc4cd7..5cbc53b 100644 --- a/state/memory.json +++ b/state/memory.json @@ -87,6 +87,7 @@ "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.", + "Zyphos traced planet geometry may sample only a hard-budgeted top-influence subset of authored fractal brush packets in `sdfDistance`; the current proven budget is four brushes after sorting selected packets by abs(amplitude)*max(radius). A 12-brush distance loop was tested and rejected because it pushed the live frame to about 33 ms; the four-brush loop returns the live view to about 16.4 ms while full packet richness remains available to post-hit material/detail.", "Temporal resolve has a cache-facing detail lane: SdfSurface.temporalDetail writes through scene-control.z into history-control.z, and D3D12Post reduces history confidence when current and previous temporal detail disagree. Use this lane for stochastic fractal/cache stability signals, not as geometry authority.", "FractalContributionCache is the live cache loop: each frame builds a resource plan from current summaries and cached states, stochastically observes only budgeted update nodes, stores mean/variance/confidence/sample age through FractalContributionEstimator, and lets backend packet compilation stay cached by selected-cut key. Do not replace this with a static plan cache that stops learning after the first camera bucket.", "Zyphos camera distance limits belong to the selected spatial domain, not one global planetary clamp. Leaf/pebble domains must be able to zoom below whole-body distances, and the parent star must be a visible SDF body when it is also the primary light source.", diff --git a/tests/Aquarium.Engine.Fractal.Tests/ZyphosFractalTerrainTests.cs b/tests/Aquarium.Engine.Fractal.Tests/ZyphosFractalTerrainTests.cs index 81c9e45..01edd56 100644 --- a/tests/Aquarium.Engine.Fractal.Tests/ZyphosFractalTerrainTests.cs +++ b/tests/Aquarium.Engine.Fractal.Tests/ZyphosFractalTerrainTests.cs @@ -53,6 +53,8 @@ public sealed class ZyphosFractalTerrainTests Assert.Contains("gpu cost", near.Summary, StringComparison.Ordinal); Assert.Contains("resident", near.Summary, StringComparison.Ordinal); Assert.Empty(near.ResourcePlan.Residency.RequestedNodes); + Assert.True(MathF.Abs(near.HeightBrushes[0].Amplitude) * MathF.Max(near.HeightBrushes[0].Radius, near.HeightBrushes[0].RadiusY) >= + MathF.Abs(near.HeightBrushes[^1].Amplitude) * MathF.Max(near.HeightBrushes[^1].Radius, near.HeightBrushes[^1].RadiusY)); } [Fact]