From 3bf608e70b4a58adca0dc0eaf23378f3b34ad98e Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 11 May 2026 16:30:27 +0100 Subject: [PATCH] Make Imagination SDF lobes continuous --- .../Render/Shaders/D3D12Scene.hlsl | 47 ++++++++++++------- state/evidence.jsonl | 1 + state/memory.json | 1 + 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl b/src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl index fe80e74..5b58280 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl @@ -307,21 +307,30 @@ float sdSuperellipsoid(float3 p, float3 scale, float exponent) return (value - 1.0) * min(scale.x, min(scale.y, scale.z)); } +float sdEllipsoid(float3 p, float3 radius) +{ + float3 safeRadius = max(radius, 0.001); + float k0 = length(p / safeRadius); + float k1 = length(p / (safeRadius * safeRadius)); + return k0 * (k0 - 1.0) / max(k1, 0.001); +} + float smoothUnion(float a, float b, float radius) { float h = saturate(0.5 + 0.5 * (b - a) / radius); return lerp(b, a, h) - radius * h * (1.0 - h); } -float harmonic5(float2 direction, float phase) +float imaginationPetalSdf(float3 local, float angle, float activity, float heartbeat) { - float x = direction.x; - float y = direction.y; - float x2 = x * x; - float y2 = y * y; - float cos5 = x * (x2 * x2 - 10.0 * x2 * y2 + 5.0 * y2 * y2); - float sin5 = y * (5.0 * x2 * x2 - 10.0 * x2 * y2 + y2 * y2); - return cos5 * cos(phase) + sin5 * sin(phase); + float2 radial = float2(cos(angle), sin(angle)); + float2 tangent = float2(-radial.y, radial.x); + float phase = timeSeconds * 1.15 + angle * 1.7 + heartbeat * 6.28318; + float3 petalCenter = float3(radial * (0.24 + activity * 0.08), 0.03 * sin(phase)); + float3 p = local - petalCenter; + float3 q = float3(dot(p.xy, radial), dot(p.xy, tangent), p.z); + float3 petalRadius = float3(0.44 + activity * 0.05, 0.20, 0.58 + 0.06 * sin(phase)); + return sdEllipsoid(q, petalRadius); } AgentSurface agentBodySdf(float3 local, AgentVisual agent) @@ -345,18 +354,24 @@ AgentSurface agentImaginationSdf(float3 local, AgentVisual agent) { float activity = agent.state.x; float heartbeat = agent.state.y; - float radial = max(length(local.xy), 0.0001); - float2 direction = local.xy / radial; - float lobeWave = harmonic5(direction, timeSeconds * 1.7); - float verticalWave = sin(local.z * 7.0 + heartbeat * 6.28318); - float polar = 0.58 + lobeWave * (0.07 + activity * 0.09); - float lobe = length(local) - polar * (1.0 + 0.06 * verticalWave); + float core = sdSuperellipsoid(local, float3(0.48 + activity * 0.08, 0.48 + activity * 0.08, 0.54), 1.18); + float phase = timeSeconds * 0.42; + float petal0 = imaginationPetalSdf(local, phase, activity, heartbeat); + float petal1 = imaginationPetalSdf(local, phase + 1.2566371, activity, heartbeat); + float petal2 = imaginationPetalSdf(local, phase + 2.5132741, activity, heartbeat); + float petal3 = imaginationPetalSdf(local, phase + 3.7699112, activity, heartbeat); + float petal4 = imaginationPetalSdf(local, phase + 5.0265482, activity, heartbeat); + float bloom = smoothUnion(core, petal0, 0.18); + bloom = smoothUnion(bloom, petal1, 0.18); + bloom = smoothUnion(bloom, petal2, 0.18); + bloom = smoothUnion(bloom, petal3, 0.18); + bloom = smoothUnion(bloom, petal4, 0.18); float ring = sdTorus(local, float2(0.72 + activity * 0.08, 0.032)); float halo = sdTorus(local.zxy, float2(0.50, 0.024)); float detail = min(ring, halo); AgentSurface surface; - surface.distanceValue = smoothUnion(lobe, detail, 0.035); - surface.materialId = lobe <= detail ? 2.0 : 2.4; + surface.distanceValue = smoothUnion(bloom, detail, 0.035); + surface.materialId = bloom <= detail ? 2.0 : 2.4; surface.costTier = 2.0; return surface; } diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 1c1e50a..e3af118 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -23,3 +23,4 @@ {"timestamp":"2026-05-11T09:40:00+01:00","topic":"agent-sdf-realtime-rendering-plan","lesson":"Agent role SDFs should render as bounded per-agent implicit objects, not one scene-global mega-SDF. Use conservative sphere-tracing distances, proxy rasterization, one role SDF selected after proxy hit, local bounds for expensive features, post-hit normals, cheap shadows, pixel-footprint hit epsilon, LOD tiers, and debug views for step count, proxy hits, material id, LOD, and SDF cost.","files":["docs/epiphany-agent-sdf-visual-language.md","state/memory.json"],"source":"Hart sphere tracing, Enhanced Sphere Tracing, Inigo Quilez SDF bounding, CTSS, NVIDIA SDF grids"} {"timestamp":"2026-05-11T16:18:00+01:00","topic":"agent-visual-state-first-slice","lesson":"The fixed orbit bodies are now backed by an AgentVisualGpu buffer carrying current center, previous center, role id, state scalars, and LOD. D3D12Scene uses the buffer for bounded agent SDF hits; D3D12Post uses the same buffer for agent temporal reprojection. Body and Imagination are the first LOD 1 role SDFs, with debug modes for role, material, step count, LOD, and cost.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","src/Aquarium.Engine.Contracts/GraphicsSettings.cs","docs/hlsl-renderer.md","state/map.yaml","state/memory.json"]} {"timestamp":"2026-05-11T16:28:00+01:00","topic":"agent-sdf-polar-seams","lesson":"Do not animate role SDF lobes with raw atan2 angle fields inside the traced distance function; the polar branch cut creates visible cracks and sliced surfaces. Use continuous harmonic polynomial lobes over normalized directions, widen conservative proxy bounds, and reduce march step scale for distance-ish composite organs.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","state/memory.json"],"source":"visible artifact review"} +{"timestamp":"2026-05-11T16:32:00+01:00","topic":"imagination-sdf-connected-lobes","lesson":"Continuous polar harmonics can still behave like a decorative pseudo-distance and leave visible petal gaps. Imagination now uses a central superquadric plus smooth-unioned ellipsoid petals, keeping the bloom continuous enough for bounded sphere tracing while preserving the five-lobed visual character.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","state/memory.json"],"source":"visible artifact review"} diff --git a/state/memory.json b/state/memory.json index a823fea..7c53aed 100644 --- a/state/memory.json +++ b/state/memory.json @@ -36,6 +36,7 @@ "Realtime role SDFs must render through per-agent proxy bounds, not a scene-global mega-SDF. Sphere-trace only conservative distance bounds, select one role SDF after proxy hit, give every expensive feature a local bound, compute normals only after hit, and require LOD plus debug views for step count, proxy hits, material id, LOD tier, and SDF cost tier before adding full organ detail.", "The first live AgentVisualState slice uploads current and previous centers, role id, state scalars, and LOD through AgentVisualGpu. Temporal reprojection must use those uploaded centers for agent field ids; do not rederive moving agent centers separately in post.", "Role SDF animation should avoid raw atan2 polar fields for lobe deformation unless the branch cut is explicitly handled. Use continuous harmonic polynomials over normalized XY directions for rotational lobes so sphere tracing does not open visible seams.", + "If a role SDF still shows cut-through gaps after removing angular branch cuts, stop using radial pseudo-distance deformation for that organ. Prefer smooth unions of analytic primitives with conservative bounds so the marcher sees connected surfaces instead of decorative distance fiction.", "Heavy/specialized SDF evaluators should not live inside generic packed-id helpers when those helpers are called repeatedly; avoid shader compiler path cloning.", "Lighting is diegetic. Self is the initial emitter; later other Selves should emit through an explicit body light lane, not generic field instances or ambient convenience fill.", "Keep bundled blue-noise texture assets available for future dithering/noise work even when no current pass samples them.",