diff --git a/Aquarium.Engine.sln b/Aquarium.Engine.sln index dcb2ce1..8b08f3f 100644 --- a/Aquarium.Engine.sln +++ b/Aquarium.Engine.sln @@ -47,6 +47,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{07C2787E EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aquarium.Fractal.Receipt", "tools\Aquarium.Fractal.Receipt\Aquarium.Fractal.Receipt.csproj", "{C0D1BFAC-B1B4-4350-92A7-D537AE382909}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aquarium.Fensalir", "src\Aquarium.Fensalir\Aquarium.Fensalir.csproj", "{F9274D99-3CC6-42B6-9817-EC7F19663B1D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -285,6 +287,18 @@ Global {C0D1BFAC-B1B4-4350-92A7-D537AE382909}.Release|x64.Build.0 = Release|Any CPU {C0D1BFAC-B1B4-4350-92A7-D537AE382909}.Release|x86.ActiveCfg = Release|Any CPU {C0D1BFAC-B1B4-4350-92A7-D537AE382909}.Release|x86.Build.0 = Release|Any CPU + {F9274D99-3CC6-42B6-9817-EC7F19663B1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F9274D99-3CC6-42B6-9817-EC7F19663B1D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F9274D99-3CC6-42B6-9817-EC7F19663B1D}.Debug|x64.ActiveCfg = Debug|Any CPU + {F9274D99-3CC6-42B6-9817-EC7F19663B1D}.Debug|x64.Build.0 = Debug|Any CPU + {F9274D99-3CC6-42B6-9817-EC7F19663B1D}.Debug|x86.ActiveCfg = Debug|Any CPU + {F9274D99-3CC6-42B6-9817-EC7F19663B1D}.Debug|x86.Build.0 = Debug|Any CPU + {F9274D99-3CC6-42B6-9817-EC7F19663B1D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F9274D99-3CC6-42B6-9817-EC7F19663B1D}.Release|Any CPU.Build.0 = Release|Any CPU + {F9274D99-3CC6-42B6-9817-EC7F19663B1D}.Release|x64.ActiveCfg = Release|Any CPU + {F9274D99-3CC6-42B6-9817-EC7F19663B1D}.Release|x64.Build.0 = Release|Any CPU + {F9274D99-3CC6-42B6-9817-EC7F19663B1D}.Release|x86.ActiveCfg = Release|Any CPU + {F9274D99-3CC6-42B6-9817-EC7F19663B1D}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -297,10 +311,12 @@ Global {37363FC6-5AA3-49B4-A3B1-E4AB2CC986EB} = {0AB3BF05-4346-4AA6-1389-037BE0695223} {F12A367A-8D8E-490D-B60E-3FDBEA3E07E2} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B} {801B1913-6AE1-4B8C-8030-4669AC4FE25E} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B} + {F9274D99-3CC6-42B6-9817-EC7F19663B1D} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B} {FF232A59-4E8D-4D56-A2C3-ACC02F5371D0} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B} {A9D41C48-7E78-4D75-A814-0C1500245EFC} = {0AB3BF05-4346-4AA6-1389-037BE0695223} {E8C66A46-1F56-484D-8CDD-5C0A3FD84A5F} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B} {E6560D72-B018-4E00-AEBD-C1B9419E0BC7} = {0AB3BF05-4346-4AA6-1389-037BE0695223} {C0D1BFAC-B1B4-4350-92A7-D537AE382909} = {07C2787E-EAC7-C090-1BA3-A61EC2A24D84} + {F9274D99-3CC6-42B6-9817-EC7F19663B1D} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B} EndGlobalSection EndGlobal diff --git a/src/Aquarium.Engine.Contracts/Fractal/AquariumFractalContracts.cs b/src/Aquarium.Engine.Contracts/Fractal/AquariumFractalContracts.cs index c501440..00c190a 100644 --- a/src/Aquarium.Engine.Contracts/Fractal/AquariumFractalContracts.cs +++ b/src/Aquarium.Engine.Contracts/Fractal/AquariumFractalContracts.cs @@ -315,7 +315,11 @@ public readonly record struct AquariumBrushClaim( float ShapePower, float Amplitude, int Seed, - string Tags); + string Tags, + float WaveAmplitude = 0.0f, + float WaveFrequency = 0.0f, + float WaveSpeed = 0.0f, + float WaveSinePower = 0.0f); public enum AquariumFractalOperation { diff --git a/src/Aquarium.Engine.Fractal/Brushes/FractalHeightBrushCompiler.cs b/src/Aquarium.Engine.Fractal/Brushes/FractalHeightBrushCompiler.cs index 02d14ae..c8fd561 100644 --- a/src/Aquarium.Engine.Fractal/Brushes/FractalHeightBrushCompiler.cs +++ b/src/Aquarium.Engine.Fractal/Brushes/FractalHeightBrushCompiler.cs @@ -27,10 +27,10 @@ public static class FractalHeightBrushCompiler claim.Radii.X, claim.ShapePower, claim.Amplitude, - WaveAmplitude: 0.0f, - WaveFrequency: 0.0f, - WaveSpeed: 0.0f, - WaveSinePower: 0.0f, + claim.WaveAmplitude, + claim.WaveFrequency, + claim.WaveSpeed, + claim.WaveSinePower, RadiusY: claim.Radii.Y, RotationRadians: claim.RotationRadians, EnvelopeFalloff: claim.Falloff, diff --git a/src/Aquarium.Engine.Fractal/Grammar/FractalDslCompiler.cs b/src/Aquarium.Engine.Fractal/Grammar/FractalDslCompiler.cs index e415916..a9dc950 100644 --- a/src/Aquarium.Engine.Fractal/Grammar/FractalDslCompiler.cs +++ b/src/Aquarium.Engine.Fractal/Grammar/FractalDslCompiler.cs @@ -89,6 +89,14 @@ public static class FractalDslCompiler claims.Add(ParseFieldClaim(tokens, fieldDomain.Key, currentNode!.Key, lineIndex, claims.Count - currentNode.FirstClaimIndex)); currentNode.ClaimCount++; break; + case "ripple": + EnsureDomain(domain, lineIndex); + EnsureNode(currentNode, lineIndex); + EnsureTokenCount(tokens, 16, lineIndex); + var rippleDomain = domain!.Value; + claims.Add(ParseRippleClaim(tokens, rippleDomain.Key, currentNode!.Key, lineIndex, claims.Count - currentNode.FirstClaimIndex)); + currentNode.ClaimCount++; + break; case "ifs": EnsureDomain(domain, lineIndex); EnsureNode(currentNode, lineIndex); @@ -161,6 +169,29 @@ public static class FractalDslCompiler tokens[11]); } + private static AquariumBrushClaim ParseRippleClaim(string[] tokens, AquariumFractalKey domainKey, AquariumFractalKey nodeKey, int lineIndex, int claimIndex) + { + var name = tokens[1]; + return FieldClaim( + AquariumFractalPayloadKind.Height, + domainKey, + nodeKey, + name, + claimIndex, + new Vector2(ParseFloat(tokens[2], lineIndex), ParseFloat(tokens[3], lineIndex)), + new Vector2(ParsePositiveFloat(tokens[4], lineIndex), ParsePositiveFloat(tokens[5], lineIndex)), + ParseFloat(tokens[6], lineIndex), + ParsePositiveFloat(tokens[7], lineIndex), + ParsePositiveFloat(tokens[8], lineIndex), + ParseFloat(tokens[9], lineIndex), + ParseInt(tokens[14], lineIndex), + tokens[15], + ParseFloat(tokens[10], lineIndex), + ParsePositiveFloat(tokens[11], lineIndex), + ParseFloat(tokens[12], lineIndex), + ParsePositiveFloat(tokens[13], lineIndex)); + } + private static AquariumFractalPayloadKind ParsePayloadKind(string token, int lineIndex) { return token switch @@ -340,7 +371,11 @@ public static class FractalDslCompiler float shapePower, float amplitude, int seed, - string tags) + string tags, + float waveAmplitude = 0.0f, + float waveFrequency = 0.0f, + float waveSpeed = 0.0f, + float waveSinePower = 0.0f) { return new AquariumBrushClaim( FractalStableKeyBuilder.Child(nodeKey, $"claim/{claimIndex:0000}/{name}"), @@ -354,7 +389,11 @@ public static class FractalDslCompiler shapePower, amplitude, seed, - tags); + tags, + waveAmplitude, + waveFrequency, + waveSpeed, + waveSinePower); } private static string StripComment(string line) diff --git a/src/Aquarium.Fensalir/Aquarium.Fensalir.csproj b/src/Aquarium.Fensalir/Aquarium.Fensalir.csproj new file mode 100644 index 0000000..09900e4 --- /dev/null +++ b/src/Aquarium.Fensalir/Aquarium.Fensalir.csproj @@ -0,0 +1,23 @@ + + + + net10.0 + Aquarium.Fensalir + Aquarium.Fensalir + enable + enable + true + + + + + + + + + + + + + + diff --git a/src/Aquarium.Fensalir/FensalirFractalScene.cs b/src/Aquarium.Fensalir/FensalirFractalScene.cs new file mode 100644 index 0000000..76c7b29 --- /dev/null +++ b/src/Aquarium.Fensalir/FensalirFractalScene.cs @@ -0,0 +1,47 @@ +using Aquarium.Engine.Fractal; +using Aquarium.Engine.Fractal.Brushes; +using Aquarium.Engine.Fractal.Debug; +using Aquarium.Engine.Fractal.Grammar; +using Aquarium.Engine.Fractal.Lod; +using Aquarium.Engine.Render; + +namespace Aquarium.Fensalir; + +public static class FensalirFractalScene +{ + private const string PatchRelativePath = "Worlds/fensalir-spine-emblem.aquageo"; + + private static readonly Lazy PatchSource = new(() => File.ReadAllText(PatchPath)); + 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, _ => 12.0f, maxEstimatedCost: 64.0f)); + private static readonly Lazy Brushes = new(() => OrderBrushes(FractalHeightBrushCompiler.CompileSelectedTree(Tree.Value, SelectedCut.Value))); + + public static string PatchPath => Path.Combine(AssemblyDirectory, PatchRelativePath); + + public static FractalOwnershipTree OwnershipTree => Tree.Value; + + public static AquariumHeightFieldBrush[] HeightBrushes => Brushes.Value; + + public static AquariumFractalSummary[] NodeSummaries => Summaries.Value; + + public static AquariumSelectedCut[] SelectedCuts => SelectedCut.Value; + + public static string Summary => + $"{Path.GetFileName(PatchPath)} / {OwnershipTree.Claims.Count} claims / {HeightBrushes.Length} surface brushes / {SelectedCuts.Length} cuts"; + + public static string DebugDump => FractalDebugDump.Build(OwnershipTree, NodeSummaries, SelectedCuts); + + private static AquariumHeightFieldBrush[] OrderBrushes(AquariumHeightFieldBrush[] brushes) + { + return brushes + .OrderByDescending(brush => MathF.Abs(brush.Amplitude) * MathF.Max(brush.Radius, brush.RadiusY) + MathF.Abs(brush.WaveAmplitude) * brush.Radius) + .ThenBy(brush => brush.Center.X) + .ThenBy(brush => brush.Center.Y) + .ToArray(); + } + + private static string AssemblyDirectory => + Path.GetDirectoryName(typeof(FensalirFractalScene).Assembly.Location) + ?? AppContext.BaseDirectory; +} diff --git a/src/Aquarium.Fensalir/FensalirRenderPlan.cs b/src/Aquarium.Fensalir/FensalirRenderPlan.cs new file mode 100644 index 0000000..999ebe2 --- /dev/null +++ b/src/Aquarium.Fensalir/FensalirRenderPlan.cs @@ -0,0 +1,39 @@ +using Aquarium.Engine.Render; + +namespace Aquarium.Fensalir; + +public static class FensalirRenderPlan +{ + public const int SpineIndex = 0; + public const int SdfObjectCount = 1; + + public static AquariumRenderPlan Create() + { + var app = new AquariumApp(); + app.Shaders + .Core("D3D12HeightField.hlsl", ShaderPath("D3D12FensalirScene.hlsl"), "D3D12Post.hlsl") + .SdfShader(ShaderPath("D3D12FensalirSpine.hlsl")); + + var heightField = app.RenderTargets.Create("height-field") + .FixedSize(128, 128) + .Format(RenderFormat.R16Float) + .Register(); + var scene = app.RenderTargets.Hdr("scene"); + app.Cameras.Orbit("main"); + app.Graph.Pass("height-field").Fullscreen(); + app.Graph.Pass("scene").Fullscreen(); + app.Graph.Pass("sdf-proxies").Proxy(); + app.Features.Bloom(scene.Color); + app.Features.Presentation(scene.Color); + app.Features.DirectWriteOverlay(); + app.Debug.View("Height Field", heightField).View("Scene", scene.Color); + return app.Plan; + } + + private static string ShaderPath(string fileName) + { + var assemblyDirectory = Path.GetDirectoryName(typeof(FensalirRenderPlan).Assembly.Location) + ?? AppContext.BaseDirectory; + return Path.Combine(assemblyDirectory, "Render", "Shaders", fileName); + } +} diff --git a/src/Aquarium.Fensalir/FensalirRuntime.cs b/src/Aquarium.Fensalir/FensalirRuntime.cs new file mode 100644 index 0000000..bcf9e0c --- /dev/null +++ b/src/Aquarium.Fensalir/FensalirRuntime.cs @@ -0,0 +1,154 @@ +using System.Numerics; +using Aquarium.Engine; +using Aquarium.Engine.Audio; +using Aquarium.Engine.Input; +using Aquarium.Engine.Render; +using Aquarium.Engine.Ui; + +namespace Aquarium.Fensalir; + +public sealed class FensalirRuntime : IAquariumRuntime +{ + private float timeSeconds; + private float previousTimeSeconds; + private float orbitYaw; + private float orbitPitch = 0.19f; + private float orbitDistance = 7.6f; + private bool autoDrift = true; + + public AquariumRuntimeOptions Options { get; private set; } + + public GraphicsSettings GraphicsSettings { get; set; } = new(0, 1.04f, 0.52f, 0.08f); + + public AquariumRenderPlan RenderPlan { get; } = FensalirRenderPlan.Create(); + + public AquariumUiDocument Ui { get; } + + public AquariumAudioDocument Audio { get; } = new(); + + public AquariumSynthDocument Synth { get; } = AquariumSynthDocument.Empty; + + public AquariumFrame Frame + { + get + { + var target = new Vector3(0.0f, 0.12f, 2.1f); + var camera = ComposeCamera(target); + return new AquariumFrame( + new ViewFrame(Vector2.Zero, 8.0f), + camera, + target, + timeSeconds, + Vector2.Zero, + FensalirSceneBuilder.Build(timeSeconds, previousTimeSeconds)); + } + } + + public FensalirRuntime() + { + Ui = new AquariumUiDocument() + .Panel("Fensalir", 18.0f, 82.0f, 360.0f, panel => + { + panel.Section("Splash Reconstruction"); + panel.Toggle("Auto Drift", () => autoDrift, value => autoDrift = value); + panel.Slider("Orbit Distance", () => orbitDistance, value => orbitDistance = Math.Clamp(value, 3.2f, 14.0f), 3.2f, 14.0f, "0.00"); + panel.Readout("Patch", () => FensalirFractalScene.Summary); + panel.Readout("Surface", () => $"{FensalirFractalScene.HeightBrushes.Count(brush => brush.WaveAmplitude != 0.0f)} ripple brushes / quadtree plane"); + panel.Readout("Renderer", () => "2D marsh field + emissive SDF spine + bloom"); + panel.Readout("Camera", () => $"{orbitDistance:0.00} wu / yaw {orbitYaw:0.00}"); + }) + .Command("fensalir", _ => $"Fensalir: {FensalirFractalScene.Summary}", "Report Fensalir splash scene status.") + .Command("fensalir-fractal", _ => FensalirFractalScene.DebugDump, "Dump the compiled Fensalir splash .aquageo patch."); + } + + public AquariumFrame ComposeFrame(AquariumFrame frame, AquariumFrameInput input) + { + return frame; + } + + public void Start() + { + Console.WriteLine("Fensalir splash reconstruction booted."); + } + + public void Update(float deltaSeconds, InputState input) + { + previousTimeSeconds = timeSeconds; + var safeDelta = Math.Max(deltaSeconds, 0.0f); + timeSeconds += safeDelta; + + if (autoDrift) + { + orbitYaw += safeDelta * 0.018f; + } + + if (input.IsKeyDown(KeyCode.A)) + { + orbitYaw -= safeDelta * 0.7f; + autoDrift = false; + } + + if (input.IsKeyDown(KeyCode.D)) + { + orbitYaw += safeDelta * 0.7f; + autoDrift = false; + } + + if (input.IsKeyDown(KeyCode.W)) + { + orbitPitch += safeDelta * 0.32f; + } + + if (input.IsKeyDown(KeyCode.S)) + { + orbitPitch -= safeDelta * 0.32f; + } + + if (MathF.Abs(input.WheelDelta) > 0.0f) + { + orbitDistance = Math.Clamp(orbitDistance - input.WheelDelta * MathF.Max(orbitDistance * 0.09f, 0.05f), 3.2f, 14.0f); + } + + if (input.LeftMouseDown && input.MouseDelta != Vector2.Zero) + { + orbitYaw -= input.MouseDelta.X * 0.006f; + orbitPitch += input.MouseDelta.Y * 0.0035f; + autoDrift = false; + } + + orbitPitch = Math.Clamp(orbitPitch, 0.08f, 0.42f); + } + + public void FlushState() + { + } + + public void Dispose() + { + } + + internal void SetOptions(AquariumRuntimeOptions options) + { + Options = options; + } + + private Vector3 ComposeCamera(Vector3 target) + { + var yaw = -0.03f + orbitYaw; + var horizontal = MathF.Cos(orbitPitch) * orbitDistance; + return new Vector3( + MathF.Sin(yaw) * horizontal, + -MathF.Cos(yaw) * horizontal, + target.Z + MathF.Sin(orbitPitch) * orbitDistance); + } +} + +public sealed class FensalirRuntimeFactory : IAquariumRuntimeFactory +{ + public IAquariumRuntime Create(AquariumRuntimeOptions options) + { + var runtime = new FensalirRuntime(); + runtime.SetOptions(options); + return runtime; + } +} diff --git a/src/Aquarium.Fensalir/FensalirSceneBuilder.cs b/src/Aquarium.Fensalir/FensalirSceneBuilder.cs new file mode 100644 index 0000000..24d3eb8 --- /dev/null +++ b/src/Aquarium.Fensalir/FensalirSceneBuilder.cs @@ -0,0 +1,53 @@ +using System.Numerics; +using Aquarium.Engine.Render; + +namespace Aquarium.Fensalir; + +public static class FensalirSceneBuilder +{ + private static readonly Vector3 SpineCenter = new(0.0f, 0.18f, 2.45f); + private const float SpineBoundRadius = 5.8f; + + public static AquariumSceneState Build(float timeSeconds, float previousTimeSeconds) + { + return new AquariumSceneState + { + TraceHeightFieldSurface = true, + UseStarfieldBackground = false, + HeightFieldBrushes = FensalirFractalScene.HeightBrushes, + SdfObjects = BuildSdfObjects(timeSeconds, previousTimeSeconds), + SdfLights = BuildSdfLights(), + }; + } + + private static AquariumSdfObject[] BuildSdfObjects(float timeSeconds, float previousTimeSeconds) + { + var sway = MathF.Sin(timeSeconds * 0.19f) * 0.018f; + var previousSway = MathF.Sin(previousTimeSeconds * 0.19f) * 0.018f; + var center = SpineCenter + new Vector3(sway, 0.0f, 0.0f); + var previousCenter = SpineCenter + new Vector3(previousSway, 0.0f, 0.0f); + return + [ + new AquariumSdfObject( + new Vector4(center, SpineBoundRadius), + new Vector4(previousCenter, 0.0f), + new Vector4(1.0f, timeSeconds, 0.0f, 0.0f)) + ]; + } + + private static AquariumSdfLight[] BuildSdfLights() + { + return + [ + new AquariumSdfLight( + new Vector4(SpineCenter, 2.8f), + new Vector4(0.95f, 1.75f, 2.8f, 10.0f)), + new AquariumSdfLight( + new Vector4(-2.5f, 0.25f, 1.3f, 1.9f), + new Vector4(1.0f, 0.16f, 0.72f, 10.0f)), + new AquariumSdfLight( + new Vector4(2.5f, 0.25f, 1.3f, 1.9f), + new Vector4(1.0f, 0.16f, 0.72f, 10.0f)), + ]; + } +} diff --git a/src/Aquarium.Fensalir/Shaders/D3D12FensalirScene.hlsl b/src/Aquarium.Fensalir/Shaders/D3D12FensalirScene.hlsl new file mode 100644 index 0000000..478cacd --- /dev/null +++ b/src/Aquarium.Fensalir/Shaders/D3D12FensalirScene.hlsl @@ -0,0 +1,273 @@ +cbuffer AquariumFrame : register(b0) +{ + float2 resolution; + float timeSeconds; + float viewRadius; + float3 cameraPosition; + float farDistance; + float3 cameraTarget; + float sceneFlags; + float2 viewCenter; + float frameIndex; + float previousTimeSeconds; + float3 previousCameraPosition; + float previousViewRadius; + float3 previousCameraTarget; + float previousSceneFlags; + float2 previousViewCenter; + float2 jitterPixels; + float2 previousJitterPixels; + float renderDebugMode; + float exposure; + float bloomIntensity; + float bloomVeilIntensity; + float4 cursorWorlds; + float4 temporalGaussianInfo; +}; + +Texture2D heightFieldTexture : register(t0); +SamplerState linearSampler : register(s0); + +static const float FIELD_ID_HEIGHT_FIELD = 4.0; +static const float HEIGHT_FIELD_TEXEL_COUNT = 128.0; + +struct VertexOut +{ + float4 position : SV_Position; + float2 uv : TEXCOORD0; +}; + +struct SceneOut +{ + float4 colorTravel : SV_Target0; + float4 metadata : SV_Target1; + float4 control : SV_Target2; + float4 reservoirGuide : SV_Target3; + float depth : SV_Depth; +}; + +struct RayMarchResult +{ + float3 color; + float travel; + float fieldId; + float3 normal; + float coverage; + float stepCount; +}; + +VertexOut FullscreenTriangleVS(uint vertexId : SV_VertexID) +{ + float2 uv = float2((vertexId << 1) & 2, vertexId & 2); + VertexOut output; + output.position = float4(uv * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0); + output.uv = uv; + return output; +} + +void cameraBasis(float3 camera, float3 target, out float3 forward, out float3 right, out float3 up) +{ + forward = normalize(target - camera); + right = normalize(cross(forward, float3(0.0, 0.0, 1.0))); + up = cross(right, forward); +} + +float3 rayDirectionForPixel(float2 pixel, float2 jitter, float3 camera, float3 target) +{ + float2 ndc = ((pixel + jitter) * 2.0 - resolution) / resolution.y; + float3 forward; + float3 right; + float3 up; + cameraBasis(camera, target, forward, right, up); + return normalize(forward * 1.6 + right * ndc.x + up * ndc.y); +} + +float2 viewLocal(float2 p) +{ + return (p - viewCenter) / max(viewRadius, 0.001); +} + +float2 viewUv(float2 p) +{ + return viewLocal(p) * 0.5 + 0.5; +} + +float terrainHeight(float2 p) +{ + return heightFieldTexture.SampleLevel(linearSampler, saturate(viewUv(p)), 0.0).r; +} + +float2 terrainGradient(float2 p) +{ + float2 uv = saturate(viewUv(p)); + float2 texel = 1.0 / HEIGHT_FIELD_TEXEL_COUNT; + float texelWorld = max((viewRadius * 2.0) / HEIGHT_FIELD_TEXEL_COUNT, 0.001); + + float hLeft = heightFieldTexture.SampleLevel(linearSampler, uv - float2(texel.x, 0.0), 0.0).r; + float hRight = heightFieldTexture.SampleLevel(linearSampler, uv + float2(texel.x, 0.0), 0.0).r; + float hDown = heightFieldTexture.SampleLevel(linearSampler, uv - float2(0.0, texel.y), 0.0).r; + float hUp = heightFieldTexture.SampleLevel(linearSampler, uv + float2(0.0, texel.y), 0.0).r; + return float2(hRight - hLeft, hUp - hDown) / (texelWorld * 2.0); +} + +bool traceHeightFieldSurfaceDirect(float3 origin, float3 direction, float intervalStart, float intervalEnd, out float3 hitPosition, out float travel) +{ + travel = max(intervalStart, 0.0); + float previousTravel = travel; + hitPosition = origin + direction * travel; + float previousGap = hitPosition.z - terrainHeight(hitPosition.xy); + + [loop] + for (int stepIndex = 0; stepIndex < 96; stepIndex++) + { + hitPosition = origin + direction * travel; + float2 local = viewLocal(hitPosition.xy); + if (length(local) > 1.08 && hitPosition.z < 4.0) + { + return false; + } + + float gap = hitPosition.z - terrainHeight(hitPosition.xy); + float hitEpsilon = max(0.002, travel * 0.00035); + if (length(local) <= 1.0 && (abs(gap) <= hitEpsilon || (previousGap > 0.0 && gap <= 0.0))) + { + float alpha = previousGap / max(previousGap - gap, 0.0001); + travel = lerp(previousTravel, travel, saturate(alpha)); + hitPosition = origin + direction * travel; + return travel > intervalStart && travel < intervalEnd && travel < farDistance; + } + + float2 slope = terrainGradient(hitPosition.xy); + float terrainRate = abs(direction.z - dot(slope, direction.xy)); + float terrainStep = gap > 0.0 ? gap / max(terrainRate, 0.22) : 0.026; + terrainStep = min(terrainStep * 0.62, max(viewRadius * 0.08, 0.026)); + previousTravel = travel; + previousGap = gap; + travel += max(terrainStep, 0.026); + if (travel > intervalEnd || travel > farDistance) + { + return false; + } + } + + return false; +} + +float hash31(float3 p) +{ + return frac(sin(dot(p, float3(12.9898, 78.233, 37.719))) * 43758.5453); +} + +float valueNoise3(float3 p) +{ + float3 cell = floor(p); + float3 local = frac(p); + local = local * local * (3.0 - 2.0 * local); + + float c000 = hash31(cell); + float c100 = hash31(cell + float3(1.0, 0.0, 0.0)); + float c010 = hash31(cell + float3(0.0, 1.0, 0.0)); + float c110 = hash31(cell + float3(1.0, 1.0, 0.0)); + float c001 = hash31(cell + float3(0.0, 0.0, 1.0)); + float c101 = hash31(cell + float3(1.0, 0.0, 1.0)); + float c011 = hash31(cell + float3(0.0, 1.0, 1.0)); + float c111 = hash31(cell + float3(1.0, 1.0, 1.0)); + + float x00 = lerp(c000, c100, local.x); + float x10 = lerp(c010, c110, local.x); + float x01 = lerp(c001, c101, local.x); + float x11 = lerp(c011, c111, local.x); + return lerp(lerp(x00, x10, local.y), lerp(x01, x11, local.y), local.z); +} + +float fractalNoise3(float3 p) +{ + float sum = 0.0; + float amplitude = 0.5; + [unroll] + for (int octave = 0; octave < 4; octave++) + { + sum += valueNoise3(p) * amplitude; + p = p * 2.03 + float3(5.7, 2.1, 9.3); + amplitude *= 0.52; + } + + return sum; +} + +float3 backgroundRadiance(float3 direction) +{ + float horizon = smoothstep(-0.24, 0.42, direction.z); + float verticalAxis = pow(saturate(1.0 - abs(direction.x) * 6.4), 3.0) * smoothstep(-0.18, 0.72, direction.z); + float hall = pow(saturate(1.0 - abs(abs(direction.x) - 0.22) * 12.0), 2.0) * smoothstep(-0.08, 0.58, direction.z); + float fog = pow(saturate(fractalNoise3(direction * 4.1 + float3(0.0, timeSeconds * 0.015, 0.0)) - 0.18), 2.2); + + float3 voidColor = lerp(float3(0.001, 0.006, 0.009), float3(0.018, 0.055, 0.062), horizon); + float3 cyan = float3(0.50, 1.55, 2.25) * verticalAxis * 0.62; + float3 magenta = float3(1.25, 0.12, 0.82) * hall * 0.18; + float3 mist = float3(0.12, 0.36, 0.38) * fog * (0.18 + horizon * 0.24); + return voidColor + cyan + magenta + mist; +} + +float3 surfaceMirrorRadiance(float3 p, float3 direction, out float3 normal) +{ + float2 gradient = terrainGradient(p.xy); + normal = normalize(float3(-gradient.x, -gradient.y, 1.0)); + float3 reflectionDirection = reflect(direction, normal); + float3 reflected = backgroundRadiance(reflectionDirection); + + float spineReflection = exp(-abs(p.x) * 2.7) * smoothstep(3.4, -2.6, p.y); + float magentaLeft = exp(-abs(p.x + 2.35) * 3.2) * smoothstep(2.4, -2.2, p.y); + float magentaRight = exp(-abs(p.x - 2.35) * 3.2) * smoothstep(2.4, -2.2, p.y); + float rippleSparkle = pow(saturate(fractalNoise3(float3(p.xy * 5.2, timeSeconds * 0.22)) - 0.47), 5.0); + float fresnel = pow(1.0 - saturate(dot(normal, -direction)), 3.0); + + float3 baseWater = float3(0.002, 0.014, 0.017); + float3 cyan = float3(0.35, 1.40, 2.35) * spineReflection * (0.38 + rippleSparkle * 0.55); + float3 magenta = float3(1.10, 0.08, 0.74) * (magentaLeft + magentaRight) * 0.12; + float3 gold = float3(1.0, 0.72, 0.26) * rippleSparkle * 0.032; + return baseWater + reflected * (0.16 + fresnel * 0.28) + cyan + magenta + gold; +} + +RayMarchResult traverseRay(float3 origin, float3 direction) +{ + RayMarchResult result; + result.color = backgroundRadiance(direction); + result.travel = farDistance + 1.0; + result.fieldId = 0.0; + result.normal = 0.0; + result.coverage = 0.0; + result.stepCount = 0.0; + + float3 surfacePosition; + float surfaceTravel; + bool surfaceHit = traceHeightFieldSurfaceDirect(origin, direction, 0.0, farDistance, surfacePosition, surfaceTravel); + if (surfaceHit) + { + float3 surfaceNormal; + result.color = surfaceMirrorRadiance(surfacePosition, direction, surfaceNormal); + result.travel = surfaceTravel; + result.fieldId = FIELD_ID_HEIGHT_FIELD; + result.normal = surfaceNormal; + result.coverage = 1.0; + } + + return result; +} + +SceneOut D3D12ScenePS(VertexOut input) +{ + float2 screenUv = float2(input.uv.x, 1.0 - input.uv.y); + float2 pixel = screenUv * resolution; + float3 rayDirection = rayDirectionForPixel(pixel, jitterPixels, cameraPosition, cameraTarget); + + RayMarchResult result = traverseRay(cameraPosition, rayDirection); + + SceneOut output; + output.colorTravel = float4(result.color, min(result.travel, farDistance + 1.0)); + output.metadata = float4(result.fieldId, result.normal); + output.control = float4(result.coverage, result.stepCount / 96.0, 0.0, 0.0); + output.reservoirGuide = float4(1.0, 0.0, 1.0, 0.0); + output.depth = saturate(result.travel / max(farDistance, 0.001)); + return output; +} diff --git a/src/Aquarium.Fensalir/Shaders/D3D12FensalirSpine.hlsl b/src/Aquarium.Fensalir/Shaders/D3D12FensalirSpine.hlsl new file mode 100644 index 0000000..f0d0546 --- /dev/null +++ b/src/Aquarium.Fensalir/Shaders/D3D12FensalirSpine.hlsl @@ -0,0 +1,150 @@ +static const int SDF_INDEX = 0; + +#define SDF_TRACE_STEPS 192 +#define SDF_TRACE_STEP_SCALE 0.34 +#define SDF_TRACE_MAX_STEP_RADIUS_SCALE 0.018 + +#include "D3D12SdfCommon.hlsli" +#include "D3D12SdfMath.hlsli" + +float sdRoundBox(float3 p, float3 b, float r) +{ + float3 q = abs(p) - b; + return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0) - r; +} + +float sdCappedCylinderZ(float3 p, float radius, float halfHeight) +{ + float2 d = abs(float2(length(p.xy), p.z)) - float2(radius, halfHeight); + return min(max(d.x, d.y), 0.0) + length(max(d, 0.0)); +} + +float sdDiamond(float3 p, float3 radius) +{ + float3 q = abs(p) / max(radius, 0.001); + return (q.x + q.y + q.z - 1.0) * min(radius.x, min(radius.y, radius.z)); +} + +float fensalirSpineDistance(float3 local) +{ + float core = sdCappedCylinderZ(local - float3(0.0, 0.0, 0.18), 0.045, 2.75); + float diamonds = 999.0; + + [unroll] + for (int index = 0; index < 8; index++) + { + float t = (float)index; + float z = -1.34 + t * 0.47; + float pulse = 0.5 + 0.5 * sin(timeSeconds * 0.42 + t * 1.7); + float side = lerp(0.22, 0.46, smoothstep(0.0, 7.0, t)) * lerp(0.92, 1.08, pulse); + float3 q = local - float3(0.0, 0.0, z); + q.xy = mul(float2x2(cos(t * 0.42), -sin(t * 0.42), sin(t * 0.42), cos(t * 0.42)), q.xy); + diamonds = min(diamonds, sdDiamond(q, float3(side, side * 0.58, 0.24))); + } + + float haloGlass = sdCappedCylinderZ(local - float3(0.0, 0.0, 0.1), 0.18, 2.45); + return min(min(core, diamonds), haloGlass); +} + +float fensalirPillarDistance(float3 local) +{ + float pillars = 999.0; + [unroll] + for (int index = 0; index < 4; index++) + { + float side = index < 2 ? -1.0 : 1.0; + float rank = (float)(index % 2); + float x = side * (1.1 + rank * 0.82); + float y = 0.34 + rank * 0.42; + float3 p = local - float3(x, y, 0.0); + float lean = side * (0.08 + rank * 0.04); + p.x -= p.z * lean; + pillars = min(pillars, sdRoundBox(p, float3(0.028 + rank * 0.012, 0.055, 2.55), 0.018)); + } + + return pillars; +} + +float fensalirReedDistance(float3 local) +{ + float reeds = 999.0; + [unroll] + for (int index = 0; index < 6; index++) + { + float side = index < 3 ? -1.0 : 1.0; + float rank = (float)(index % 3); + float x = side * (3.35 + rank * 0.32); + float y = -1.76 + rank * 0.18; + float height = 0.7 + rank * 0.18; + float3 a = float3(x, y, -2.05); + float3 b = float3(x + side * (0.18 + rank * 0.04), y + 0.08, -2.05 + height); + reeds = min(reeds, sdCapsuleSegment(local, a, b, 0.018)); + } + + return reeds; +} + +float sdfDistance(float3 p, int sdfIndex) +{ + SdfObject scene = sdfObjects[sdfIndex]; + float3 local = p - scene.centerRadius.xyz; + float spine = fensalirSpineDistance(local); + float pillars = fensalirPillarDistance(local); + float reeds = fensalirReedDistance(local); + return min(spine, min(pillars, reeds)); +} + +SdfSurface sdfSurface(float3 p, int sdfIndex) +{ + SdfObject scene = sdfObjects[sdfIndex]; + float3 local = p - scene.centerRadius.xyz; + float spine = fensalirSpineDistance(local); + float pillars = fensalirPillarDistance(local); + float reeds = fensalirReedDistance(local); + float nearest = min(spine, min(pillars, reeds)); + + float rune = pow(saturate(1.0 - abs(frac(local.z * 3.7 + local.x * 0.31) - 0.5) * 16.0), 2.6); + float coreGlow = pow(saturate(1.0 - length(local.xy) * 5.2), 2.0); + float magentaEdge = pow(saturate(abs(local.x) - 0.78), 2.0) * 0.05; + + SdfSurface surface; + surface.baseColor = float3(0.02, 0.07, 0.08); + surface.metallic = 0.0; + surface.roughness = 0.22; + surface.emission = 0.0; + surface.temporalDetail = 0.35 + rune * 0.35; + surface.reservoirConfidence = 1.0; + + if (nearest == spine) + { + surface.baseColor = float3(0.35, 0.86, 0.98); + surface.roughness = 0.06; + surface.emission = float3(0.35, 1.55, 2.45) * (1.2 + coreGlow * 4.0 + rune * 1.8); + } + else if (nearest == pillars) + { + surface.baseColor = float3(0.018, 0.030, 0.034); + surface.metallic = 0.35; + surface.roughness = 0.34; + surface.emission = float3(0.75, 0.03, 0.48) * (0.08 + magentaEdge); + } + else + { + surface.baseColor = float3(0.006, 0.018, 0.014); + surface.roughness = 0.72; + surface.emission = float3(0.03, 0.18, 0.13); + } + + return surface; +} + +float3 shadeSdf(float2 uv, float travel, float3 p, float3 normal, int sdfIndex, SdfSurface surface) +{ + float3 viewDirection = normalize(cameraPosition - p); + float rim = pow(1.0 - saturate(dot(normal, viewDirection)), 3.1); + float3 pbr = shadeSdfPbr(p, normal, surface); + float3 cyanRim = float3(0.22, 1.25, 2.4) * rim * 0.75; + return pbr + cyanRim; +} + +#include "D3D12SdfProxy.hlsli" diff --git a/src/Aquarium.Fensalir/Worlds/fensalir-spine-emblem.aquageo b/src/Aquarium.Fensalir/Worlds/fensalir-spine-emblem.aquageo new file mode 100644 index 0000000..a116d18 --- /dev/null +++ b/src/Aquarium.Fensalir/Worlds/fensalir-spine-emblem.aquageo @@ -0,0 +1,16 @@ +# Fensalir splash scene patch. +# The marsh is a 2D surface domain: low height for mirror bed, ripple brushes for +# water motion, and recursive fine claims for small surface texture. +domain Surface2D fensalir/splash - -8 8 -4 6 0 0 0 0 +domain Surface2D fensalir/marsh fensalir/splash -8 8 -4 4 0 0 0 0 +domain Object3D fensalir/hall fensalir/marsh 0 0 0 6 0 0 0 0 +domain Object3D fensalir/spine fensalir/hall 0 0 2.6 3.8 0 0 0 0 +tile PositiveZ 0 0 0 fensalir/marsh-plane fensalir/marsh +height mirror-bed 0 0 8 4.8 0 2.4 1 -0.018 11 water-bed +ripple spine-reflection 0 -0.85 1.18 4.1 0 3.8 0.72 0.012 0.046 20.0 0.22 1.55 17 cyan-ripple +ripple magenta-left -2.4 -0.72 0.64 2.6 0.12 4.4 0.9 0.004 0.022 17.0 0.17 1.42 19 magenta-ripple +ripple magenta-right 2.4 -0.72 0.64 2.6 -0.12 4.4 0.9 0.004 0.022 17.0 0.17 1.42 23 magenta-ripple +ripple hall-wake 0 1.2 4.8 1.2 0 3.0 1.1 -0.006 0.019 11.0 -0.08 1.25 29 hall-wake +ifs edge-reeds 3 2 -6.5 -0.8 0.52 1.8 0.48 3.5 0.91 5.0 1.05 0.006 31 reed-shadow +ifs edge-reeds 3 2 6.5 -0.7 0.52 1.8 0.48 3.5 -0.91 5.0 1.05 0.006 37 reed-shadow +ifs micro-ripples 4 3 0 -1.6 2.8 1.2 0.42 2.6 0.37 6.2 0.8 0.003 41 micro-ripple diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 23bd2d8..9ad8c72 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -208,3 +208,4 @@ {"timestamp":"2026-05-21T11:55:00+01:00","topic":"adaptive-focus-receipt-loop","lesson":"The receipt harness can now close the first residual feedback loop over the same GPU-resident resources. --adaptive-focus requires warmup and readback, runs the warmup epoch, builds visual parity, applies the first view's suggested priority focus to subsequent measured frames, then reports the adaptive focus in the JSON/console receipt. On the local GTX 1070 mixed flame smoke, the previous non-adaptive setup scored 67.07%; adaptive focus suggested 0.516,-0.302 radius 1.794 strength 1 and measured 70.89% at 0.160 ms/frame. This is not final runtime architecture because it uses a blocking readback between epochs, but it proves feedback improves the cache target before building the delayed/GPU-side path.","files":["tools/Aquarium.Fractal.Receipt/Program.cs","state/map.yaml","state/memory.json"],"source":"continued from residual-to-focus analyzer into a measurable adaptive reservoir control loop"} {"timestamp":"2026-05-21T12:05:00+01:00","topic":"fractal-splat-taa-guide-schema","lesson":"D3D12FractalSplatRender now writes the shared reservoir/TAA guide schema instead of leaking backend layer validation into resolver fields. The guide is x combined reservoir confidence, y sample age in frames from the oldest resident Form/Appearance/Transport row update, z domain validity, w invalidation code. This matches D3D12Post.hlsl expectations and docs/temporal-spatial-evidence-reservoir.md; the previous x/y/z = SDF/PBR/radiosity validation mapping made the resolver interpret PBR validation as sample age and radiosity validation as domain validity.","files":["src/Aquarium.Engine/Render/Shaders/D3D12FractalSplatRender.hlsl","state/map.yaml","state/memory.json"],"source":"continued TAA/reservoir integration after noticing the live guide buffer violated its own documented schema"} {"timestamp":"2026-05-21T12:10:00+01:00","topic":"reservoir-guide-debug-view","lesson":"Render debug mode 12 now visualizes the reservoir/TAA guide schema directly: red is current reservoir confidence, green is normalized guide sample age, and blue is domain validity. The previous debug view mixed confidence, temporal detail, and history weight, which made the labeled guide mode unable to diagnose guide-buffer bugs.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","state/map.yaml","state/memory.json"],"source":"continued after fixing the fractal guide producer and checking whether the visible debug mode matched the schema"} +{"timestamp":"2026-05-21T11:42:16+01:00","topic":"fensalir-splash-ripple-scene","lesson":"The first Fensalir art-target client proves a cleaner scene reproduction boundary than more abstract splat demos: the .aquageo patch owns the marsh surface and ripple brushes, FensalirSceneBuilder publishes those brushes plus one bounded SDF spine proxy, and client shaders own the dark reflective water/mist and luminous stacked-diamond hall silhouette. Aetheria's transferable primitive is the compact radial wave splat: envelope * powered cosine, not a bespoke water mesh. Missing future work is now visible at the right boundary: richer material/page DSL for water color/roughness, transparent fog density fields, and an IFS-owned spine/pillar grammar instead of a hand-authored first proxy shader.","files":["src/Aquarium.Fensalir/Worlds/fensalir-spine-emblem.aquageo","src/Aquarium.Fensalir/FensalirRuntime.cs","src/Aquarium.Fensalir/FensalirSceneBuilder.cs","src/Aquarium.Fensalir/Shaders/D3D12FensalirScene.hlsl","src/Aquarium.Fensalir/Shaders/D3D12FensalirSpine.hlsl","src/Aquarium.Engine.Fractal/Grammar/FractalDslCompiler.cs","src/Aquarium.Engine.Fractal/Brushes/FractalHeightBrushCompiler.cs","src/Aquarium.Engine.Contracts/Fractal/AquariumFractalContracts.cs","tests/Aquarium.Engine.Fractal.Tests/FensalirFractalSceneTests.cs","state/map.yaml","state/memory.json"],"source":"user pivoted from abstract Perfect Machine work to reproducing the documented Fensalir splash art as an actual DSL/rendering target"} diff --git a/state/map.yaml b/state/map.yaml index 34fa2e6..fabb821 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -51,6 +51,18 @@ current_model: purpose: > Non-Epiphany planetary-scale rendering demo using the shared Aquarium host, D3D12 renderer, reload transport, UI contracts, bloom, and SDF proxy path. + fensalir_client: + implementation: src/Aquarium.Fensalir + render_plan: src/Aquarium.Fensalir/FensalirRenderPlan.cs + scene_builder: src/Aquarium.Fensalir/FensalirSceneBuilder.cs + shaders: src/Aquarium.Fensalir/Shaders + world_patch: src/Aquarium.Fensalir/Worlds/fensalir-spine-emblem.aquageo + splash_prompt: research/rendering/fensalir-spine-emblem-ifs-demo.md + ground_truth_image: src/Aquarium.Engine/Assets/Fensalir-Splash.png + purpose: > + First artistic Fensalir reconstruction client: loads a .aquageo scene + patch, lowers marsh/water surface claims into shaped 2D ripple brushes, + and renders the central luminous spine through the normal SDF proxy path. samples: minimal_client: src/Aquarium.Sample.Minimal dependencies: @@ -138,6 +150,7 @@ renderer_state: - Fractal residency uses score-per-cost retention under RAM pressure and emits evicted node keys as planner output; real storage mutation waits for a page/payload store boundary. - Compact 3D form splats now have explicit opaque and transparent CPU contracts: structural FractalProbeSample evidence carries layer/encoding metadata, Form/SignedDistance lowers through AquariumFractalSdfSplat3D and FractalSdfSplat3DCompiler, and Form/Density or Form/Extinction lowers through AquariumFractalDensitySplat3D and FractalDensitySplat3DCompiler. The same ResampledImportanceReservoir handles both; lowering rejects wrong encodings instead of silently forcing density through SDF semantics. - The `.aquageo` DSL now accepts `density` and `extinction` field claims using the same compact brush syntax as `height`, and the recursive `flame` primitive emits Density payloads. FractalSummaryBuilder treats Height, SignedDistance, Density, and Extinction as Form contribution. FractalHeightBrushCompiler filters mixed trees to Height payloads for height-field lowering instead of forcing transparent fields into terrain brushes. + - The `.aquageo` DSL also accepts `ripple` claims for 2D surface domains. A ripple is a Height claim with the same compact shaped envelope plus explicit wave amplitude, radial frequency, speed, and sine-power, lowered into the existing AquariumHeightFieldBrush wave lane. This is the Aetheria-style cheap water primitive Fensalir uses for the marsh mirror plane. - Hot fractal splats and their temporal cache layers must be GPU-resident packed buffers. AquariumPackedFractalSdfSplat3D is the first opaque 80-byte numeric Form packet; AquariumPackedFractalDensitySplat3D is the matching 80-byte transparent Form packet for density/extinction. The current SDF envelope, PBR material, and radiosity reservoir packets are distinct 64-byte UAV rows sampled in independent compute passes for Form, Appearance, and Transport, and FractalGpuReservoirBudgetPlanner now reports both backend pass kind and conceptual layer/encoding. SDF/PBR/radiosity are backend packet names, not the conceptual architecture. tools/Aquarium.Fractal.Receipt proves a D3D12 compute path can keep 2,000,000 splats and 2,000,000 reservoirs per layer resident on the GTX 1070. The fallback hash-fractal receipt updates 50,000 entries per reservoir layer per frame with 2 candidates/update and runs at 4.471 ms/frame, 223.7 FPS equivalent. The authored IFS-program path now uses precomposed selected-cut rows instead of replaying ancestry per splat; a depth-48 authored receipt with 4 compact transforms and 15,000 updates per reservoir layer runs at 4.908 ms/frame, 203.7 FPS equivalent, with full reservoir coverage in 133.3 frames. Receipts use only tiny checksum readback and compile the shared engine shader asset src/Aquarium.Engine/Render/Shaders/D3D12FractalReservoirCompute.hlsl. - 2D-projected-to-3D splats have a pure compiler seam: FractalProjectedSdfSplatCompiler maps resident SignedDistance2D page payload samples through an explicit page-to-world function and normal into bounded AquariumFractalSdfSplat3D packets. - AquariumSceneState now carries AquariumFractalReservoirField as the narrow client-to-renderer request for GPU-resident fractal reservoirs: resident splat count, stochastic splat updates per frame, IFS depth/seed, candidates per reservoir update, stochastic updates per pass, authored program transforms, and an explicit world center/radius. This is a budgeted GPU field request, not a CPU splat list. diff --git a/state/memory.json b/state/memory.json index e816a14..1b5b9e8 100644 --- a/state/memory.json +++ b/state/memory.json @@ -33,6 +33,8 @@ ], "rendering": [ "Height-field shape is defined by brush data uploaded by the client. Epiphany currently supplies its gravity wells, CPU placement, and cursor projection; generic engine height-field and scene shaders consume the resulting brush constants.", + "Fensalir is now the engine brand and has a first artistic reconstruction client at src/Aquarium.Fensalir. It loads Worlds/fensalir-spine-emblem.aquageo, lowers the foreground marsh into shaped 2D ripple brushes, renders a custom dark water/mist scene shader, and draws the central luminous stacked-diamond spine through an SDF proxy shader. The splash image at src/Aquarium.Engine/Assets/Fensalir-Splash.png and prompt note at research/rendering/fensalir-spine-emblem-ifs-demo.md are the art target, not incidental branding.", + "The `.aquageo` DSL has a first-class `ripple` primitive for flat surface domains: center, radii, rotation, falloff, shape power, base amplitude, wave amplitude, radial frequency, speed, sine-power, seed, and tags. This is the Aetheria/Epiphany-style compact wave splat lowered into AquariumHeightFieldBrush; do not hard-code future water waves in client C# when the patch should own them.", "The height-field surface is direct-traced as a terminating reflective surface over scalar height data. It writes the primary surface packet with FIELD_ID_HEIGHT_FIELD, terrain normal, full coverage, and Studio2 PMREM reflection; flat regions sample up to PMREM mip 3 while sloped/waved regions sharpen toward mip 0. Ray misses use a cone-averaged Studio2 PMREM mip 3 as the soft background so low-resolution mip texels do not become visible blocks.", "Mouse/cursor-owned SDF bodies need object-motion reprojection. Carry current and previous cursor world anchors through frame constants and reproject cursor hits from current center to previous center.", "The Epiphany cursor locator is currently a luminous five-petal hibiscus SDF in the body proxy pass. Its center stays at cursor XY with z equal to cursor radius, so its contact tip reaches Grid z=0 without sampling or projecting to the Grid surface. The previous MathWorld teardrop curve profile remains reusable SDF math for future objects: x=cos(t), y=sin(t)*sin^m(t/2), radius `sqrt(1 - x^2) * ((1 - x) / 2)^3`.", diff --git a/tests/Aquarium.Engine.Fractal.Tests/Aquarium.Engine.Fractal.Tests.csproj b/tests/Aquarium.Engine.Fractal.Tests/Aquarium.Engine.Fractal.Tests.csproj index 595338b..59d26df 100644 --- a/tests/Aquarium.Engine.Fractal.Tests/Aquarium.Engine.Fractal.Tests.csproj +++ b/tests/Aquarium.Engine.Fractal.Tests/Aquarium.Engine.Fractal.Tests.csproj @@ -22,6 +22,7 @@ + diff --git a/tests/Aquarium.Engine.Fractal.Tests/FensalirFractalSceneTests.cs b/tests/Aquarium.Engine.Fractal.Tests/FensalirFractalSceneTests.cs new file mode 100644 index 0000000..1bf7d54 --- /dev/null +++ b/tests/Aquarium.Engine.Fractal.Tests/FensalirFractalSceneTests.cs @@ -0,0 +1,37 @@ +using Aquarium.Fensalir; + +namespace Aquarium.Engine.Fractal.Tests; + +public sealed class FensalirFractalSceneTests +{ + [Fact] + public void FensalirSceneLoadsSplashPatchFromAquageoFile() + { + var tree = FensalirFractalScene.OwnershipTree; + var brushes = FensalirFractalScene.HeightBrushes; + + Assert.EndsWith(".aquageo", FensalirFractalScene.PatchPath, StringComparison.Ordinal); + Assert.True(File.Exists(FensalirFractalScene.PatchPath), $"Expected copied aquageo patch at {FensalirFractalScene.PatchPath}."); + Assert.Contains(tree.Domains, domain => domain.Kind == AquariumFractalDomainKind.Surface2D && domain.Key.Value == "fensalir/marsh"); + Assert.Contains(tree.Domains, domain => domain.Kind == AquariumFractalDomainKind.Object3D && domain.Key.Value == "fensalir/spine"); + Assert.Contains(tree.Claims, claim => claim.Tags == "cyan-ripple" && claim.WaveAmplitude > 0.0f); + Assert.Contains(tree.Claims, claim => claim.Tags == "micro-ripple"); + Assert.Equal(tree.Claims.Count(claim => claim.PayloadKind == AquariumFractalPayloadKind.Height), brushes.Length); + Assert.Contains(brushes, brush => brush.WaveAmplitude > 0.0f && brush.WaveFrequency > 0.0f && brush.WaveSinePower > 0.0f); + Assert.Contains("surface brushes", FensalirFractalScene.Summary, StringComparison.Ordinal); + } + + [Fact] + public void FensalirSceneBuildsReflectiveSurfaceAndSpineProxy() + { + var scene = FensalirSceneBuilder.Build(1.0f, 0.9f); + + Assert.True(scene.TraceHeightFieldSurface); + Assert.False(scene.UseStarfieldBackground); + Assert.NotEmpty(scene.HeightFieldBrushes); + var spine = Assert.Single(scene.SdfObjects); + Assert.True(spine.CenterRadius.W >= 5.0f); + Assert.Equal(FensalirRenderPlan.SpineIndex, 0); + Assert.True(scene.SdfLights.Count >= 1); + } +} diff --git a/tests/Aquarium.Engine.Fractal.Tests/FractalDslCompilerTests.cs b/tests/Aquarium.Engine.Fractal.Tests/FractalDslCompilerTests.cs index 0dbd4f8..0ec73e2 100644 --- a/tests/Aquarium.Engine.Fractal.Tests/FractalDslCompilerTests.cs +++ b/tests/Aquarium.Engine.Fractal.Tests/FractalDslCompilerTests.cs @@ -101,6 +101,26 @@ public sealed class FractalDslCompilerTests Assert.Equal(0.35f, tree.Claims[1].Amplitude); } + [Fact] + public void DslRippleClaimCarriesAetheriaStyleWaveEnvelope() + { + const string source = """ + tile PositiveZ 0 0 0 fensalir/marsh + ripple spine-reflection 0 -1 1.2 4.0 0.1 3.8 0.72 0.012 0.046 20.0 0.22 1.55 17 cyan-ripple + """; + + var tree = FractalDslCompiler.Compile(source); + var claim = Assert.Single(tree.Claims); + + Assert.Equal(AquariumFractalPayloadKind.Height, claim.PayloadKind); + Assert.Equal("cyan-ripple", claim.Tags); + Assert.Equal(0.012f, claim.Amplitude); + Assert.Equal(0.046f, claim.WaveAmplitude); + Assert.Equal(20.0f, claim.WaveFrequency); + Assert.Equal(0.22f, claim.WaveSpeed); + Assert.Equal(1.55f, claim.WaveSinePower); + } + [Fact] public void DslPreservesMultipleTileRoots() {