diff --git a/research/rendering/fractal-brush-implementation-roadmap.md b/research/rendering/fractal-brush-implementation-roadmap.md index ba63f28..9ba4ba9 100644 --- a/research/rendering/fractal-brush-implementation-roadmap.md +++ b/research/rendering/fractal-brush-implementation-roadmap.md @@ -219,6 +219,8 @@ Tasks: - [ ] Implement operation bounds. - [x] Add flattening compiler to shaped 2D brush packets. - [x] Add debug dump for authored tree and flattened packets. +- [x] Preserve multiple `.aquageo` tile roots in the ownership tree instead of + collapsing every claim under the final tile. Tests: @@ -362,7 +364,9 @@ Tasks: - [x] Add Zyphos cube-sphere domain root. - [x] Add first tile grammar: ridges, craters, and material bands. - [x] Lower selected cut to shaped 2D height/material brush packets. -- [ ] Feed planet shader from tile-local domain. +- [x] Feed planet shader from tile-local cube-face domains for post-hit + material/detail evaluation. +- [ ] Feed traced planet geometry from selected-cut/resident tile packets. - [ ] Add face/tile/LOD/cache debug modes. - [ ] Remove or quarantine old spherical noise path as baseline fixture. diff --git a/src/Aquarium.Engine.Contracts/Render/AquariumRenderPlan.cs b/src/Aquarium.Engine.Contracts/Render/AquariumRenderPlan.cs index 094890c..d8319b6 100644 --- a/src/Aquarium.Engine.Contracts/Render/AquariumRenderPlan.cs +++ b/src/Aquarium.Engine.Contracts/Render/AquariumRenderPlan.cs @@ -227,7 +227,11 @@ public readonly record struct AquariumHeightFieldBrush( float WaveSinePower, float RadiusY = 0.0f, float RotationRadians = 0.0f, - float EnvelopeFalloff = 0.0f); + float EnvelopeFalloff = 0.0f, + float DomainFace = -1.0f, + float DomainLevel = 0.0f, + float DomainX = 0.0f, + float DomainY = 0.0f); public sealed class AquariumSceneState { diff --git a/src/Aquarium.Engine.Fractal/Brushes/FractalHeightBrushCompiler.cs b/src/Aquarium.Engine.Fractal/Brushes/FractalHeightBrushCompiler.cs index 643bcfa..1e60b76 100644 --- a/src/Aquarium.Engine.Fractal/Brushes/FractalHeightBrushCompiler.cs +++ b/src/Aquarium.Engine.Fractal/Brushes/FractalHeightBrushCompiler.cs @@ -1,10 +1,16 @@ using Aquarium.Engine.Render; +using Aquarium.Engine.Fractal.Grammar; namespace Aquarium.Engine.Fractal.Brushes; public static class FractalHeightBrushCompiler { public static AquariumHeightFieldBrush Compile(AquariumBrushClaim claim) + { + return Compile(claim, null); + } + + public static AquariumHeightFieldBrush Compile(AquariumBrushClaim claim, AquariumFractalDomain? domain) { if (claim.PayloadKind != AquariumFractalPayloadKind.Height) { @@ -27,7 +33,11 @@ public static class FractalHeightBrushCompiler WaveSinePower: 0.0f, RadiusY: claim.Radii.Y, RotationRadians: claim.RotationRadians, - EnvelopeFalloff: claim.Falloff); + EnvelopeFalloff: claim.Falloff, + DomainFace: domain is { Kind: AquariumFractalDomainKind.CubeSphereTile } ? domain.Value.Parameters0.X : -1.0f, + DomainLevel: domain is { Kind: AquariumFractalDomainKind.CubeSphereTile } ? domain.Value.Parameters0.Y : 0.0f, + DomainX: domain is { Kind: AquariumFractalDomainKind.CubeSphereTile } ? domain.Value.Parameters0.Z : 0.0f, + DomainY: domain is { Kind: AquariumFractalDomainKind.CubeSphereTile } ? domain.Value.Parameters0.W : 0.0f); } public static AquariumHeightFieldBrush[] CompileMany(IReadOnlyList claims) @@ -42,4 +52,20 @@ public static class FractalHeightBrushCompiler return brushes; } + + public static AquariumHeightFieldBrush[] CompileTree(FractalOwnershipTree tree) + { + ArgumentNullException.ThrowIfNull(tree); + + var domains = tree.Domains.ToDictionary(domain => domain.Key, domain => domain); + var brushes = new AquariumHeightFieldBrush[tree.Claims.Count]; + for (var index = 0; index < tree.Claims.Count; index++) + { + var claim = tree.Claims[index]; + domains.TryGetValue(claim.DomainKey, out var domain); + brushes[index] = Compile(claim, domain); + } + + return brushes; + } } diff --git a/src/Aquarium.Engine.Fractal/Grammar/FractalDslCompiler.cs b/src/Aquarium.Engine.Fractal/Grammar/FractalDslCompiler.cs index fbabcb2..b0c7e69 100644 --- a/src/Aquarium.Engine.Fractal/Grammar/FractalDslCompiler.cs +++ b/src/Aquarium.Engine.Fractal/Grammar/FractalDslCompiler.cs @@ -13,8 +13,10 @@ public static class FractalDslCompiler var lines = source.Replace("\r\n", "\n", StringComparison.Ordinal).Split('\n'); AquariumFractalDomain? domain = null; AquariumFractalKey rootKey = default; + NodeDraft? currentNode = null; var domains = new List(); var claims = new List(); + var nodes = new List(); for (var lineIndex = 0; lineIndex < lines.Length; lineIndex++) { @@ -44,16 +46,26 @@ public static class FractalDslCompiler new Vector4((float)tile.Face, tile.Level, tile.X, tile.Y), Vector4.Zero); domains.Add(domain.Value); + rootKey = FractalStableKeyBuilder.Child(domainKey, "root"); + currentNode = new NodeDraft(rootKey, domainKey, claims.Count); + nodes.Add(currentNode); break; case "height": EnsureDomain(domain, lineIndex); + EnsureNode(currentNode, lineIndex); EnsureTokenCount(tokens, 12, lineIndex); - claims.Add(ParseHeight(tokens, rootKey, lineIndex, claims.Count)); + var heightDomain = domain!.Value; + claims.Add(ParseHeight(tokens, heightDomain.Key, currentNode!.Key, lineIndex, claims.Count - currentNode.FirstClaimIndex)); + currentNode.ClaimCount++; break; case "ifs": EnsureDomain(domain, lineIndex); + EnsureNode(currentNode, lineIndex); EnsureTokenCount(tokens, 15, lineIndex); - AddIfsClaims(tokens, rootKey, lineIndex, claims); + var ifsDomain = domain!.Value; + var beforeIfs = claims.Count; + AddIfsClaims(tokens, ifsDomain.Key, currentNode!.Key, lineIndex, claims); + currentNode.ClaimCount += claims.Count - beforeIfs; break; default: throw new FormatException($"Unknown fractal DSL command `{tokens[0]}` at line {lineIndex + 1}."); @@ -65,7 +77,7 @@ public static class FractalDslCompiler throw new FormatException("Fractal DSL must declare a `tile ` line before claims."); } - return FractalOwnershipTreeBuilder.BuildFlatUnion(domain.Value, domains, rootKey, claims); + return new FractalOwnershipTree(domain.Value, domains, BuildNodes(nodes, claims), claims); } private static AquariumFractalDomain ParseDomain(string[] tokens, int lineIndex) @@ -90,11 +102,12 @@ public static class FractalDslCompiler new Vector4(parameters[4], parameters[5], parameters[6], parameters[7])); } - private static AquariumBrushClaim ParseHeight(string[] tokens, AquariumFractalKey rootKey, int lineIndex, int claimIndex) + private static AquariumBrushClaim ParseHeight(string[] tokens, AquariumFractalKey domainKey, AquariumFractalKey nodeKey, int lineIndex, int claimIndex) { var name = tokens[1]; return HeightClaim( - rootKey, + domainKey, + nodeKey, name, claimIndex, new Vector2(ParseFloat(tokens[2], lineIndex), ParseFloat(tokens[3], lineIndex)), @@ -107,7 +120,7 @@ public static class FractalDslCompiler tokens[11]); } - private static void AddIfsClaims(string[] tokens, AquariumFractalKey rootKey, int lineIndex, List claims) + private static void AddIfsClaims(string[] tokens, AquariumFractalKey domainKey, AquariumFractalKey nodeKey, int lineIndex, List claims) { var name = tokens[1]; var levels = ParsePositiveInt(tokens[2], lineIndex); @@ -128,11 +141,12 @@ public static class FractalDslCompiler throw new FormatException($"IFS child scale must be below 1 at line {lineIndex + 1}."); } - EmitIfsLevel(rootKey, name, center, radii, levels, branches, childScale, spread, rotationStep, falloff, shapePower, amplitude, seed, tags, claims); + EmitIfsLevel(domainKey, nodeKey, name, center, radii, levels, branches, childScale, spread, rotationStep, falloff, shapePower, amplitude, seed, tags, claims); } private static void EmitIfsLevel( - AquariumFractalKey rootKey, + AquariumFractalKey domainKey, + AquariumFractalKey nodeKey, string name, Vector2 center, Vector2 radii, @@ -149,7 +163,7 @@ public static class FractalDslCompiler List claims) { var level = claims.Count; - claims.Add(HeightClaim(rootKey, $"{name}/{level}", claims.Count, center, radii, rotationStep * level, falloff, shapePower, amplitude, seed + level, tags)); + claims.Add(HeightClaim(domainKey, nodeKey, $"{name}/{level}", claims.Count, center, radii, rotationStep * level, falloff, shapePower, amplitude, seed + level, tags)); if (levelsRemaining <= 1) { @@ -162,7 +176,8 @@ public static class FractalDslCompiler var phase = ((MathF.Tau * branch) / branches) + rotationStep * level + HashAngle(seed, level, branch); var offset = new Vector2(MathF.Cos(phase), MathF.Sin(phase)) * spread * MathF.Max(nextRadii.X, nextRadii.Y); EmitIfsLevel( - rootKey, + domainKey, + nodeKey, name, center + offset, nextRadii, @@ -181,7 +196,8 @@ public static class FractalDslCompiler } private static AquariumBrushClaim HeightClaim( - AquariumFractalKey rootKey, + AquariumFractalKey domainKey, + AquariumFractalKey nodeKey, string name, int claimIndex, Vector2 center, @@ -194,9 +210,9 @@ public static class FractalDslCompiler string tags) { return new AquariumBrushClaim( - FractalStableKeyBuilder.Child(rootKey, $"claim/{claimIndex:0000}/{name}"), - rootKey, - rootKey, + FractalStableKeyBuilder.Child(nodeKey, $"claim/{claimIndex:0000}/{name}"), + domainKey, + nodeKey, AquariumFractalPayloadKind.Height, center, radii, @@ -230,6 +246,61 @@ public static class FractalDslCompiler } } + private static void EnsureNode(NodeDraft? node, int lineIndex) + { + if (node is null) + { + throw new FormatException($"Fractal DSL claim at line {lineIndex + 1} appears before a tile root was created."); + } + } + + private static AquariumFractalNode[] BuildNodes(IReadOnlyList drafts, IReadOnlyList claims) + { + var nodes = new AquariumFractalNode[drafts.Count]; + for (var nodeIndex = 0; nodeIndex < drafts.Count; nodeIndex++) + { + var draft = drafts[nodeIndex]; + nodes[nodeIndex] = new AquariumFractalNode( + draft.Key, + draft.DomainKey, + default, + AquariumFractalOperation.Union, + FirstChildIndex: 0, + ChildCount: 0, + draft.FirstClaimIndex, + draft.ClaimCount, + BoundsForClaims(claims, draft.FirstClaimIndex, draft.ClaimCount), + Seed: 0); + } + + return nodes; + } + + private static Vector4 BoundsForClaims(IReadOnlyList claims, int firstClaimIndex, int claimCount) + { + if (claimCount == 0) + { + return Vector4.Zero; + } + + var minX = float.PositiveInfinity; + var minY = float.PositiveInfinity; + var maxX = float.NegativeInfinity; + var maxY = float.NegativeInfinity; + + for (var index = firstClaimIndex; index < firstClaimIndex + claimCount; index++) + { + var claim = claims[index]; + var radius = MathF.Max(claim.Radii.X, claim.Radii.Y); + minX = MathF.Min(minX, claim.Center.X - radius); + minY = MathF.Min(minY, claim.Center.Y - radius); + maxX = MathF.Max(maxX, claim.Center.X + radius); + maxY = MathF.Max(maxY, claim.Center.Y + radius); + } + + return new Vector4(minX, minY, maxX, maxY); + } + private static CubeFace ParseFace(string value, int lineIndex) { if (Enum.TryParse(value, ignoreCase: false, out var face)) @@ -291,4 +362,15 @@ public static class FractalDslCompiler var normalized = (value & 0xFFFF) / 65535.0f; return (normalized - 0.5f) * 0.35f; } + + private sealed class NodeDraft(AquariumFractalKey key, AquariumFractalKey domainKey, int firstClaimIndex) + { + public AquariumFractalKey Key { get; } = key; + + public AquariumFractalKey DomainKey { get; } = domainKey; + + public int FirstClaimIndex { get; } = firstClaimIndex; + + public int ClaimCount { get; set; } + } } diff --git a/src/Aquarium.Engine/Render/D3D12Renderer.cs b/src/Aquarium.Engine/Render/D3D12Renderer.cs index b5a9679..8c21a2c 100644 --- a/src/Aquarium.Engine/Render/D3D12Renderer.cs +++ b/src/Aquarium.Engine/Render/D3D12Renderer.cs @@ -1200,6 +1200,7 @@ public sealed class D3D12Renderer : IAquariumRenderer context.CommandList.SetGraphicsRootSignature(fullscreenRootSignature); context.CommandList.SetGraphicsRootDescriptorTable(RootFrameConstants, frameResources.FrameConstantsDescriptor.Gpu); context.CommandList.SetGraphicsRootDescriptorTable(RootSourceTexture, frameResources.HeightFieldDescriptor.Gpu); + context.CommandList.SetGraphicsRootDescriptorTable(RootHeightFieldBrushes, frameResources.HeightFieldBrushConstantsDescriptor.Gpu); context.CommandList.SetGraphicsRootDescriptorTable(RootSdfLights, frameResources.SdfLightDescriptor.Gpu); context.CommandList.SetGraphicsRootDescriptorTable(RootStudioPmrem, frameResources.StudioPmremDescriptor.Gpu); context.CommandList.SetGraphicsRootDescriptorTable(RootStudioIrradiance, frameResources.StudioIrradianceDescriptor.Gpu); diff --git a/src/Aquarium.Engine/Render/Features/D3D12HeightFieldBrushConstants.cs b/src/Aquarium.Engine/Render/Features/D3D12HeightFieldBrushConstants.cs index c90f025..8ed8328 100644 --- a/src/Aquarium.Engine/Render/Features/D3D12HeightFieldBrushConstants.cs +++ b/src/Aquarium.Engine/Render/Features/D3D12HeightFieldBrushConstants.cs @@ -9,7 +9,7 @@ internal struct D3D12HeightFieldBrushConstants { public const int MaxBrushCount = 64; - private const int VectorCount = MaxBrushCount * 3; + private const int VectorCount = MaxBrushCount * 4; private VectorTable values; @@ -25,13 +25,14 @@ internal struct D3D12HeightFieldBrushConstants index, new Vector4(brush.Center, brush.Radius, radiusY), new Vector4(brush.Power, brush.Amplitude, brush.RotationRadians, brush.EnvelopeFalloff), - new Vector4(brush.WaveAmplitude, brush.WaveFrequency, brush.WaveSpeed, brush.WaveSinePower)); + new Vector4(brush.WaveAmplitude, brush.WaveFrequency, brush.WaveSpeed, brush.WaveSinePower), + new Vector4(brush.DomainFace, brush.DomainLevel, brush.DomainX, brush.DomainY)); } return constants; } - private void Set(int brushIndex, Vector4 centerRadius, Vector4 shape, Vector4 wave) + private void Set(int brushIndex, Vector4 centerRadius, Vector4 shape, Vector4 wave, Vector4 domain) { if ((uint)brushIndex >= MaxBrushCount) { @@ -41,6 +42,7 @@ internal struct D3D12HeightFieldBrushConstants SetVector(brushIndex, centerRadius); SetVector(MaxBrushCount + brushIndex, shape); SetVector(MaxBrushCount * 2 + brushIndex, wave); + SetVector(MaxBrushCount * 3 + brushIndex, domain); } private void SetVector(int index, Vector4 value) diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12HeightField.hlsl b/src/Aquarium.Engine/Render/Shaders/D3D12HeightField.hlsl index aaa50be..517c22d 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12HeightField.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/D3D12HeightField.hlsl @@ -29,6 +29,7 @@ cbuffer HeightFieldBrushes : register(b1) float4 brushCenterRadius[64]; float4 brushShape[64]; float4 brushWave[64]; + float4 brushDomain[64]; }; struct VertexOut diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12SdfCommon.hlsli b/src/Aquarium.Engine/Render/Shaders/D3D12SdfCommon.hlsli index b5e3d04..3ea29cd 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12SdfCommon.hlsli +++ b/src/Aquarium.Engine/Render/Shaders/D3D12SdfCommon.hlsli @@ -24,6 +24,14 @@ cbuffer AquariumFrame : register(b0) float4 cursorWorlds; }; +cbuffer HeightFieldBrushes : register(b1) +{ + float4 brushCenterRadius[64]; + float4 brushShape[64]; + float4 brushWave[64]; + float4 brushDomain[64]; +}; + TextureCube studioPmremTexture : register(t22); TextureCube studioIrradianceTexture : register(t23); SamplerState linearSampler : register(s0); diff --git a/src/Aquarium.Zyphos/Shaders/D3D12ZyphosPlanet.hlsl b/src/Aquarium.Zyphos/Shaders/D3D12ZyphosPlanet.hlsl index b512142..60d8fa6 100644 --- a/src/Aquarium.Zyphos/Shaders/D3D12ZyphosPlanet.hlsl +++ b/src/Aquarium.Zyphos/Shaders/D3D12ZyphosPlanet.hlsl @@ -47,6 +47,103 @@ float zyHash21(float2 p) return frac(p.x * p.y); } +float zyCompactBrush(float2 delta, float2 radii, float rotation, float falloff, float shapePower) +{ + float c = cos(rotation); + float s = sin(rotation); + float2 local = float2(delta.x * c + delta.y * s, -delta.x * s + delta.y * c); + float2 normalized = local / max(radii, float2(0.001, 0.001)); + float r2 = dot(normalized, normalized); + if (r2 >= 1.0) + { + return 0.0; + } + + float edgeValue = exp(-falloff); + float gaussianValue = exp(-falloff * r2); + float compactValue = (gaussianValue - edgeValue) / max(1.0 - edgeValue, 0.000001); + return pow(saturate(compactValue), shapePower); +} + +float2 zyCubeFaceUv(float3 dir, out float face) +{ + float3 a = abs(dir); + if (a.x >= a.y && a.x >= a.z) + { + if (dir.x >= 0.0) + { + face = 0.0; + return float2(-dir.z, dir.y) / max(a.x, 0.0001); + } + + face = 1.0; + return float2(dir.z, dir.y) / max(a.x, 0.0001); + } + + if (a.y >= a.z) + { + if (dir.y >= 0.0) + { + face = 2.0; + return float2(dir.x, -dir.z) / max(a.y, 0.0001); + } + + face = 3.0; + return float2(dir.x, dir.z) / max(a.y, 0.0001); + } + + if (dir.z >= 0.0) + { + face = 4.0; + return dir.xy / max(a.z, 0.0001); + } + + face = 5.0; + return float2(-dir.x, dir.y) / max(a.z, 0.0001); +} + +float2 zyTileBrushPlane(float2 faceUv, float level, float tileX, float tileY, out float inTile) +{ + float axisTiles = exp2(level); + float2 local01 = (faceUv * 0.5 + 0.5) * axisTiles - float2(tileX, tileY); + float2 inside = step(float2(0.0, 0.0), local01) * step(local01, float2(1.0, 1.0)); + inTile = inside.x * inside.y; + return (local01 * 2.0 - 1.0) * 30.0; +} + +float zyAuthoredBrushTerrain(float3 dir, out float materialMask) +{ + float face; + float2 faceUv = zyCubeFaceUv(dir, face); + float height = 0.0; + materialMask = 0.0; + + for (int index = 0; index < 64; index++) + { + float4 centerRadius = brushCenterRadius[index]; + float4 shape = brushShape[index]; + float4 domain = brushDomain[index]; + if (centerRadius.z <= 0.0 || abs(domain.x - face) > 0.25) + { + continue; + } + + float inTile; + float2 plane = zyTileBrushPlane(faceUv, domain.y, domain.z, domain.w, inTile); + if (inTile <= 0.0) + { + continue; + } + + float2 radii = float2(centerRadius.z, centerRadius.w > 0.0 ? centerRadius.w : centerRadius.z); + float weight = zyCompactBrush(plane - centerRadius.xy, radii, shape.z, max(shape.w, 0.001), max(shape.x, 0.001)); + height += shape.y * weight; + materialMask = max(materialMask, abs(shape.y) * weight); + } + + return height; +} + float zyTileRelief(float2 uv, float level, float amplitude, float ridgeBias) { float scale = exp2(level); @@ -126,6 +223,8 @@ SdfSurface sdfSurface(float3 p, int sdfIndex) float land = smoothstep(seaLevel - 0.03, seaLevel + 0.06, field); float mountain = smoothstep(seaLevel + 0.12, seaLevel + 0.28, field); float tileRelief = zyQuadtreeSdfRelief(dir); + float authoredMaterial; + float authoredHeight = zyAuthoredBrushTerrain(dir, authoredMaterial); float leafCluster = zyLeafCluster(dir); float pebbleCluster = zyPebbleCluster(dir); float polar = smoothstep(0.72, 0.92, abs(dir.z)); @@ -138,6 +237,7 @@ SdfSurface sdfSurface(float3 p, int sdfIndex) float3 landColor = lerp(lowland, highland, mountain); landColor = lerp(landColor, snow, saturate(polar + mountain * 0.38)); landColor = lerp(landColor, float3(0.62, 0.54, 0.36), saturate(tileRelief * 14.0)); + landColor = lerp(landColor, float3(0.78, 0.56, 0.30), saturate(authoredMaterial * 2.6 + authoredHeight * 5.0)); landColor = lerp(landColor, float3(0.025, 0.24, 0.08), leafCluster * 0.82); landColor = lerp(landColor, float3(0.42, 0.39, 0.34), pebbleCluster * 0.65); diff --git a/src/Aquarium.Zyphos/ZyphosFractalTerrain.cs b/src/Aquarium.Zyphos/ZyphosFractalTerrain.cs index 3a889e2..db62564 100644 --- a/src/Aquarium.Zyphos/ZyphosFractalTerrain.cs +++ b/src/Aquarium.Zyphos/ZyphosFractalTerrain.cs @@ -15,7 +15,7 @@ public static class ZyphosFractalTerrain private static readonly Lazy Tree = new(() => FractalDslCompiler.Compile(PatchSource.Value)); private static readonly Lazy Summaries = new(() => FractalSummaryBuilder.Build(Tree.Value)); private static readonly Lazy SelectedCut = new(() => FractalSelectedCutBuilder.Build(Summaries.Value, _ => 8.0f, maxEstimatedCost: 8.0f)); - private static readonly Lazy Brushes = new(() => FractalHeightBrushCompiler.CompileMany(Tree.Value.Claims)); + private static readonly Lazy Brushes = new(() => FractalHeightBrushCompiler.CompileTree(Tree.Value)); public static string PatchPath => Path.Combine(AppContext.BaseDirectory, PatchRelativePath); @@ -23,8 +23,12 @@ public static class ZyphosFractalTerrain public static AquariumHeightFieldBrush[] HeightBrushes => Brushes.Value; + public static AquariumFractalSummary[] NodeSummaries => Summaries.Value; + + public static AquariumSelectedCut[] SelectedCuts => SelectedCut.Value; + public static string DebugDump => FractalDebugDump.Build(OwnershipTree, Summaries.Value, SelectedCut.Value); public static string Summary => - $"{Path.GetFileName(PatchPath)} / {OwnershipTree.Claims.Count} DSL claims / {OwnershipTree.Nodes.Count} node / {SelectedCut.Value.Length} cuts / {HeightBrushes.Length} shaped brushes"; + $"{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 2bf021f..1261295 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -146,3 +146,4 @@ {"timestamp":"2026-05-18T05:13:27+01:00","topic":"zyphos-umbros-fractal-stress-domains","lesson":"Zyphos and Umbros should both be first-class selectable fractal bodies. The `.aquageo` patch now declares Umbros lat/long plus multiple cube-tile children for both bodies and emits 31 shaped brush claims. D3D12 height-field brush constants were expanded to a deliberate 32-entry fixed table so stress data is not silently clipped at 16. Planet and Umbros SDF shaders also add cheap bounded quadtree-style object-space relief for layered geometry independent of the flattened 2D brush backend.","files":["src/Aquarium.Zyphos/Worlds/zyphos-first-fractal-terrain.aquageo","src/Aquarium.Zyphos/ZyphosSpatialDomainCatalog.cs","src/Aquarium.Engine/Render/Features/D3D12HeightFieldBrushConstants.cs","src/Aquarium.Engine/Render/Shaders/D3D12HeightField.hlsl","src/Aquarium.Zyphos/Shaders/D3D12ZyphosPlanet.hlsl","src/Aquarium.Zyphos/Shaders/D3D12ZyphosUmbros.hlsl","tests/Aquarium.Engine.Fractal.Tests/ZyphosFractalTerrainTests.cs","tests/Aquarium.Engine.Fractal.Tests/ZyphosSpatialDomainCatalogTests.cs"],"source":"user asked for Zyphos and Umbros selectable sub-domains plus more quadtree SDF fractals and layered geometry for stress testing"} {"timestamp":"2026-05-18T09:45:34+01:00","topic":"everything-is-a-fractal-recursive-domains","lesson":"The Zyphos world patch now expresses the 'everything is a fractal' idea as explicit recursive domains: planet -> lat/long -> continent -> forest -> tree -> leaf and continent -> coast -> pebble field, plus Umbros -> crater province -> boulder field -> pebble field. The flattened stress backend emits 58 shaped brush claims into a 64-entry D3D12 table, while SDF shaders add bounded leaf/pebble material-relief clusters so the recursion is visible even before true recursive residency and LOD caching exist.","files":["src/Aquarium.Zyphos/Worlds/zyphos-first-fractal-terrain.aquageo","src/Aquarium.Zyphos/ZyphosSpatialDomainCatalog.cs","src/Aquarium.Zyphos/ZyphosRuntime.cs","src/Aquarium.Engine/Render/Features/D3D12HeightFieldBrushConstants.cs","src/Aquarium.Engine/Render/Shaders/D3D12HeightField.hlsl","src/Aquarium.Zyphos/Shaders/D3D12ZyphosPlanet.hlsl","src/Aquarium.Zyphos/Shaders/D3D12ZyphosUmbros.hlsl","tests/Aquarium.Engine.Fractal.Tests/ZyphosCameraComposerTests.cs","tests/Aquarium.Engine.Fractal.Tests/ZyphosFractalTerrainTests.cs","tests/Aquarium.Engine.Fractal.Tests/ZyphosSpatialDomainCatalogTests.cs"],"source":"user asked to see recursive domains everywhere, from continent-scale detail down to pebble, forests down to leaf"} {"timestamp":"2026-05-18T09:58:37+01:00","topic":"zyphos-visible-sun-and-domain-zoom","lesson":"The primary star cannot remain only an SDF light if users need spatial orientation; it is now a rendered SDF object with emission/corona and a Solar navigation target. Camera zoom limits are now derived from the selected domain pose instead of a global 8-unit floor, so leaf and pebble domains can be inspected at their own scale while broad orbital domains still retain safe maximum framing.","files":["src/Aquarium.Zyphos/ZyphosRenderPlan.cs","src/Aquarium.Zyphos/ZyphosSceneBuilder.cs","src/Aquarium.Zyphos/Shaders/D3D12ZyphosStar.hlsl","src/Aquarium.Zyphos/ZyphosCameraComposer.cs","src/Aquarium.Zyphos/ZyphosRuntime.cs","src/Aquarium.Zyphos/ZyphosSpatialDomainCatalog.cs","tests/Aquarium.Engine.Fractal.Tests/ZyphosCameraComposerTests.cs"],"source":"user asked where the sun is and why zoom cannot reach the cool small features"} +{"lesson":"The first live bridge from the fractal architecture into Zyphos SDF rendering is material/detail, not traced form: .aquageo now preserves multiple tile roots, height brush packets carry cube-tile face/level/x/y metadata, D3D12 binds that packet table into the SDF pass, and the planet shader evaluates authored brushes in cube-face tile space after hit. Evaluating all authored brushes inside sdfDistance was tested and cut because it pushed the live frame toward 50-100 ms; traced geometry needs selected-cut/resident packet policy first.","timestamp":"2026-05-18T11:28:00+01:00","files":["src/Aquarium.Engine.Fractal/Grammar/FractalDslCompiler.cs","src/Aquarium.Engine.Fractal/Brushes/FractalHeightBrushCompiler.cs","src/Aquarium.Engine.Contracts/Render/AquariumRenderPlan.cs","src/Aquarium.Engine/Render/Features/D3D12HeightFieldBrushConstants.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12SdfCommon.hlsli","src/Aquarium.Zyphos/Shaders/D3D12ZyphosPlanet.hlsl","research/rendering/fractal-brush-implementation-roadmap.md"],"source":"user pointed out the renderer was only a pile of legos and ordered the real machine to be built","topic":"zyphos-aquageo-tile-packet-sdf-bridge"} diff --git a/state/memory.json b/state/memory.json index 0bf1348..c7554e5 100644 --- a/state/memory.json +++ b/state/memory.json @@ -80,6 +80,8 @@ "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.", "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 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.", "The consolidated fractal brush architecture lives in research/rendering/fractal-brush-architecture-plan.md. Its pipeline is client intent -> domain roots -> semantic IFS brush grammar -> ownership tree -> node summaries -> contribution cache/residency scheduler -> backend packets -> renderer passes -> debug/evidence. Its credibility depends on module boundaries and tests: contracts, pure CPU fractal core, D3D12 backend, client adapters, mock payload/probe/random/clock seams, shader parity tests, and deterministic performance fixtures.", "The actionable fractal brush roadmap lives in research/rendering/fractal-brush-implementation-roadmap.md. Start with the first work packet: add Aquarium.Engine.Fractal and tests, cube-face/tile key types, identity and tangent projection candidates, an area distortion sampler, face-edge tests, and a projection report before touching recursive detail." diff --git a/tests/Aquarium.Engine.Fractal.Tests/FractalDslCompilerTests.cs b/tests/Aquarium.Engine.Fractal.Tests/FractalDslCompilerTests.cs index d7f2390..9ccdc17 100644 --- a/tests/Aquarium.Engine.Fractal.Tests/FractalDslCompilerTests.cs +++ b/tests/Aquarium.Engine.Fractal.Tests/FractalDslCompilerTests.cs @@ -63,6 +63,26 @@ public sealed class FractalDslCompilerTests Assert.All(first.Claims, claim => Assert.Equal("crater", claim.Tags)); } + [Fact] + public void DslPreservesMultipleTileRoots() + { + const string source = """ + domain Planetary demo/planet - 1 0.56 0 0 + tile PositiveZ 0 0 0 zyphos/continent demo/planet + height basin 0 0 30 30 0 3 1 -0.18 7 basin + tile NegativeX 2 2 1 zyphos/leaf demo/planet + ifs leaf 2 2 9 9 1.8 0.72 0.42 2.8 0.61 6.0 0.58 0.018 101 leaf + """; + + var tree = FractalDslCompiler.Compile(source); + + Assert.Equal(2, tree.Nodes.Count); + Assert.Contains(tree.Nodes, node => node.DomainKey.Value == "cube/PositiveZ/L00/0/0:zyphos/continent" && node.ClaimCount == 1); + Assert.Contains(tree.Nodes, node => node.DomainKey.Value == "cube/NegativeX/L02/2/1:zyphos/leaf" && node.ClaimCount == 3); + Assert.Contains(tree.Claims, claim => claim.DomainKey.Value == "cube/PositiveZ/L00/0/0:zyphos/continent"); + Assert.Contains(tree.Claims, claim => claim.DomainKey.Value == "cube/NegativeX/L02/2/1:zyphos/leaf"); + } + [Fact] public void DslRejectsClaimsBeforeTile() { diff --git a/tests/Aquarium.Engine.Fractal.Tests/FractalHeightBrushCompilerTests.cs b/tests/Aquarium.Engine.Fractal.Tests/FractalHeightBrushCompilerTests.cs index 282db88..e7225bd 100644 --- a/tests/Aquarium.Engine.Fractal.Tests/FractalHeightBrushCompilerTests.cs +++ b/tests/Aquarium.Engine.Fractal.Tests/FractalHeightBrushCompilerTests.cs @@ -1,6 +1,7 @@ using System.Numerics; using Aquarium.Engine.Fractal; using Aquarium.Engine.Fractal.Brushes; +using Aquarium.Engine.Fractal.Grammar; namespace Aquarium.Engine.Fractal.Tests; @@ -54,4 +55,37 @@ public sealed class FractalHeightBrushCompilerTests Assert.Throws(() => FractalHeightBrushCompiler.Compile(claim)); } + + [Fact] + public void TreeCompilePreservesCubeTileDomainMetadata() + { + var domain = new AquariumFractalDomain( + new AquariumFractalKey("cube/NegativeX/L02/2/1:zyphos/leaf"), + AquariumFractalDomainKind.CubeSphereTile, + default, + new Vector4((float)CubeFace.NegativeX, 2.0f, 2.0f, 1.0f), + Vector4.Zero); + var rootKey = new AquariumFractalKey("cube/NegativeX/L02/2/1:zyphos/leaf/root"); + var claim = new AquariumBrushClaim( + new AquariumFractalKey("claim/leaf"), + domain.Key, + rootKey, + AquariumFractalPayloadKind.Height, + Vector2.Zero, + Vector2.One, + RotationRadians: 0.0f, + Falloff: 3.0f, + ShapePower: 1.0f, + Amplitude: 0.25f, + Seed: 3, + Tags: "leaf"); + var tree = FractalOwnershipTreeBuilder.BuildFlatUnion(domain, rootKey, [claim]); + + var brush = Assert.Single(FractalHeightBrushCompiler.CompileTree(tree)); + + Assert.Equal((float)CubeFace.NegativeX, brush.DomainFace); + Assert.Equal(2.0f, brush.DomainLevel); + Assert.Equal(2.0f, brush.DomainX); + Assert.Equal(1.0f, brush.DomainY); + } } diff --git a/tests/Aquarium.Engine.Fractal.Tests/ZyphosFractalTerrainTests.cs b/tests/Aquarium.Engine.Fractal.Tests/ZyphosFractalTerrainTests.cs index 85530f0..fc599dc 100644 --- a/tests/Aquarium.Engine.Fractal.Tests/ZyphosFractalTerrainTests.cs +++ b/tests/Aquarium.Engine.Fractal.Tests/ZyphosFractalTerrainTests.cs @@ -23,6 +23,7 @@ public sealed class ZyphosFractalTerrainTests Assert.Contains(tree.Domains, domain => domain.Kind == AquariumFractalDomainKind.CubeSphereTile && domain.ParentKey.Value == "zyphos/canopy-leaf"); Assert.Contains(tree.Domains, domain => domain.Kind == AquariumFractalDomainKind.CubeSphereTile && domain.ParentKey.Value == "umbros/pebble-field"); Assert.Equal(new AquariumFractalKey("umbros/pebble-field"), tree.Domain.ParentKey); + Assert.Equal(7, tree.Nodes.Count); Assert.Equal(58, tree.Claims.Count); Assert.Equal(tree.Claims.Count, brushes.Length); Assert.Contains(tree.Claims, claim => claim.Tags == "crater");