diff --git a/src/Aquarium.Engine/Assets/Textures/studio3_irradiance.dds b/src/Aquarium.Engine/Assets/Textures/studio3_irradiance.dds new file mode 100644 index 0000000..ffb7fdb Binary files /dev/null and b/src/Aquarium.Engine/Assets/Textures/studio3_irradiance.dds differ diff --git a/src/Aquarium.Engine/Assets/Textures/studio3_pmrem.dds b/src/Aquarium.Engine/Assets/Textures/studio3_pmrem.dds new file mode 100644 index 0000000..a5097bd Binary files /dev/null and b/src/Aquarium.Engine/Assets/Textures/studio3_pmrem.dds differ diff --git a/src/Aquarium.Engine/Render/D3D12Renderer.cs b/src/Aquarium.Engine/Render/D3D12Renderer.cs index a1d9e6a..c1a08a8 100644 --- a/src/Aquarium.Engine/Render/D3D12Renderer.cs +++ b/src/Aquarium.Engine/Render/D3D12Renderer.cs @@ -35,8 +35,8 @@ public sealed class D3D12Renderer : IAquariumRenderer private const float SurfaceTransparentMaxZ = 0.45f; private const int BloomLevelCount = 3; private const Format SceneHdrFormat = Format.R16G16B16A16_Float; - private const string StudioPmremRelativePath = "Assets/Textures/studio2_pmrem.dds"; - private const string StudioIrradianceRelativePath = "Assets/Textures/studio2_irradiance.dds"; + private const string StudioPmremRelativePath = "Assets/Textures/studio3_pmrem.dds"; + private const string StudioIrradianceRelativePath = "Assets/Textures/studio3_irradiance.dds"; private const int RootFrameConstants = 0; private const int RootSourceTexture = 1; private const int RootHeightFieldBrushes = 2; diff --git a/src/Aquarium.Epiphany/Shaders/D3D12LifeAgent.hlsl b/src/Aquarium.Epiphany/Shaders/D3D12LifeAgent.hlsl index f01c878..fe52d6d 100644 --- a/src/Aquarium.Epiphany/Shaders/D3D12LifeAgent.hlsl +++ b/src/Aquarium.Epiphany/Shaders/D3D12LifeAgent.hlsl @@ -3,20 +3,39 @@ static const int SDF_INDEX = 7; #include "D3D12SdfCommon.hlsli" #include "D3D12SdfMath.hlsli" +static const float LIFE_B = 0.125; +static const float LIFE_PROFILE_B = 0.175; +static const float LIFE_PROFILE_START_RADIUS = 0.030; +static const float LIFE_PROFILE_END_RADIUS = 0.0; +static const float LIFE_TURNS = 3.10; +static const float LIFE_WALL = 0.020; +static const float LIFE_C_SPAN = 4.25; +static const float LIFE_OPEN_CENTER = PI; +static const float LIFE_APERTURE_FLARE = 0.0; +static const float LIFE_CONTACT_PULL = 1.0; +static const float LIFE_CONTACT_SPAN_PULL = 1.0; +static const float LIFE_TERMINAL_U = 0.34; + +static const float LIFE_MAT_OUTER = 1.0; +static const float LIFE_MAT_INNER = 2.0; +static const float LIFE_MAT_SEAM = 3.0; +static const float LIFE_MAT_PEARL = 4.0; +static const float LIFE_MAT_EMBER = 5.0; + struct LifeDomain { float body; float shell; - float aperture; float ember; float seam; - float bead; - float rib; - float crack; + float pearl; float lip; - float spiral; - float spiralStep; - float surfaceBand; + float mat; + float u; + float v; + float w; + float edge; + float endpoint; float pressure; }; @@ -27,117 +46,267 @@ float2 lifeRotate2(float2 p, float angle) return float2(c * p.x - s * p.y, s * p.x + c * p.y); } -float lifeHash(float n) +float lifeTri(float x) { - return frac(sin(n * 127.1) * 43758.5453); + return abs(frac(x) - 0.5) * 2.0; } -float lifeSeedShell(float3 p, float pressure, out float surfaceBand) +float lifeHash21(float2 p) { - float2 q = p.xz - float2(0.105, -0.015); - float angle = atan2(q.y, q.x); - float directionalRadius = 0.66 - + 0.16 * cos(angle + 0.05) - + 0.06 * cos(2.0 * angle + 0.35) - - 0.035 * cos(3.0 * angle - 0.40); - float thickness = 0.330 + 0.075 * smoothstep(-0.55, 0.45, p.x) + 0.030 * cos(angle + 0.20); - float3 normalized = float3(q.x / max(directionalRadius * 1.12, 0.001), - p.y / max(thickness, 0.001), - q.y / max(directionalRadius * 0.93, 0.001)); - float shell = (length(normalized) - 1.0) * min(thickness, directionalRadius * 0.93); - float dome = sdEllipsoid(p - float3(0.135, 0.000, 0.015), float3(0.72, 0.43, 0.60)); - shell = smoothUnion(shell, dome + 0.020, 0.060); - - float breathe = 0.010 * sin(timeSeconds * 1.2 + angle * 1.7) * (1.0 - pressure * 0.45); - surfaceBand = abs(shell) - 0.030; - return shell + breathe; + return frac(sin(dot(p, float2(127.1, 311.7))) * 43758.5453); } -float lifeSpiralField(float2 p, out float nearestTurn, out float stepAlong) +float2 lifeHash22(float2 p) { - float2 q = p + float2(0.055, -0.015); - float radius = max(length(q), 0.035); - float theta = atan2(q.y, q.x); - const float growth = 0.185; - const float startRadius = 0.050; - - float turn = (log(radius / startRadius) / growth - theta) / (2.0 * PI); - nearestTurn = clamp(round(turn), 0.0, 3.0); - float targetRadius = startRadius * exp(growth * (theta + 2.0 * PI * nearestTurn)); - float radialError = radius - targetRadius; - stepAlong = theta + 2.0 * PI * nearestTurn; - return abs(radialError); + float2 q = float2(dot(p, float2(127.1, 311.7)), dot(p, float2(269.5, 183.3))); + return frac(sin(q) * 43758.5453); } -float lifeAperture(float3 p, float pressure) +float lifeVoronoiEdge(float2 p) { - float3 q = p - float3(-0.345 + pressure * 0.055, -0.045, 0.050); - q.xz = lifeRotate2(q.xz, -0.28); - float bowl = sdEllipsoid(q, float3(0.435 - pressure * 0.035, 0.375, 0.335 - pressure * 0.018)); - float mouthGate = p.x + 0.180 + pressure * 0.060; - return max(bowl, mouthGate); + float2 cell = floor(p); + float2 local = frac(p); + float nearest = 8.0; + float nextNearest = 8.0; + + [unroll] + for (int y = -1; y <= 1; y++) + { + [unroll] + for (int x = -1; x <= 1; x++) + { + float2 offset = float2((float)x, (float)y); + float2 jitter = lifeHash22(cell + offset); + float2 d = offset + jitter - local; + float distanceSquared = dot(d, d); + if (distanceSquared < nearest) + { + nextNearest = nearest; + nearest = distanceSquared; + } + else if (distanceSquared < nextNearest) + { + nextNearest = distanceSquared; + } + } + } + + return sqrt(nextNearest) - sqrt(nearest); +} + +float lifeAngleDelta(float a, float b) +{ + return atan2(sin(a - b), cos(a - b)); +} + +float lifeSpiralRadius(float u) +{ + return exp(LIFE_B * u); +} + +float lifeProfileGrowthRadius(float u) +{ + float age = clamp(u + LIFE_TURNS * 2.0 * PI, 0.0, LIFE_TURNS * 2.0 * PI); + return LIFE_PROFILE_START_RADIUS * exp(LIFE_PROFILE_B * age); +} + +float lifeProfileTerminalFlare(float u) +{ + return 0.0; +} + +float lifeProfileBaseRadius(float u) +{ + return lifeProfileGrowthRadius(u) + lifeProfileTerminalFlare(u); +} + +float lifeShellThickness(float profileRadius) +{ + return LIFE_WALL * max(pow(profileRadius, 0.35), 0.76); +} + +float lifeApertureHalfSpan(float u) +{ + return LIFE_C_SPAN * 0.5 - LIFE_APERTURE_FLARE * smoothstep(-1.05, 0.25, u); +} + +float lifeArcCenter(float u) +{ + return LIFE_OPEN_CENTER + PI; +} + +float lifeContactHalfSpan(float halfSpan, float u) +{ + float whorlRadius = lifeSpiralRadius(u); + float previousProfile = lifeProfileBaseRadius(u - 2.0 * PI); + float d = (1.0 - exp(-LIFE_B * 2.0 * PI)) * whorlRadius; + float ratio = previousProfile / max(d, 0.0001); + float feasible = step(0.0001, ratio); + float kp = clamp(ratio, 0.0, 1.0); + float minimum = lerp(halfSpan, acos(-sqrt(max(1.0 - kp * kp, 0.0))) + 0.035, feasible); + return lerp(halfSpan, max(halfSpan, minimum), LIFE_CONTACT_SPAN_PULL); +} + +float lifeContactArcRadius(float whorlRadius, float u, float center, float halfSpan) +{ + float k = exp(-LIFE_B * 2.0 * PI); + float d = (1.0 - k) * whorlRadius; + float previousProfile = lifeProfileBaseRadius(u - 2.0 * PI); + float base = lifeProfileBaseRadius(u); + float endpoint = center + halfSpan; + float c = cos(endpoint); + float s = sin(endpoint); + float root = previousProfile * previousProfile - d * d * s * s; + float solved = -d * c + sqrt(max(root, 0.0)); + float feasible = step(0.0, root) * step(0.0, solved); + float contactRadius = lerp(base, max(solved, 0.012), feasible); + return lerp(base, contactRadius, LIFE_CONTACT_PULL); +} + +float lifeArcDistance(float2 q, float radius, float center, float halfSpan, out float v, out float w, out float edge, out float endpointMask) +{ + float lenQ = max(length(q), 0.0001); + v = atan2(q.y, q.x); + w = lenQ / max(radius, 0.0001); + float da = lifeAngleDelta(v, center); + float absDa = abs(da); + + float2 e0 = radius * float2(cos(center - halfSpan), sin(center - halfSpan)); + float2 e1 = radius * float2(cos(center + halfSpan), sin(center + halfSpan)); + float circleDistance = abs(lenQ - radius); + float endpointDistance = min(length(q - e0), length(q - e1)); + + edge = (absDa - halfSpan) * radius; + endpointMask = smoothstep(0.035, -0.010, abs(edge)); + return absDa <= halfSpan ? circleDistance : endpointDistance; +} + +float lifeBranchSolidDistance(float3 p, float t, float n, out float u, out float v, out float w, out float edge, out float endpoint) +{ + u = 2.0 * PI * n + t; + float whorlRadius = lifeSpiralRadius(u); + float r = max(length(p.xy), 0.0001); + float center = lifeArcCenter(u); + float halfSpan = lifeContactHalfSpan(lifeApertureHalfSpan(u), u); + float profileRadius = lifeContactArcRadius(whorlRadius, u, center, halfSpan); + float centerDistance = lifeArcDistance(float2(r - whorlRadius, p.z), profileRadius, center, halfSpan, v, w, edge, endpoint); + + float d = centerDistance - lifeShellThickness(profileRadius); + d = max(d, (-LIFE_TURNS * 2.0 * PI - 0.16) - u); + d = max(d, u - LIFE_TERMINAL_U); + return d; +} + +LifeDomain lifeMakeDomain(float d, float shell, float mat, float u, float v, float w, float edge, float endpoint, float pressure) +{ + LifeDomain domain; + domain.body = d; + domain.shell = shell; + domain.ember = 999.0; + domain.seam = 999.0; + domain.pearl = 999.0; + domain.lip = 999.0; + domain.mat = mat; + domain.u = u; + domain.v = v; + domain.w = w; + domain.edge = edge; + domain.endpoint = endpoint; + domain.pressure = pressure; + return domain; +} + +LifeDomain lifeChoose(LifeDomain a, LifeDomain b) +{ + if (b.body < a.body) + { + return b; + } + + return a; +} + +LifeDomain lifeBranchDomain(float3 p, float t, float n, float pressure) +{ + float u; + float v; + float w; + float edge; + float endpoint; + float shell = lifeBranchSolidDistance(p, t, n, u, v, w, edge, endpoint); + + float prevU; + float prevV; + float prevW; + float prevEdge; + float prevEndpoint; + float previous = lifeBranchSolidDistance(p, t, n - 1.0, prevU, prevV, prevW, prevEdge, prevEndpoint); + float hasPrevious = smoothstep(-LIFE_TURNS * 2.0 * PI + 0.12, -LIFE_TURNS * 2.0 * PI + 0.42, u); + float seamLocality = smoothstep(0.030, 0.003, abs(edge)); + float trimmedShell = shell; + + float innerSide = (1.0 - smoothstep(0.990, 1.015, w)) * (1.0 - endpoint); + float mat = (innerSide > 0.50 && u > -2.65) ? LIFE_MAT_INNER : LIFE_MAT_OUTER; + LifeDomain domain = lifeMakeDomain(trimmedShell, shell, mat, u, v, w, edge, endpoint, pressure); + + float seamGate = smoothstep(-LIFE_TURNS * 2.0 * PI + 0.55, -LIFE_TURNS * 2.0 * PI + 1.20, u); + float seam = max(abs(edge) - 0.0035, shell - 0.006); + seam = lerp(999.0, seam, hasPrevious * seamLocality); + domain.seam = seam; + + float pearlWave = lifeTri(u * 1.72 + 0.040 * sin(v * 1.7)); + float pearlLine = pearlWave * 0.052; + float pearlBand = length(float2(pearlLine, shell)) - 0.009; + float pearlGate = seamGate * (1.0 - endpoint * 0.50) * smoothstep(0.20, 0.92, w); + domain.pearl = lerp(999.0, pearlBand, pearlGate); + + domain.lip = lerp(999.0, length(float2(abs(edge), shell)) - 0.024, endpoint); + + float pearlDetail = domain.pearl; + float lipDetail = domain.lip; + float detail = min(pearlDetail, lipDetail); + domain.body = min(trimmedShell, detail); + if (detail < trimmedShell) + { + domain.mat = LIFE_MAT_PEARL; + } + + return domain; } LifeDomain lifeDomain(float3 local, SdfObject sdfObject) { - float pressure = saturate(sdfObject.state.z + (1.0 - saturate(sdfObject.state.y)) * 0.12); + float pressure = saturate(sdfObject.state.z + (1.0 - saturate(sdfObject.state.y)) * 0.10); float3 p = local; - p.xz = lifeRotate2(p.xz, -0.18); + p *= 1.08; + p.yz = lifeRotate2(p.yz, -0.10); + p.xy = lifeRotate2(p.xy, -0.22); - float surfaceBand; - float shell = lifeSeedShell(p, pressure, surfaceBand); - float aperture = lifeAperture(p, pressure); - float openedShell = max(shell, -aperture); + // Shell grammar lives in xy/z: xy is the logarithmic spiral plane, z is + // the C-profile thickness axis. Map world yz into that domain so the + // right-side view sees the growth spiral instead of a sliced rim. + p = float3(p.y, p.z, p.x); - float turn; - float stepAlong; - float spiralLine = lifeSpiralField(p.xz, turn, stepAlong); - float spiralGate = smoothstep(0.035, 0.22, p.x + 0.44) * (1.0 - smoothstep(0.70, 0.92, length(p.xz))); - float seam = max(spiralLine - lerp(0.008, 0.014, pressure), surfaceBand); - float darkGroove = (1.0 - smoothstep(0.0, 0.018, seam)) * spiralGate; + float r = max(length(p.xy), 0.0001); + float t = atan2(p.y, p.x); + float n = (log(max((r * r + p.z * p.z) / (2.0 * r), 0.0001)) / LIFE_B - t) / (2.0 * PI); + n = clamp(n, -LIFE_TURNS, 0.0); - float beadPeriod = sin(stepAlong * 9.5 + 0.7 * sin(stepAlong * 0.65)); - float beadWindow = smoothstep(0.30, 0.66, p.x + 0.42) * smoothstep(0.82, 0.24, length(p.xz)); - float beadCore = length(float2(spiralLine * 1.15, beadPeriod * 0.028)) - 0.015; - float bead = max(beadCore, surfaceBand - 0.014); - float beadMask = (1.0 - smoothstep(0.0, 0.012, bead)) * beadWindow * spiralGate; + LifeDomain domain = lifeMakeDomain(999.0, 999.0, LIFE_MAT_OUTER, 0.0, 0.0, 0.0, 999.0, 0.0, pressure); + float n0 = floor(n); + float n1 = ceil(n); + domain = lifeChoose(domain, lifeBranchDomain(p, t, n0, pressure)); + domain = lifeChoose(domain, lifeBranchDomain(p, t, n1, pressure)); - float2 ribQ = p.xz + float2(0.055, -0.015); - float ribRadius = max(length(ribQ), 0.045); - float ribAngle = atan2(ribQ.y, ribQ.x); - float ribPhase = ribAngle - 1.85 * log(ribRadius + 0.030); - float ribWave = min(frac(ribPhase * 1.18 + 0.08), 1.0 - frac(ribPhase * 1.18 + 0.08)); - float rib = max(ribWave * ribRadius - 0.014, surfaceBand - 0.020); - float apertureReliefMask = smoothstep(0.12, 0.34, p.x + 0.36); - float ribGate = smoothstep(0.12, 0.24, ribRadius) * (1.0 - smoothstep(0.88, 1.02, ribRadius)) * apertureReliefMask; - float ribLift = (1.0 - smoothstep(0.0, 0.018, rib)) * ribGate * 0.008; + float ember = sdSphere(p - float3(0.0, 0.0, 0.0), 0.060 + 0.004 * sin(timeSeconds * 2.1)); + if (ember < domain.body) + { + LifeDomain emberDomain = lifeMakeDomain(ember, domain.shell, LIFE_MAT_EMBER, domain.u, domain.v, domain.w, domain.edge, domain.endpoint, pressure); + emberDomain.ember = ember; + return emberDomain; + } - float3 emberP = p - float3(-0.260 + pressure * 0.035, -0.050, 0.030); - float emberPulse = 0.012 * sin(timeSeconds * 2.1 + pressure * 1.7); - float ember = sdSphere(emberP, 0.090 + emberPulse); - - float lip = max(abs(aperture) - 0.030, abs(shell) - 0.045); - float lipLift = (1.0 - smoothstep(0.0, 0.024, lip)) * 0.036; - float beadLift = beadMask * 0.034; - float grooveCut = darkGroove * lerp(0.012, 0.026, pressure); - - float crackSeed = sin(stepAlong * 5.7 + sin(p.y * 8.0) * 0.7) * sin((p.z - p.x) * 16.0); - float crack = max(abs(crackSeed) - 0.955, surfaceBand - 0.004); - - LifeDomain domain; - domain.body = min(openedShell - ribLift - lipLift - beadLift + grooveCut, ember); - domain.shell = openedShell; - domain.aperture = aperture; domain.ember = ember; - domain.seam = seam; - domain.bead = bead; - domain.rib = rib; - domain.crack = crack; - domain.lip = lip; - domain.spiral = spiralLine; - domain.spiralStep = stepAlong; - domain.surfaceBand = surfaceBand; - domain.pressure = pressure; return domain; } @@ -157,35 +326,43 @@ SdfSurface sdfSurface(float3 p, int sdfIndex) LifeDomain domain = lifeDomain(local, sdfObject); float heartbeat = saturate(sdfObject.state.y); - float ember = 1.0 - smoothstep(0.000, 0.018, domain.ember); - float lip = (1.0 - ember) * (1.0 - smoothstep(0.000, 0.018, domain.lip)); - float bead = (1.0 - ember) * (1.0 - lip * 0.40) * (1.0 - smoothstep(0.000, 0.011, domain.bead)); - float seam = (1.0 - ember) * (1.0 - smoothstep(0.000, 0.016, domain.seam)); - float rib = (1.0 - ember) * (1.0 - smoothstep(0.000, 0.018, domain.rib)); - float crack = (1.0 - ember) * (1.0 - smoothstep(0.000, 0.006, domain.crack)); - float chamber = (1.0 - ember) * smoothstep(0.070, -0.075, domain.aperture) * smoothstep(0.32, -0.10, local.x + 0.22); + float emberMask = domain.mat == LIFE_MAT_EMBER ? 1.0 : 0.0; + float pearlMask = domain.mat == LIFE_MAT_PEARL ? 1.0 : 0.0; + float seamMask = (1.0 - emberMask) * (1.0 - pearlMask) * (1.0 - smoothstep(0.000, 0.010, domain.seam)); + float innerMask = domain.mat == LIFE_MAT_INNER ? 1.0 : 0.0; - float nacre = 0.5 + 0.5 * sin(domain.spiralStep * 1.7 + local.y * 5.0 + timeSeconds * 0.08); - float3 teal = lerp(float3(0.018, 0.32, 0.31), float3(0.042, 0.62, 0.57), nacre); - float3 gold = lerp(float3(0.88, 0.42, 0.10), float3(1.0, 0.78, 0.25), nacre); - float3 pearl = float3(0.96, 0.88, 0.68); - float3 scar = float3(0.035, 0.020, 0.015); - float3 emberColor = float3(1.0, 0.38, 0.055); + float nacre = 0.5 + 0.5 * sin(domain.u * 0.78 + domain.v * 1.35 + timeSeconds * 0.06); + float3 fractureP = local * 3.75; + float warp = sin(dot(fractureP, float3(1.7, -0.9, 1.2))) * 0.28 + + sin(dot(fractureP, float3(-0.6, 1.9, 1.1))) * 0.18; + float fractureEdgeA = lifeVoronoiEdge(fractureP.xy + warp); + float fractureEdgeB = lifeVoronoiEdge(fractureP.yz * 1.13 - warp * 0.7); + float fractureEdgeC = lifeVoronoiEdge(fractureP.zx * 0.91 + warp * 0.5); + float fractureEdge = min(fractureEdgeA, min(fractureEdgeB, fractureEdgeC)); + float fractureMask = (1.0 - emberMask) * smoothstep(0.080, 0.010, fractureEdge); + float3 teal = lerp(float3(0.006, 0.185, 0.250), float3(0.030, 0.470, 0.610), nacre); + float3 innerPearl = lerp(float3(0.840, 0.805, 0.700), float3(0.985, 0.940, 0.800), nacre); + float3 gold = lerp(float3(0.82, 0.420, 0.080), float3(1.0, 0.735, 0.205), nacre); + float3 pearlColor = float3(0.965, 0.905, 0.735); + float3 seamColor = float3(0.075, 0.050, 0.026); + float3 emberColor = float3(1.0, 0.390, 0.050); SdfSurface surface; - surface.baseColor = lerp(teal, gold, chamber * 0.94); - surface.baseColor = lerp(surface.baseColor, pearl, saturate(lip * 0.72 + bead * 1.35 + rib * 0.68)); - float scarMask = saturate(seam * (1.0 - bead) * (1.0 - rib) * (0.06 + domain.pressure * 0.14) + crack * 0.24); - surface.baseColor = lerp(surface.baseColor, scar, scarMask); - surface.baseColor = lerp(surface.baseColor, emberColor, ember); - surface.metallic = 0.06 + 0.22 * saturate(lip + bead); - surface.roughness = lerp(0.22, 0.11, saturate(lip + bead + ember * 0.5)); - surface.emission = primitiveEmissionRadiance(sdfFieldId(sdfIndex)) * 0.020 - + teal * 0.070 - + gold * chamber * (0.64 + heartbeat * 0.34) - + pearl * saturate(bead + rib * 0.55) * 0.28 - + emberColor * ember * (2.4 + heartbeat * 1.1 + domain.pressure * 0.8) - + gold * crack * 0.10; + surface.baseColor = lerp(teal, innerPearl, innerMask); + surface.baseColor = lerp(surface.baseColor, gold, fractureMask * lerp(0.42, 0.76, innerMask)); + surface.baseColor = lerp(surface.baseColor, pearlColor, pearlMask); + surface.baseColor = lerp(surface.baseColor, seamColor, seamMask); + surface.baseColor = lerp(surface.baseColor, emberColor, emberMask); + surface.metallic = lerp(0.04, 0.10, saturate(fractureMask + seamMask * 0.35)); + surface.metallic = lerp(surface.metallic, 0.03, pearlMask); + surface.roughness = lerp(0.28, 0.16, saturate(innerMask + pearlMask + seamMask * 0.6)); + surface.roughness = lerp(surface.roughness, 0.08, emberMask); + surface.emission = primitiveEmissionRadiance(sdfFieldId(sdfIndex)) * 0.012 + + gold * innerMask * 0.050 + + gold * fractureMask * 0.095 + + pearlColor * pearlMask * 0.040 + + gold * seamMask * 0.090 + + emberColor * emberMask * (3.2 + heartbeat * 1.1 + domain.pressure * 0.8); return surface; } @@ -196,13 +373,12 @@ float3 shadeSdf(float2 uv, float travel, float3 p, float3 normal, int sdfIndex, float3 local = (p - sdfObject.centerRadius.xyz) / radius; LifeDomain domain = lifeDomain(local, sdfObject); float3 shaded = shadeSdfPbr(p, normal, surface); - float3 viewDirection = normalize(cameraPosition - p); - float edge = pow(1.0 - saturate(dot(normal, viewDirection)), 3.0); - float apertureGlow = smoothstep(0.10, -0.08, domain.aperture) * smoothstep(0.20, -0.08, local.x + 0.18); + float fresnel = pow(1.0 - saturate(dot(normal, viewDirection)), 3.2); + float innerGlow = domain.mat == LIFE_MAT_INNER ? 1.0 : 0.0; return shaded - + float3(0.08, 0.48, 0.44) * edge * 0.10 - + float3(1.0, 0.44, 0.06) * apertureGlow * 0.28; + + float3(0.020, 0.360, 0.330) * fresnel * 0.10 + + float3(1.0, 0.470, 0.080) * innerGlow * 0.050; } #define SDF_TRACE_STEP_SCALE 0.12 diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 5973b92..70a81ff 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -101,3 +101,5 @@ {"timestamp":"2026-05-14T05:55:00+01:00","topic":"life-nautilus-source-port","lesson":"For Life, the durable model is the Nautilus.glsl logarithmic shell solve: find the nearest exponential spiral boundary in cylindrical space, use its u/v/w section coordinates for wall thickness, septa, ribs, aperture/cut, pearls, cracks, and materials. A loose phase field plus welded opening is not a coherent shell."} {"timestamp":"2026-05-14T13:38:00+01:00","topic":"life-spec-over-reference-port","lesson":"Do not recreate a reference shader when the task is to learn its spatial-domain mapping. For Life, Nautilus.glsl is a coordinate lesson; the spec authority is a protective revolved seed/cardioid shell with a visible ember, logarithmic seam, and memory beads sharing one spiral domain."} {"timestamp":"2026-05-14T14:38:00+01:00","topic":"life-shell-authority","lesson":"Life's shell silhouette must be a filled protective mass; letting the logarithmic spiral own body distance creates hollow coils, fins, or mechanical mouths. Use the spiral domain for raised ribs, beads, seam, and scar material only. Check front plus oblique previews against the concept before accepting a pass."} +{"timestamp":"2026-05-14T15:32:00+01:00","topic":"life-balanced-whorl-domain","lesson":"Life needs both sides of the nautilus grammar: a log-spiral whorl solve must physically shape the shell, but it cannot be the only body authority or the form collapses into a hollow C-shell. Union the whorl with a smaller same-domain backing mass, then derive aperture lip, chamber gold, ember reveal, raised ribs, and pearl beads from the shared spiral/aperture fields.","files":["src/Aquarium.Epiphany/Shaders/D3D12LifeAgent.hlsl","state/life-agent-sdf-notes.md","state/evidence.jsonl"],"source":"user rejected the egg lineage and required repeated restart until the spiral shell manifests as geometry"} +{"timestamp":"2026-05-14T16:31:00+01:00","topic":"life-curve-first-build","lesson":"When rebuilding Life, do not start by tuning the full organ. First make the log-spiral domain read as a naked curve: ember at the core, roughly two revolutions, and the wide mouth-side lip termination. Only after that curve reads should shell inflation, aperture carving, ember reveal, ribs, and pearl beads be layered back on the same solved domain.","files":["src/Aquarium.Epiphany/Shaders/D3D12LifeAgent.hlsl","state/life-agent-sdf-notes.md","state/evidence.jsonl"],"source":"user corrected the iteration process: build the log spiral one step at a time instead of doing everything at once"} diff --git a/state/life-agent-sdf-notes.md b/state/life-agent-sdf-notes.md index b0176b1..506a903 100644 --- a/state/life-agent-sdf-notes.md +++ b/state/life-agent-sdf-notes.md @@ -11,14 +11,39 @@ Working model: - The source-backed model comes from `artifacts/Nautilus.glsl`: solve the nearest logarithmic spiral boundary in cylindrical shell space, then derive wall thickness, septa, aperture/cut exposure, ribs, stripes, lip, pearls, cracks, and chamber light from that solved domain. - Do not replace the solve with a loose `sin(phase)` whorl. That was the false shortcut. - Do not recreate the Shadertoy Nautilus. Its durable lesson is spatial-domain mapping, not the Life silhouette. +- For Life's C mantle, do not cut a closed Nautilus section circle with an angular wedge. A wedge intersection creates planar cut walls and umbrella fins. The C profile must be a distance to an arc in the solved section circle: inside the kept angular span, distance to the circle; outside it, distance to the nearest arc endpoint/contact region. +- Do not carry over the Nautilus aperture/opening stabilizer as an independent torus-like fallback in the Life C-arc topology. In the source shader it patches a closed-shell discontinuity; in Life it becomes a giant false shell that overwhelms the actual spiral branch solve. +- Life's C profile radius should not default to the full Nautilus section-circle radius. To make the mantle start near the ember equator and build on itself, derive the local C arc radius from previous-turn contact: with current whorl center radius R, previous-turn ratio k=exp(-B*TAU), and endpoint angle halfSpan, solve R + a*cos(halfSpan) = k*R + k*a for profile radius a. Keep this as domain math, not a bridge pasted on after the fact. +- Correction to the Life C-contact math: exact endpoint contact with the previous turn's section circle is possible only if cos(endpointAngle)^2 >= 1-k^2, where k=exp(-B*TAU). If the kept C span is too narrow for the growth rate, gaps are mathematically unavoidable. The shader playground should surface this by deriving/clamping the feasible half-span and solving the real section-circle contact equation, not by adding a fake bridge. +- Further correction: the Life mantle section does not have to grow at the same exponential rate as the spiral centerline. Keep separate exponents for centerline growth (`B`) and C-profile growth (`PROFILE_B`). The previous-turn profile ratio is `kp=exp(-PROFILE_B*TAU)`, which belongs in the endpoint contact solve; assuming `kp==k` overconstrains the form and can force persistent gaps. +- Bug in the first separate-profile attempt: adding `PROFILE_B` to the contact equation is meaningless unless the actual C profile radius field uses it. Define a profile radius field such as `PROFILE_END_RADIUS * exp(PROFILE_B*u)`, solve current endpoint contact against the previous turn's actual profile radius, and consider adjacent branch candidates beyond floor/ceil because the nearest closed-circle branch may not be the nearest C-arc branch. +- Better Life profile parameterization: do not define profile radius as `PROFILE_END_RADIUS * exp(PROFILE_B*u)`, because setting the terminal amplitude to zero makes the whole field zero and `PROFILE_B` inert. Use a seed/ember radius plus age-based growth, e.g. `PROFILE_START_RADIUS * exp(PROFILE_B * (u + TURNS*TAU))`, with terminal flare as an additive option. Contact solve should fall back to the base profile when exact contact is infeasible rather than widening into a pillbug. +- Contact must be solved surface-to-surface, not centerline-to-centerline. If the current C endpoint is placed on the previous turn's profile centerline, the wall radii interpenetrate and any seam placed there will expose the lie. Solve endpoint distance against `previousProfile + previousWall + currentWall`, refine current wall thickness once, and keep the endpoint geometry in the same angular frame as the solve. Terminal flare should be released from contact pull so `PROFILE_END_RADIUS` can actually widen the mouth instead of being cancelled by the previous-turn constraint. +- Further Life C-contact correction: never force contact by widening the C span toward a nearly closed circle. That only turns the section into an overlapping pillbug. The previous turn in the contact equation must be the actual solved previous profile radius, not `profileBaseRadius(u - TAU)`. Evaluate the finite same-phase growth lineage and solve each turn against the solved turn before it. +- Missing Life C-contact degree of freedom: a fixed C arc centered on the spiral whorl cannot generally touch the previous turn for the desired half-open span. `PROFILE_B` cannot fix an impossible triangle; below the spiral growth it stalls, above it grows but gaps. The coherent grammar is radius for fullness plus a solved section-space profile-center offset for contact. Solve `|vec2(D + oCur - oPrev,0) + radius*endpoint| = previousRadius + previousWall + currentWall`; do not fake contact by changing span. +- Life C-profile feasibility: once contact is solved by x-offset, radius is constrained by the endpoint's perpendicular component. If `radius * abs(sin(endpointAngle)) > previousRadius + previousWall + currentWall`, no x-offset can create contact. Clamp or derive profile radius inside that envelope before solving offset; otherwise high `PROFILE_B` explodes and low settings appear inert. Do not use a terminal release blend, because it breaks the seam continuity the end radius is supposed to preserve. +- Life C-profile recurrence must not anchor at the first visible loop. A variable-generation recurrence (`floor((u + TURNS*TAU)/TAU)`) creates a branch cut every revolution: the innermost loop grows naturally until it hits the clamped origin, then each later loop inherits the same discontinuity. Use fixed prehistory for every `u` and walk forward the same number of turns so there is no special visible origin. +- Fixed prehistory is also wrong for Life C-profile contact: it removes the branch cut by converging every visible turn toward the same mature solved profile, producing a tire/pastry. The better model is closed-form self-similarity: express profile fullness relative to spiral radius and solve offset directly with `k=exp(-B*TAU)`, e.g. `|vec2((1-k)*R*(1+beta),0)+radius*endpoint| = previousRadius + previousWall + currentWall`, then `offset=beta*R`. No recurrence, no clamped origin, no inherited mature profile. +- Retreat from the overfit contact solves: the readable fixed-center C profile was the right visual base even when it intersected. The coherent non-overlap rule is accretion ownership: newer shell may meet older shell but may not occupy its volume. Restore the readable fixed-center contact radius and trim each branch by the previous turn's signed volume (`current minus previous`) so the seam is an actual boolean boundary instead of another fragile radius/offset compensator. +- The readable overlapping model specifically included contact pull: widen the C span to the minimum endpoint-contact-feasible span, then pull the fixed-center profile radius toward the previous-turn contact solve. If that is omitted, parameter changes can produce a non-overlapping gap model instead of the useful raw overlap that the accretion trim is supposed to cut. - The spec authority is a protective revolved seed/cardioid shell around a visible ember. The Nautilus spiral math should only coordinate seam, bead trail, aperture logic, and surface breathing. - Lip, pearls, ribs, cracks, and chamber light are fields on the same shell/spiral coordinates, not separate child objects. -- Current failure as of `20260514-141015`: the render is less egg-shaped, but the center reads as a mechanical mouth because the spiral/seam field owns too much material authority and the aperture is a bite. The next model must make the shell mass first, then use spiral coordinates for raised pale ribs and bead trail only. - Concept target: front view should show a heavy teal shell mass with a round outer whorl, a gold inner aperture bowl on the left, a visible ember near the inner spiral, pale raised ribs arcing from the center to the outer shell, and memory beads along the spiral lip. Oblique views may reveal thickness, but must not expose detached ornaments or a hollow ring. -- Accepted direction as of `20260514-143806`: filled directional shell mass owns the silhouette, aperture carves a smooth golden bowl, ember remains visible, log-spiral relief produces pale raised ribs and rounder bead samples, and scar/groove material is subordinate. The spiral organizes the shell; it is not the shell body. +- Working checkpoint as of `20260514-163152`: build Life in ordered layers. First solve the log spiral curve until it reads alone: ember at the core, about two turns, and a wide lip termination on the mouth side. Then inflate that curve into shell mass, carve the aperture from the same mouth field, reveal the ember, and only then add ribs/pearls as masks on the solved spiral domain. +- Cut line: if a future pass tries to tune ornament before the curve reads, stop. If the shell becomes an egg with spiral decals, delete it. If the spiral alone becomes a hollow C-shell, add support from the same domain instead of welding on separate organs. +- Aquarium placement correction: the Life spiral plane belongs in world `YZ`, with shell profile thickness along world `X`. In the preview set, `life-right` is the lip-side `Y+` camera, so use `life-left` as the reference comparison view when matching the concept art's visible spiral face. Do not fake the mouth by trimming the shell against the previous turn's volume; that cuts along the spiral plane, which is not where the biological aperture lives. +- Life material/detail correction: pearl ribs must be raised circular-section distance fields on the shell surface, not painted color masks. Inner shell material should be nacre/pearl with warped Voronoi gold fractures; the same fracture field can tint the teal enamel outside. Failed hypothesis: closing the C span near the terminal turn creates a false lip-side blade and should not be kept. +- Life containment correction: removing the terminal `u` bound before a correct C-span taper exists lets the final branch run into giant nacre fins. Keep the terminal bound as a temporary containment invariant until the mouth profile is solved by the C-domain itself. +- Rollback checkpoint: after the 2026-05-15 failed mouth/profile detour, the source shader was restored to the live-reload shader from `artifacts/dev-reload/slots/20260515-145843-490c3cac/Render/Shaders/D3D12LifeAgent.hlsl`. Treat that as the current coherent baseline before attempting more Life mouth work. -Latest preview used for judgment: +Latest active checkpoint: -- `artifacts/agent-previews/Life/20260514-143806/life-front.png` -- `artifacts/agent-previews/Life/20260514-143806/life-mouth-oblique.png` -- `artifacts/agent-previews/Life/20260514-143806/life-three-quarter.png` +- `artifacts/agent-previews/Life/20260514-193811/life-front.png` +- `artifacts/agent-previews/Life/20260514-193811/life-mouth-oblique.png` +- `artifacts/agent-previews/Life/20260514-193811/life-three-quarter.png` + +Current judgment: + +- The active source is the last accepted pre-detour C-sweep shader, not the later scaled-inverse/profile-rewrite experiments. +- Do not reintroduce the rounded terminal-overrun cap that replaced `d = max(d, u - LIFE_TERMINAL_U)`. It was the only diff between the restored source and the actual last known pre-nightmare build, and it did not earn its keep. +- The current form is not final. The next productive move is a narrow, reference-checked mouth/lip pass from this baseline, with the actual `Life_C_Sweep_ShaderToy.glsl` playground in sight.