Rewrite Life as spiral shell SDF

This commit is contained in:
Meta Vens 2026-05-14 01:51:59 +01:00
commit 4db3916e9c
4 changed files with 248 additions and 7 deletions

View file

@ -2,31 +2,254 @@ static const int SDF_INDEX = 7;
#include "D3D12SdfCommon.hlsli"
#include "D3D12SdfMath.hlsli"
#include "D3D12AgentCharacters.hlsli"
struct LifeDomain
{
float body;
float outerShell;
float innerCavity;
float rib;
float seam;
float innerBowl;
float bead;
float ember;
float crack;
float spiralLine;
float aperture;
float2 shellUv;
};
float lifeSpiralPhase(float2 uv)
{
float r = max(length(uv), 0.035);
float theta = atan2(uv.y, uv.x);
return theta - 1.42 * log(r + 0.075);
}
float lifeSpiralLine(float2 uv, float phaseOffset)
{
float r = max(length(uv), 0.035);
float phase = lifeSpiralPhase(uv) + phaseOffset;
return abs(sin(phase)) * r;
}
float lifeShellRadius(float theta, float pressure)
{
float broad = 0.45 + 0.19 * cos(theta - 0.10);
float lip = 0.10 * cos(theta * 2.0 + 0.62);
float livingAsymmetry = 0.035 * sin(theta * 3.0 - 0.7);
return max(0.22, (broad + lip + livingAsymmetry) * lerp(1.0, 0.92, pressure));
}
float lifeShellSurface(float3 local, float pressure, out float shellBoundary, out float sideBoundary, out float aperture)
{
float2 uv = float2(local.x + 0.030, local.z - 0.005);
float r = length(uv);
float theta = atan2(uv.y, uv.x);
float shellRadius = lifeShellRadius(theta, pressure);
float cardioidBoundary = r - shellRadius;
float3 ellipsoidCenter = float3(0.080, 0.000, -0.005);
float3 ellipsoidRadius = float3(0.68, 0.37, 0.58) * (1.0 - pressure * 0.045);
float ellipsoid = sdEllipsoid(local - ellipsoidCenter, ellipsoidRadius);
float mantleBias = smoothstep(-0.02, 0.20, -cardioidBoundary) * 0.018;
float outerBody = ellipsoid - mantleBias;
shellBoundary = outerBody;
sideBoundary = ellipsoid;
float3 cavityCenter = float3(-0.365, -0.080, 0.065);
float cavity = sdEllipsoid(local - cavityCenter, float3(0.34, 0.27, 0.41));
float mouthBias = dot(normalize(float3(-0.90, -0.24, 0.13)), local - cavityCenter);
aperture = max(cavity, -mouthBias - 0.19);
return max(outerBody, -aperture);
}
float lifeRibDistance(float3 local, float shellBoundary, float sideBoundary, float pressure)
{
float2 uv = float2(local.x + 0.030, local.z - 0.005);
float r = max(length(uv), 0.035);
float theta = atan2(uv.y, uv.x);
float ribs = abs(sin((theta - 1.05 * log(r + 0.085)) * 9.0 + 0.35 * sin(theta * 2.0))) * r;
float ribWidth = lerp(0.018, 0.027, pressure);
float shellBand = abs(shellBoundary + 0.020) - 0.030;
float sideMask = sideBoundary - 0.035;
return max(max(shellBand, ribs - ribWidth), sideMask);
}
float lifeSeamDistance(float3 local, float shellBoundary, float sideBoundary, float pressure, out float spiralLine)
{
float2 uv = float2(local.x + 0.030, local.z - 0.005);
spiralLine = lifeSpiralLine(uv, -0.34);
float seamWidth = lerp(0.016, 0.036, pressure);
float surfaceBand = abs(shellBoundary + 0.010) - 0.020;
float frontBand = abs(local.y + 0.192) - 0.035;
float lip = max(max(surfaceBand, frontBand), spiralLine - seamWidth);
float cavityLip = abs(length((local - float3(-0.360, -0.090, 0.065)).xz / float2(0.34, 0.43)) - 1.0) * 0.10;
float apertureRim = max(abs(local.y + 0.165) - 0.026, cavityLip - 0.013);
return min(lip, apertureRim);
}
float lifeBeadDistance(float3 local, float pressure)
{
float bead = 10.0;
[unroll]
for (int i = 0; i < 15; i++)
{
float t = ((float)i + 0.25) / 14.5;
float angle = 2.78 - t * 5.15;
float rr = 0.075 * exp(t * 1.96);
float2 uv = rr * float2(cos(angle), sin(angle));
float side = -0.245 + 0.018 * sin(t * 6.2831853);
float3 center = float3(uv.x - 0.030, side, uv.y + 0.005);
float beadRadius = lerp(0.022, 0.050, smoothstep(0.20, 0.86, t));
beadRadius *= 1.0 - pressure * 0.16;
bead = min(bead, sdSphere(local - center, beadRadius));
}
return bead;
}
float lifeInnerBowlDistance(float3 local)
{
float2 bowlCenter = float2(-0.300, 0.070);
float2 q = (local.xz - bowlCenter) / float2(0.33, 0.42);
float footprint = (length(q) - 1.0) * 0.33;
float cup = saturate(1.0 - length(q));
float targetY = -0.238 + cup * 0.070;
float sheet = abs(local.y - targetY) - 0.020;
float spiralGrain = lifeSpiralLine(local.xz - float2(-0.030, 0.005), 0.38) - 0.012;
return max(max(footprint, sheet), min(spiralGrain, 0.018));
}
float lifeCrackLine(float3 local, float shellBoundary, float sideBoundary)
{
float2 uv = float2(local.x + 0.030, local.z - 0.005);
float r = max(length(uv), 0.035);
float theta = atan2(uv.y, uv.x);
float webA = abs(sin(theta * 13.0 + log(r + 0.075) * 18.0 + sin(theta * 4.0))) * r;
float webB = abs(sin(theta * 19.0 - log(r + 0.110) * 11.0 + 1.7)) * r;
float vein = min(webA, webB);
float surfaceBand = abs(shellBoundary + 0.003) - 0.012;
float sideMask = sideBoundary - 0.020;
return max(max(surfaceBand, vein - 0.0045), sideMask);
}
LifeDomain lifeDomain(float3 local, SdfObject sdfObject)
{
float pressure = saturate(sdfObject.state.z + (1.0 - sdfObject.state.y) * 0.18);
float shellBoundary;
float sideBoundary;
float aperture;
float shell = lifeShellSurface(local, pressure, shellBoundary, sideBoundary, aperture);
float rib = lifeRibDistance(local, shellBoundary, sideBoundary, pressure);
float spiralLine;
float seam = lifeSeamDistance(local, shellBoundary, sideBoundary, pressure, spiralLine);
float innerBowl = lifeInnerBowlDistance(local);
float bead = lifeBeadDistance(local, pressure);
float ember = sdSphere(local - float3(0.030, -0.178, 0.020), 0.072 + sdfObject.state.y * 0.012);
float crack = lifeCrackLine(local, shellBoundary, sideBoundary);
LifeDomain domain;
domain.body = min(min(shell, rib), min(min(seam, innerBowl), min(bead, ember)));
domain.outerShell = shell;
domain.innerCavity = -aperture;
domain.rib = rib;
domain.seam = seam;
domain.innerBowl = innerBowl;
domain.bead = bead;
domain.ember = ember;
domain.crack = crack;
domain.spiralLine = spiralLine;
domain.aperture = aperture;
domain.shellUv = float2(local.x + 0.030, local.z - 0.005);
return domain;
}
float sdfDistance(float3 p, int sdfIndex)
{
SdfObject sdfObject = sdfObjects[sdfIndex];
float radius = max(sdfObject.centerRadius.w, 0.001);
float3 local = (p - sdfObject.centerRadius.xyz) / radius;
return sdfObjectFallbackSdf(local, sdfObject) * radius;
return lifeDomain(local, sdfObject).body * radius;
}
SdfSurface sdfSurface(float3 p, int sdfIndex)
{
SdfObject sdfObject = sdfObjects[sdfIndex];
float radius = max(sdfObject.centerRadius.w, 0.001);
float3 local = (p - sdfObject.centerRadius.xyz) / radius;
LifeDomain domain = lifeDomain(local, sdfObject);
float activity = saturate(sdfObject.state.x);
float heartbeat = saturate(sdfObject.state.y);
float pressure = saturate(sdfObject.state.z + (1.0 - heartbeat) * 0.18);
float shellDetail = min(min(domain.outerShell, domain.rib), min(domain.seam, domain.innerBowl));
float isEmber = domain.ember <= min(shellDetail, domain.bead) ? 1.0 : 0.0;
float isBead = (1.0 - isEmber) * (domain.bead <= shellDetail ? 1.0 : 0.0);
float isBowl = (1.0 - isEmber) * (1.0 - isBead) * (domain.innerBowl <= min(min(domain.outerShell, domain.rib), domain.seam) ? 1.0 : 0.0);
float isSeam = (1.0 - isEmber) * (1.0 - isBead) * (1.0 - isBowl) * (domain.seam <= min(domain.outerShell, domain.rib) ? 1.0 : 0.0);
float isRib = (1.0 - isEmber) * (1.0 - isBead) * (1.0 - isBowl) * (1.0 - isSeam) * (domain.rib <= domain.outerShell ? 1.0 : 0.0);
float isShell = (1.0 - isEmber) * (1.0 - isBead) * (1.0 - isBowl) * (1.0 - isSeam) * (1.0 - isRib);
float inner = saturate(isBowl + isShell * (domain.innerCavity >= domain.outerShell ? 1.0 : 0.0));
float crackMask = isShell * (1.0 - inner) * (1.0 - smoothstep(0.000, 0.010, domain.crack));
float nacre = 0.5 + 0.5 * sin(lifeSpiralPhase(domain.shellUv) * 7.0 + local.y * 16.0 + timeSeconds * 0.18);
float3 teal = lerp(float3(0.026, 0.34, 0.38), float3(0.10, 0.62, 0.66), nacre);
float3 innerGold = lerp(float3(0.92, 0.47, 0.10), float3(1.0, 0.78, 0.28), nacre);
float3 ribGold = float3(1.0, 0.86, 0.58);
float3 beadPearl = lerp(float3(0.86, 0.78, 0.62), float3(1.0, 0.96, 0.82), nacre);
float3 ember = float3(1.0, 0.48, 0.08);
float3 crackGold = float3(0.95, 0.56, 0.16);
SdfSurface surface;
surface.baseColor = lerp(float3(0.18, 0.54, 0.16), float3(0.76, 1.0, 0.42), sdfObject.state.y);
surface.metallic = 0.0;
surface.roughness = 0.62;
surface.emission = primitiveEmissionRadiance(sdfFieldId(sdfIndex)) + surface.baseColor * 0.05;
surface.baseColor = teal * isShell * (1.0 - inner)
+ innerGold * inner
+ innerGold * isBowl
+ ribGold * isRib
+ ribGold * isSeam
+ beadPearl * isBead
+ ember * isEmber;
surface.baseColor = lerp(surface.baseColor, crackGold, crackMask * 0.70);
surface.metallic = 0.0 * isShell + 0.42 * isRib + 0.28 * isSeam + 0.0 * (isBowl + isBead + isEmber);
surface.roughness = 0.24 * isShell + 0.18 * inner + 0.13 * isRib + 0.11 * isSeam + 0.10 * isBead + 0.30 * isEmber;
float3 lifeLight = primitiveEmissionRadiance(sdfFieldId(sdfIndex));
surface.emission = lifeLight * 0.03
+ teal * isShell * (1.0 - inner) * 0.030
+ innerGold * inner * (0.34 + heartbeat * 0.36)
+ ribGold * isRib * 0.070
+ ribGold * isSeam * (0.34 + activity * 0.22)
+ beadPearl * isBead * (0.24 + heartbeat * 0.20)
+ ember * isEmber * (2.4 + heartbeat * 1.1)
+ crackGold * crackMask * (0.06 + pressure * 0.18);
return surface;
}
float3 shadeSdf(float2 uv, float travel, float3 p, float3 normal, int sdfIndex, SdfSurface surface)
{
return shadeSdfPbr(p, normal, surface);
SdfObject sdfObject = sdfObjects[sdfIndex];
float radius = max(sdfObject.centerRadius.w, 0.001);
float3 local = (p - sdfObject.centerRadius.xyz) / radius;
LifeDomain domain = lifeDomain(local, sdfObject);
float3 pbr = shadeSdfPbr(p, normal, surface);
float3 viewDirection = normalize(cameraPosition - p);
float edge = pow(1.0 - saturate(dot(normal, viewDirection)), 3.4);
float warmCore = exp(-dot(local - float3(0.030, -0.178, 0.020), local - float3(0.030, -0.178, 0.020)) * 9.0);
float seamGlow = 1.0 - smoothstep(0.0, 0.030, min(domain.seam, domain.spiralLine));
float shellOnly = domain.outerShell <= min(min(domain.rib, domain.seam), min(domain.bead, domain.ember)) ? 1.0 : 0.0;
return pbr
+ float3(1.0, 0.50, 0.10) * warmCore * 0.42
+ float3(0.90, 0.72, 0.42) * seamGlow * 0.08
+ float3(0.16, 0.74, 0.78) * edge * shellOnly * 0.18;
}
#define SDF_TRACE_STEP_SCALE 0.16
#define SDF_TRACE_MAX_STEP_RADIUS_SCALE 0.008
#include "D3D12SdfProxy.hlsli"

View file

@ -94,3 +94,4 @@
{"timestamp":"2026-05-13T20:00:00+01:00","topic":"soul-plane-intersection-crystal","lesson":"Soul seams are not unreasonable as geometry: build the crystal from explicit signed half-space planes, derive edges from adjacent active plane intersections, then extrude face interiors and cut narrow V-grooves on selected edge chains. Auxiliary gates may choose which edges glow, but the edge itself must come from the plane intersection graph. Broad shading uses the active plane normal; cut normals are secondary.","files":["src/Aquarium.Epiphany/Shaders/D3D12SoulAgent.hlsl","state/evidence.jsonl"],"source":"user asked for organic plane intersections with extruded faces and glowing groove centers"}
{"timestamp":"2026-05-13T20:18:00+01:00","topic":"soul-organic-plane-family","lesson":"Soul's plane-intersection crystal should not default back to symmetric octahedral sign pairs. Keep the half-space/active-edge architecture, but use an irregular family of constraint planes with varied offsets plus a few smaller trimming planes so the crystal reads as a living verdict object instead of an octahedron with minor perturbations.","files":["src/Aquarium.Epiphany/Shaders/D3D12SoulAgent.hlsl","state/evidence.jsonl"],"source":"user noted the plane-intersection model was right but the cutting planes still looked too octahedral"}
{"timestamp":"2026-05-13T20:56:00+01:00","topic":"isolated-agent-preview-loop","lesson":"Agent SDF iteration needs a renderer-owned visual feedback loop. Use the real D3D12 renderer to render one selected Epiphany SDF subject across several isolated camera views, then save final-frame PNGs for reference-art comparison. Preview-only isolation belongs in the preview render plan/shader, not in regular scene frame controls; do not duplicate SDF shader logic in a separate toy renderer.","files":["src/Aquarium.Epiphany.AgentPreview/Program.cs","src/Aquarium.Epiphany.AgentPreview/Shaders/D3D12AgentPreviewScene.hlsl","scripts/render-agent-preview.ps1","src/Aquarium.Engine/Render/D3D12Renderer.cs","state/map.yaml","state/evidence.jsonl"],"source":"user requested self-directed visual iteration, then caught preview isolation leaking into the normal client"}
{"timestamp":"2026-05-14T01:50:00+01:00","topic":"life-shell-domain","lesson":"Life reads as a nautilus only when volume and ornament have separate but coherent authority: rounded shell volume owns the silhouette, while logarithmic shell coordinates own ribs, seam glow, cracks, aperture grain, and bead samples. Making the shell an extruded cardioid disk created a cylindrical side view; using a rounded volume with spiral-domain surface grammar captured the reference energy more cleanly.","files":["src/Aquarium.Epiphany/Shaders/D3D12LifeAgent.hlsl","state/life-agent-sdf-notes.md","state/map.yaml","state/evidence.jsonl"],"source":"self-directed Life SDF iteration against imagegen reference"}

View file

@ -0,0 +1,16 @@
# Life Agent SDF Notes
Reference: `artifacts/ig_0b80263584b1a81e016a051475aeac8191acb0ced03b9a3e7e.png`.
Working model:
- The readable form is a memory nautilus, not a generic seed.
- A rounded ellipsoid owns the volume; an attempted extruded cardioid disk made side views look cylindrical.
- The logarithmic shell domain owns spiral ribs, seam glow, crack veins, aperture grain, and bead placement.
- The aperture needs a warm inner bowl or it collapses into empty black background in isolated previews.
- Beads are allowed to be discrete samples because the spec calls them beads, but their positions should still be samples of the shell spiral instead of arbitrary orbit dots.
Latest preview used for judgment:
- `artifacts/agent-previews/Life/20260514-014531/life-front.png`
- `artifacts/agent-previews/Life/20260514-014531/life-three-quarter.png`

View file

@ -79,6 +79,7 @@ renderer_state:
- Epiphany's cursor is a luminous five-petal hibiscus SDF centered one cursor radius above the XY plane so its contact tip reaches Grid z=0 without projecting to the Grid surface.
- SDF/analytic Epiphany role visuals upload current centers, previous centers, and state scalars through the public `AquariumSdfObject` contract.
- Agent SDF visual language is documented against Epiphany's published CultNet surfaces: identity from agent memory, motion from heartbeat, posture from role/coordinator/result surfaces, pressure from reorient/pressure surfaces, and expression through bounded orbit wandering plus CPU-visible gravity-well pulses.
- Life is a memory-nautilus SDF owned by a logarithmic shell domain: rounded teal shell volume, shared spiral ribs/seam/crack masks, warm aperture bowl, ember, and memory beads all derive from the same local shell coordinates rather than a fallback primitive.
- SDF light buffer feeds Self emission and direct object lighting; future other Selves should join this light lane, not a generic field-instance table.
- Studio2 PMREM and irradiance DDS cubemaps are loaded as D3D12 TextureCubes; PMREM serves roughness-mip specular, irradiance serves Lambertian diffuse IBL for non-metal bodies.
- DirectWrite/Direct2D unified debug panel with tabs for Aquarium renderer controls, client-declared debug panels, terminal commands, and engine/client tooling surfaces.