diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12BodyCommon.hlsli b/src/Aquarium.Engine/Render/Shaders/D3D12BodyCommon.hlsli index d87d0cc..5b0d940 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12BodyCommon.hlsli +++ b/src/Aquarium.Engine/Render/Shaders/D3D12BodyCommon.hlsli @@ -180,6 +180,50 @@ float3 bodyLightIrradianceAt(float3 p, float3 normal) return irradiance; } +float3 bodyLightSpecularRadiance(float3 p, float3 normal, float roughness, float3 f0, float intensity) +{ + static const float MinimumRoughness = 0.045; + + float3 viewDirection = normalize(cameraPosition - p); + float ndv = saturate(dot(normal, viewDirection)); + float safeRoughness = max(roughness, MinimumRoughness); + float alpha = safeRoughness * safeRoughness; + float alpha2 = alpha * alpha; + float k = (safeRoughness + 1.0); + k = (k * k) * 0.125; + float geometryV = ndv / max(ndv * (1.0 - k) + k, 0.00001); + float3 result = 0.0; + + [loop] + for (int i = 0; i < BODY_LIGHT_COUNT; i++) + { + BodyLight light = bodyLights[i]; + float3 radiance = light.radianceFieldId.rgb; + if (dot(radiance, radiance) <= 0.000001) + { + continue; + } + + float3 toLight = light.centerRadius.xyz - p; + float distanceSquared = max(dot(toLight, toLight), 0.01); + float3 lightDirection = toLight * rsqrt(distanceSquared); + float radius = max(light.centerRadius.w, 0.001); + float3 irradiance = radiance * saturate((radius * radius) / distanceSquared) * intensity; + float3 halfVector = normalize(lightDirection + viewDirection); + float ndl = saturate(dot(normal, lightDirection)); + float ndh = saturate(dot(normal, halfVector)); + float vdh = saturate(dot(viewDirection, halfVector)); + float denominator = ndh * ndh * (alpha2 - 1.0) + 1.0; + float distribution = alpha2 / max(PI * denominator * denominator, 0.00001); + float geometryL = ndl / max(ndl * (1.0 - k) + k, 0.00001); + float3 fresnel = f0 + (1.0 - f0) * pow(1.0 - vdh, 5.0); + float3 specular = (distribution * geometryL * geometryV) * fresnel / max(4.0 * ndl * ndv, 0.00001); + result += specular * irradiance * ndl; + } + + return result; +} + float3 fresnelSchlickRoughness(float cosine, float3 f0, float roughness) { return f0 + (max(1.0 - roughness, f0) - f0) * pow(1.0 - cosine, 5.0); diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12CursorBody.hlsl b/src/Aquarium.Engine/Render/Shaders/D3D12CursorBody.hlsl index 7f097f5..2e7a3c7 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12CursorBody.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/D3D12CursorBody.hlsl @@ -5,6 +5,80 @@ static const int BODY_INDEX = 8; static const float CURSOR_RADIUS = 0.56; +float2 hibiscusPetalCenter(float u) +{ + float radial = 0.92 * u * u * (1.0 - 0.10 * u); + float height = -0.10 + 0.82 * u; + return float2(radial, height); +} + +float sdHibiscusPetalRibbon(float3 q) +{ + float u = saturate((q.z + 0.10) / 0.82); + float2 center = hibiscusPetalCenter(u); + float widthGrowth = smoothstep(0.08, 1.0, u); + float width = lerp(0.030, 0.42, widthGrowth); + float thickness = lerp(0.010, 0.046, widthGrowth); + float fold = 0.055 * q.y * q.y / max(width * width, 0.001); + float radialDistance = abs(q.x - center.x - fold) - thickness; + float verticalDistance = max(-0.10 - q.z, q.z - 0.72); + float sideDistance = abs(q.y) - width; + return max(max(radialDistance, verticalDistance), sideDistance); +} + +float sdHibiscusCursorPetal(float3 local, float angle, float timeSeconds) +{ + float2 radial = float2(cos(angle), sin(angle)); + float2 tangent = float2(-radial.y, radial.x); + float sway = 0.030 * sin(timeSeconds * 0.95 + angle * 1.7); + float3 center = float3(radial * 0.20, 0.07 + sway); + float3 p = local - center; + float3 q = float3(dot(p.xy, radial), dot(p.xy, tangent), p.z); + return sdHibiscusPetalRibbon(q); +} + +float sdHibiscusSepal(float3 local, float angle) +{ + float2 radial = float2(cos(angle), sin(angle)); + float3 a = float3(0.0, 0.0, -0.46); + float3 b = float3(radial * 0.26, -0.22); + return sdTaperedCapsuleSegment(local, a, b, 0.058, 0.022); +} + +float sdHibiscusStamen(float3 local) +{ + float column = sdQuadraticTube(local, float3(0.0, 0.0, 0.02), float3(-0.12, 0.08, 0.43), float3(0.13, 0.04, 0.86), 0.048, 0.032); + float bead0 = sdSphere(local - float3(0.14, 0.04, 0.92), 0.064); + float bead1 = sdSphere(local - float3(0.18, 0.12, 0.72), 0.046); + float bead2 = sdSphere(local - float3(-0.12, 0.04, 0.62), 0.044); + float beads = min(bead0, min(bead1, bead2)); + return min(column, beads); +} + +float sdHibiscusCursor(float3 local, float timeSeconds) +{ + float sway = 0.10 * sin(timeSeconds * 0.85); + float petal0 = sdHibiscusCursorPetal(local, 1.45 + sway, timeSeconds); + float petal1 = sdHibiscusCursorPetal(local, 2.62 + sway * 0.7, timeSeconds); + float petal2 = sdHibiscusCursorPetal(local, 3.88 + sway * 0.5, timeSeconds); + float petal3 = sdHibiscusCursorPetal(local, 5.12 + sway * 0.4, timeSeconds); + float petal4 = sdHibiscusCursorPetal(local, 0.22 + sway * 0.6, timeSeconds); + float petals = min(min(petal0, petal1), min(min(petal2, petal3), petal4)); + + float throatSphere = sdSphere(local - float3(0.0, 0.0, -0.05), 0.24); + float throatTop = local.z - 0.07; + float throat = max(throatSphere, throatTop); + float stamen = sdHibiscusStamen(local); + + float calyxCore = sdQuadraticTube(local, float3(0.0, 0.0, -1.0), float3(0.06, -0.04, -0.62), float3(0.0, 0.0, -0.18), 0.014, 0.120); + float sepals = min(sdHibiscusSepal(local, 1.57), min(sdHibiscusSepal(local, 3.66), sdHibiscusSepal(local, 5.75))); + float calyx = smoothUnion(calyxCore, sepals, 0.035); + + float blossom = smoothUnion(petals, throat, 0.10); + blossom = smoothUnion(blossom, stamen, 0.065); + return smoothUnion(blossom, calyx, 0.120); +} + float cursorHibiscusSdf(float3 p) { AgentVisual cursor = agentVisuals[CURSOR_OBJECT_INDEX]; @@ -24,52 +98,6 @@ BodySurface bodySurface(float3 p, int agentIndex) return surface; } -float3 cursorSpecularBodyLightRadiance(float3 p, float3 normal) -{ - static const float MinimumRoughness = 0.045; - static const float CursorRoughness = 0.22; - - float3 viewDirection = normalize(cameraPosition - p); - float ndv = saturate(dot(normal, viewDirection)); - float roughness = max(CursorRoughness, MinimumRoughness); - float alpha = roughness * roughness; - float alpha2 = alpha * alpha; - float k = (roughness + 1.0); - k = (k * k) * 0.125; - float geometryV = ndv / max(ndv * (1.0 - k) + k, 0.00001); - float3 f0 = float3(1.0, 0.38, 0.72); - float3 result = 0.0; - [loop] - for (int i = 0; i < BODY_LIGHT_COUNT; i++) - { - BodyLight light = bodyLights[i]; - float3 radiance = light.radianceFieldId.rgb; - if (dot(radiance, radiance) <= 0.000001) - { - continue; - } - - float3 toLight = light.centerRadius.xyz - p; - float distanceSquared = max(dot(toLight, toLight), 0.01); - float3 lightDirection = toLight * rsqrt(distanceSquared); - float radius = max(light.centerRadius.w, 0.001); - float3 irradiance = radiance * saturate((radius * radius) / distanceSquared) * 7.0; - float3 halfVector = normalize(lightDirection + viewDirection); - float ndl = saturate(dot(normal, lightDirection)); - float ndh = saturate(dot(normal, halfVector)); - float vdh = saturate(dot(viewDirection, halfVector)); - float denominator = ndh * ndh * (alpha2 - 1.0) + 1.0; - float distribution = alpha2 / max(PI * denominator * denominator, 0.00001); - float geometryL = ndl / max(ndl * (1.0 - k) + k, 0.00001); - float geometry = geometryL * geometryV; - float3 fresnel = f0 + (1.0 - f0) * pow(1.0 - vdh, 5.0); - float3 specular = (distribution * geometry) * fresnel / max(4.0 * ndl * ndv, 0.00001); - result += specular * irradiance * ndl; - } - - return result; -} - float3 cursorEmissionRadiance(float3 p, float3 normal) { AgentVisual cursor = agentVisuals[CURSOR_OBJECT_INDEX]; @@ -94,7 +122,7 @@ float3 shadeBody(float2 uv, float travel, float3 p, float3 normal, int agentInde static const float CursorRoughness = 0.22; float3 cursorF0 = float3(1.0, 0.38, 0.72); return cursorEmissionRadiance(p, normal) - + cursorSpecularBodyLightRadiance(p, normal) + + bodyLightSpecularRadiance(p, normal, CursorRoughness, cursorF0, 7.0) + studioPmremSpecularRadiance(p, normal, CursorRoughness, cursorF0); } diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12SdfMath.hlsli b/src/Aquarium.Engine/Render/Shaders/D3D12SdfMath.hlsli index c9f1f10..98fe222 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12SdfMath.hlsli +++ b/src/Aquarium.Engine/Render/Shaders/D3D12SdfMath.hlsli @@ -110,78 +110,4 @@ float sdTeardropRevolution(float3 local, float contactZ, float tipZ, float radiu return max(radialDistance, max(topDistance, bottomDistance)); } -float2 hibiscusPetalCenter(float u) -{ - float radial = 0.92 * u * u * (1.0 - 0.10 * u); - float height = -0.10 + 0.82 * u; - return float2(radial, height); -} - -float sdHibiscusPetalRibbon(float3 q, float phase) -{ - float u = saturate((q.z + 0.10) / 0.82); - float2 center = hibiscusPetalCenter(u); - float widthGrowth = smoothstep(0.08, 1.0, u); - float width = lerp(0.030, 0.42, widthGrowth); - float thickness = lerp(0.010, 0.046, widthGrowth); - float fold = 0.055 * q.y * q.y / max(width * width, 0.001); - float radialDistance = abs(q.x - center.x - fold) - thickness; - float verticalDistance = max(-0.10 - q.z, q.z - 0.72); - float sideDistance = abs(q.y) - width; - return max(max(radialDistance, verticalDistance), sideDistance); -} - -float sdHibiscusCursorPetal(float3 local, float angle, float timeSeconds) -{ - float2 radial = float2(cos(angle), sin(angle)); - float2 tangent = float2(-radial.y, radial.x); - float phase = timeSeconds * 0.95 + angle * 1.7; - float3 center = float3(radial * 0.20, 0.07 + 0.030 * sin(phase)); - float3 p = local - center; - float3 q = float3(dot(p.xy, radial), dot(p.xy, tangent), p.z); - return sdHibiscusPetalRibbon(q, phase); -} - -float sdHibiscusSepal(float3 local, float angle) -{ - float2 radial = float2(cos(angle), sin(angle)); - float3 a = float3(0.0, 0.0, -0.46); - float3 b = float3(radial * 0.26, -0.22); - return sdTaperedCapsuleSegment(local, a, b, 0.058, 0.022); -} - -float sdHibiscusStamen(float3 local) -{ - float column = sdQuadraticTube(local, float3(0.0, 0.0, 0.02), float3(-0.12, 0.08, 0.43), float3(0.13, 0.04, 0.86), 0.048, 0.032); - float bead0 = sdSphere(local - float3(0.14, 0.04, 0.92), 0.064); - float bead1 = sdSphere(local - float3(0.18, 0.12, 0.72), 0.046); - float bead2 = sdSphere(local - float3(-0.12, 0.04, 0.62), 0.044); - float beads = min(bead0, min(bead1, bead2)); - return min(column, beads); -} - -float sdHibiscusCursor(float3 local, float timeSeconds) -{ - float sway = 0.10 * sin(timeSeconds * 0.85); - float petal0 = sdHibiscusCursorPetal(local, 1.45 + sway, timeSeconds); - float petal1 = sdHibiscusCursorPetal(local, 2.62 + sway * 0.7, timeSeconds); - float petal2 = sdHibiscusCursorPetal(local, 3.88 + sway * 0.5, timeSeconds); - float petal3 = sdHibiscusCursorPetal(local, 5.12 + sway * 0.4, timeSeconds); - float petal4 = sdHibiscusCursorPetal(local, 0.22 + sway * 0.6, timeSeconds); - float petals = min(min(petal0, petal1), min(min(petal2, petal3), petal4)); - - float throatSphere = sdSphere(local - float3(0.0, 0.0, -0.05), 0.24); - float throatTop = local.z - 0.07; - float throat = max(throatSphere, throatTop); - float stamen = sdHibiscusStamen(local); - - float calyxCore = sdQuadraticTube(local, float3(0.0, 0.0, -1.0), float3(0.06, -0.04, -0.62), float3(0.0, 0.0, -0.18), 0.014, 0.120); - float sepals = min(sdHibiscusSepal(local, 1.57), min(sdHibiscusSepal(local, 3.66), sdHibiscusSepal(local, 5.75))); - float calyx = smoothUnion(calyxCore, sepals, 0.035); - - float blossom = smoothUnion(petals, throat, 0.10); - blossom = smoothUnion(blossom, stamen, 0.065); - return smoothUnion(blossom, calyx, 0.120); -} - #endif diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 20a71e9..d37459b 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -42,3 +42,4 @@ {"timestamp":"2026-05-12T00:12:00+01:00","topic":"cursor-petal-single-formula","lesson":"The hibiscus cursor petal should not be assembled from piecewise vertical panels and horizontal blades. Model each petal from one longitudinal coordinate: radial displacement grows quadratically so the root starts vertical, height follows a smooth cubic center curve, width and thickness grow from thin root to broad distal blade, and decorative ruffles stay out until the core SDF is stable and cheap.","files":["src/Aquarium.Engine/Render/Shaders/D3D12SdfMath.hlsli","state/memory.json"],"source":"user visual/math review"} {"timestamp":"2026-05-12T00:17:00+01:00","topic":"cursor-hibiscus-reset","lesson":"When the hibiscus cursor starts turning into SDF Jenga, reset the function around anatomical parameters instead of stapling on fixes. The current reset keeps five petals as one cheap graph-style ribbon formula each: u comes from height, radial displacement is quadratic so roots start vertical, width and thickness grow with u, and decorative trig/filament swarms are cut until the core form is stable and fast.","files":["src/Aquarium.Engine/Render/Shaders/D3D12SdfMath.hlsli","state/memory.json"],"source":"user architecture correction"} {"timestamp":"2026-05-12T00:26:00+01:00","topic":"agent-sdf-form-discipline","lesson":"Carry the cursor hibiscus lesson into agent bodies: start every role SDF from a coherent anatomical/form model with a small set of parameters that explain the silhouette across views. Prefer one governing coordinate, profile, width, thickness, symmetry, and material-region model over stitched primitives. Add ornament only after the core form is readable, fast, and stable; fine veins, glitter, filaments, and state pulses should begin as shading or LOD-gated overlays, not traced geometry.","files":["state/memory.json","state/map.yaml"],"source":"cursor hibiscus iteration review"} +{"timestamp":"2026-05-12T00:34:00+01:00","topic":"shader-include-ownership","lesson":"Keep shader include ownership strict before role bodies multiply. D3D12SdfMath.hlsli should hold reusable SDF primitives and generic form helpers, not cursor-specific hibiscus anatomy. Body-specific SDF structure belongs in the owning body shader. Shared lighting equations belong in D3D12BodyCommon.hlsli as material-parameterized helpers so cursor, agents, and future bodies do not duplicate GGX/body-light loops.","files":["src/Aquarium.Engine/Render/Shaders/D3D12BodyCommon.hlsli","src/Aquarium.Engine/Render/Shaders/D3D12CursorBody.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12SdfMath.hlsli","state/memory.json"],"source":"user architecture correction"} diff --git a/state/memory.json b/state/memory.json index 7a55ea9..a7f3b84 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 fullscreen scene pass owns background and Grid only. Self, Face, Imagination, Eyes, Body, Hands, Soul, Life, and cursor each render through their own shader file and proxy pipeline using AgentVisualGpu, conservative screen rectangles from center plus bound radius, and travel-derived depth writes for Grid/body occlusion. Shared body proxy mechanics may live in includes; body identity SDF and material code should not collapse back into a single body shader.", "Reusable SDF primitives and preserved formulas belong in D3D12SdfMath.hlsli. Current role character organs belong in D3D12AgentCharacters.hlsli. D3D12Renderer expands local shader includes before D3DCompile because the Vortice convenience path does not provide a working include handler here.", + "Shader include ownership should stay boring and strict: D3D12SdfMath.hlsli contains reusable SDF primitives and generic form helpers only; body-specific anatomy such as the cursor hibiscus lives in that body's shader; shared lighting equations live in D3D12BodyCommon.hlsli and take material parameters rather than being duplicated per body.", "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.",