diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12BodyProxy.hlsli b/src/Aquarium.Engine/Render/Shaders/D3D12BodyProxy.hlsli index 347981f..79fd790 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12BodyProxy.hlsli +++ b/src/Aquarium.Engine/Render/Shaders/D3D12BodyProxy.hlsli @@ -3,13 +3,17 @@ #endif #ifndef BODY_TRACE_STEP_SCALE -#define BODY_TRACE_STEP_SCALE 0.055 +#define BODY_TRACE_STEP_SCALE 0.20 #endif #ifndef BODY_TRACE_MIN_STEP #define BODY_TRACE_MIN_STEP 0.0009 #endif +#ifndef BODY_TRACE_MAX_STEP_RADIUS_SCALE +#define BODY_TRACE_MAX_STEP_RADIUS_SCALE 0.012 +#endif + float3 bodyNormal(float3 p, int agentIndex) { float epsilon = 0.006; @@ -19,6 +23,32 @@ float3 bodyNormal(float3 p, int agentIndex) return normalize(float3(dx, dy, dz)); } +bool refineBodyHit(float3 origin, float3 direction, int agentIndex, float lowTravel, float highTravel, out float travel, out float3 normal, out BodySurface surface) +{ + BodySurface highSurface = bodySurface(origin + direction * highTravel, agentIndex); + + [unroll] + for (int i = 0; i < 8; i++) + { + float midTravel = (lowTravel + highTravel) * 0.5; + BodySurface midSurface = bodySurface(origin + direction * midTravel, agentIndex); + if (midSurface.distanceValue <= 0.0) + { + highTravel = midTravel; + highSurface = midSurface; + } + else + { + lowTravel = midTravel; + } + } + + travel = highTravel; + surface = highSurface; + normal = bodyNormal(origin + direction * travel, agentIndex); + return true; +} + bool traceBody(float3 origin, float3 direction, int agentIndex, out float travel, out float3 normal, out BodySurface surface, out float stepCount) { AgentVisual agent = agentVisuals[agentIndex]; @@ -40,6 +70,9 @@ bool traceBody(float3 origin, float3 direction, int agentIndex, out float travel normal = 0.0; stepCount = 0.0; surface = bodySurface(origin + direction * travel, agentIndex); + float previousTravel = travel; + float previousDistance = surface.distanceValue; + float maxStep = max(agent.centerRadius.w * BODY_TRACE_MAX_STEP_RADIUS_SCALE, BODY_TRACE_MIN_STEP); [loop] for (int stepIndex = 0; stepIndex < BODY_TRACE_STEPS; stepIndex++) @@ -52,13 +85,20 @@ bool traceBody(float3 origin, float3 direction, int agentIndex, out float travel float3 p = origin + direction * travel; surface = bodySurface(p, agentIndex); stepCount = (float)(stepIndex + 1); + if (previousDistance > 0.0 && surface.distanceValue <= 0.0) + { + return refineBodyHit(origin, direction, agentIndex, previousTravel, travel, travel, normal, surface); + } + if (abs(surface.distanceValue) < max(BODY_TRACE_MIN_STEP, travel * 0.00018)) { normal = bodyNormal(p, agentIndex); return true; } - travel += max(abs(surface.distanceValue) * BODY_TRACE_STEP_SCALE, BODY_TRACE_MIN_STEP); + previousTravel = travel; + previousDistance = surface.distanceValue; + travel += clamp(abs(surface.distanceValue) * BODY_TRACE_STEP_SCALE, BODY_TRACE_MIN_STEP, maxStep); } return false; diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12SdfMath.hlsli b/src/Aquarium.Engine/Render/Shaders/D3D12SdfMath.hlsli index 3d220ee..a4ac909 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12SdfMath.hlsli +++ b/src/Aquarium.Engine/Render/Shaders/D3D12SdfMath.hlsli @@ -41,6 +41,12 @@ float smoothUnion(float a, float b, float radius) return lerp(b, a, h) - radius * h * (1.0 - h); } +float sdEllipseFootprint(float2 p, float2 radius) +{ + float2 safeRadius = max(radius, 0.001); + return (length(p / safeRadius) - 1.0) * min(safeRadius.x, safeRadius.y); +} + float teardropProfileRadius(float z, float contactZ, float tipZ, float radiusScale, float ripplePhase, float rippleAmount) { float u = saturate((z - contactZ) / (tipZ - contactZ)); @@ -68,14 +74,16 @@ 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.36, 0.08 + 0.030 * sin(phase)); + float3 center = float3(radial * 0.34, 0.10 + 0.030 * sin(phase)); float3 p = local - center; float3 q = float3(dot(p.xy, radial), dot(p.xy, tangent), p.z); - float flare = saturate((q.x + 0.28) * 1.25); - float ruffle = 0.035 * sin(q.y * 28.0 + q.x * 7.0 + phase) * flare; - float curl = 0.075 * sin(q.x * 3.8 + phase) * flare; - float petal = sdEllipsoid(q + float3(0.0, ruffle, curl), float3(0.86, 0.25, 0.24)); - return petal; + float flare = saturate((q.x + 0.34) * 1.18); + float surfaceZ = -0.08 * q.x * q.x + 0.10 * sin(q.x * 2.6 + phase) * flare; + float rib = 0.018 * sin(q.y * 34.0 + q.x * 9.0 + phase) * flare; + float sheet = abs(q.z - surfaceZ - rib) - 0.026; + float footprint = sdEllipseFootprint(float2(q.x - 0.12, q.y), float2(0.92, 0.26)); + float notch = sdEllipseFootprint(float2(q.x + 0.54, q.y), float2(0.20, 0.18)); + return max(max(sheet, footprint), -notch); } float sdHibiscusCursor(float3 local, float timeSeconds) diff --git a/state/evidence.jsonl b/state/evidence.jsonl index f8aaf6d..89f0eee 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -35,3 +35,4 @@ {"timestamp":"2026-05-11T23:17:40+01:00","topic":"body-proxy-screen-space-convention","lesson":"Body proxy quads and body proxy ray construction must use the same screen-space Y convention as the fullscreen scene pass. Clip-space proxy center should use projected.y directly, and the proxy pixel shader must convert SV_Position top-left pixel coordinates to the bottom-left pixel coordinates expected by rayDirectionForPixel. If they disagree, bodies appear to swim in camera space instead of staying grounded in world space.","files":["src/Aquarium.Engine/Render/Shaders/D3D12BodyCommon.hlsli","src/Aquarium.Engine/Render/Shaders/D3D12BodyProxy.hlsli"],"source":"visible transform bug report"} {"timestamp":"2026-05-11T23:23:04+01:00","topic":"cursor-hibiscus-anatomy","lesson":"The cursor hibiscus needs recognizable flower anatomy, not just three glossy petals. The cursor SDF now includes curled ruffled petals, a throat, a protruding staminal column with pollen beads, and a green calyx/contact stem, with a larger proxy bound to prevent clipping the expanded silhouette.","files":["src/Aquarium.Engine/Render/Shaders/D3D12SdfMath.hlsli","src/Aquarium.Engine/Render/Shaders/D3D12CursorBody.hlsl","src/Aquarium.Engine/Render/D3D12Renderer.cs"],"source":"visual reference comparison"} {"timestamp":"2026-05-11T23:35:00+01:00","topic":"thin-structure-body-marching","lesson":"All role bodies are expected to carry thin visible structure, so conservative body SDF tracing is the shared default rather than a cursor-specific exception. Body proxy tracing now uses tighter hit epsilon, more steps, and smaller step scale through shared macros; faster tracing should only reappear through explicit LOD policy after it proves it preserves filaments, ribs, rings, petals, and other narrow organs.","files":["src/Aquarium.Engine/Render/Shaders/D3D12BodyProxy.hlsli","src/Aquarium.Engine/Render/Shaders/D3D12CursorBody.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12SdfMath.hlsli","state/memory.json"],"source":"user visual artifact review"} +{"timestamp":"2026-05-11T23:39:00+01:00","topic":"sheet-sdf-petals-and-guarded-marching","lesson":"Do not represent petals and other thin organs as fat ellipsoids with decorative displacement. The recursive lotus reference preserves delicate structure by using slab/intersection fields and scaling the distance estimate after its log-spherical mapping; Aquarium cursor petals now use thin clipped sheet SDFs, and the shared body marcher caps step length plus refines positive-to-negative sign crossings instead of trusting pseudo-distance composites blindly.","files":["src/Aquarium.Engine/Render/Shaders/D3D12BodyProxy.hlsli","src/Aquarium.Engine/Render/Shaders/D3D12SdfMath.hlsli","state/memory.json"],"source":"https://github.com/pac-dev/notes/blob/master/content/logspherical/recursive_lotus.glsl"} diff --git a/state/memory.json b/state/memory.json index 82d4ac5..8aa2d95 100644 --- a/state/memory.json +++ b/state/memory.json @@ -41,6 +41,7 @@ "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.", "Chained smooth-union role organs need conservative tracing even when each primitive has a decent distance estimate. Keep petal overlaps substantial, union radii generous, hit epsilon tight, and step scale small enough that narrow joins are sampled instead of skipped.", "All role bodies should be expected to contain thin structure. The shared body proxy marcher must default to conservative tracing that preserves stamens, petals, ribs, rings, filaments, and other narrow organs; faster tracing belongs behind explicit LOD policy, not private one-off body overrides.", + "Thin petal-like organs should be modeled as sheet/slab fields with explicit footprint bounds, not fat ellipsoids with decorative warps. If a transform or warp changes local metric, either scale the returned distance estimate conservatively like log-spherical SDF examples do, or cap the marcher step and refine sign crossings.", "Imagination should read as distinct petals first, not as a fully merged blob. Keep the central seed small, make petal lobes narrow and visibly separated, and accept intentional negative space when it makes the role shape legible.", "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.",