diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl b/src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl index 22c36a8..7baa943 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl @@ -262,15 +262,28 @@ bool traceSphereInInterval(float3 origin, float3 direction, float3 center, float float cursorTopProfileRadius(float t) { - float x = saturate(t); + float x = pow(saturate(t), 2.8); return x * x * (3.0 - 2.0 * x); } +float cursorTopProfileSlope(float t) +{ + float safeT = max(saturate(t), 0.0001); + float x = pow(safeT, 2.8); + float smoothstepSlope = 6.0 * x * (1.0 - x); + return smoothstepSlope * 2.8 * pow(safeT, 1.8); +} + float cursorBottomProfileRadius(float t) { return 1.0 - sqrt(saturate(t)); } +float cursorBottomProfileSlope(float t) +{ + return -0.5 * rsqrt(max(saturate(t), 0.001)); +} + float cursorTopSdf(float3 p) { static const float BottomHeight = 0.625; @@ -282,13 +295,18 @@ float cursorTopSdf(float3 p) float2 samplePoint = float2(length(local.xy), local.z); float topT = saturate((TopHeight - samplePoint.y) / TopHeight); float bottomT = saturate(-samplePoint.y / BottomHeight); - float profileRadius = samplePoint.y >= 0.0 + bool upperProfile = samplePoint.y >= 0.0; + float profileRadius = upperProfile ? WaistRadius * cursorTopProfileRadius(topT) : WaistRadius * cursorBottomProfileRadius(bottomT); + float profileSlope = upperProfile + ? -WaistRadius * cursorTopProfileSlope(topT) / TopHeight + : -WaistRadius * cursorBottomProfileSlope(bottomT) / BottomHeight; float radialDistance = samplePoint.x - profileRadius; + float surfaceDistance = radialDistance * rsqrt(1.0 + min(profileSlope * profileSlope, 144.0)); float topDistance = samplePoint.y - TopHeight; float bottomDistance = -BottomHeight - samplePoint.y; - float boundedDistance = max(radialDistance, max(topDistance, bottomDistance)); + float boundedDistance = max(surfaceDistance, max(topDistance, bottomDistance)); return boundedDistance * CURSOR_RADIUS; } @@ -336,7 +354,7 @@ bool traceCursorTop(float3 origin, float3 direction, float intervalStart, float return true; } - travel += max(abs(distanceValue) * 0.72, 0.004); + travel += max(abs(distanceValue) * 0.58, 0.003); } return false; diff --git a/state/evidence.jsonl b/state/evidence.jsonl index def576e..85b459e 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -115,3 +115,4 @@ {"timestamp":"2026-05-10T05:12:00.0000000+01:00","topic":"d3d12-medium-world-anchors","lesson":"Registered volumetric brushes must be anchored in world space, not Grid visibility space. D3D12 cloud ellipsoids were centered from `frame.Grid.Center`, so panning the camera/Grid dragged the medium with it. Store cloud centers as world-space simulation anchors and let the Grid move independently.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","state/memory.json","state/scratch.md"]} {"timestamp":"2026-05-10T05:42:00.0000000+01:00","topic":"d3d12-cursor-sdf-motion","lesson":"Interactive SDF bodies need their own object-motion reprojection data. The cursor SuperFormula body carries current and previous cursor world anchors in frame constants, and resolve maps current cursor hits to the previous cursor center before sampling history. Heavy specialized SDF traces should be invoked once per matching froxel, not from the generic packed-id helper for every int4 component, or shader compile time can explode.","files":["src/Aquarium.Engine.Contracts/AquariumFrame.cs","src/Aquarium.Engine/AquariumHost.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","state/memory.json","state/scratch.md"]} {"timestamp":"2026-05-10T06:48:21.8223534+01:00","topic":"d3d12-cursor-spinning-top-profile","lesson":"For the cursor body, a revolved 2D profile is a better machine than a SuperFormula when the desired shape is an elongated spinning top. The implemented profile is evaluated top-to-bottom: the upper two-thirds grows from tip to waist with `3x^2 - 2x^3`, and the lower third shrinks from waist to bottom tip with `1 - sqrt(x)`. Keep this evaluator analytic and cheap; sampled profile-segment distance made D3D12 shader pipeline compile stall.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","state/memory.json","state/scratch.md"]} +{"timestamp":"2026-05-10T07:03:23.3356282+01:00","topic":"d3d12-profile-field-conservative-march","lesson":"A revolved profile equation is not automatically a valid SDF. `radial - radius(z)` overestimates distance on sloped/grazing shoulders, which made the cursor top tear open from above. Scale the radial distance by `rsqrt(1 + slope^2)` and use smaller march advances so the field is conservative enough for sphere tracing.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","state/memory.json","state/scratch.md"]} diff --git a/state/memory.json b/state/memory.json index e486852..c63d724 100644 --- a/state/memory.json +++ b/state/memory.json @@ -22,7 +22,7 @@ "Do not put the D3D12 Grid through transparent froxel candidate/event traversal. The one-pass transparent binning experiment made the Grid angle-dependent and brittle. The live Grid contract is direct scene tracing as a non-terminating stochastic event before the nearest solid. Grid must not write the surface packet. Medium has a separate temporal packet even when a solid is behind it; Grid/particles have a separate stochastic-event color+metadata history lane. Git holds the old experiment; runtime code should stay lean.", "D3D12 Grid line width normalization should match the D3D11 reference: use periodic line domains with `fwidth()` and pixel-width constants, not world-space `ddx/ddy(p.xy)` footprint guesses. For a single Grid event, emit expected premultiplied event radiance from analytic coverage; do not blue-noise dither one sample into visible grain. Blue-noise stochastic selection belongs in the future multi-event chooser when several transparent samples compete for one ray/pixel.", "D3D12 solid scene candidate discovery belongs in the view-froxel volume. At 720p the active tube is 160x90x32; primitive ids are indexed by low-res screen cell and depth slice, then scene rays test exact solid intersections inside that slice interval. The CPU-filled view-froxel buffers are bootstrap only; the durable path should become GPU/raster binning so per-frame upload bandwidth does not become the next stupid tax.", - "Mouse/cursor-owned SDF bodies need object-motion reprojection. Carry current and previous cursor world anchors through frame constants and reproject cursor hits from current center to previous center, just like orbiting planets. The current cursor body is a revolved spinning-top profile, not a SuperFormula: upper two-thirds grows top-to-waist with `3x^2 - 2x^3`, lower third shrinks waist-to-bottom with `1 - sqrt(x)`.", + "Mouse/cursor-owned SDF bodies need object-motion reprojection. Carry current and previous cursor world anchors through frame constants and reproject cursor hits from current center to previous center, just like orbiting planets. The current cursor body is a revolved spinning-top profile, not a SuperFormula: upper two-thirds grows top-to-waist with shaped smoothstep `smoothstep(pow(x, 2.8))`, lower third shrinks waist-to-bottom with `1 - sqrt(x)`. Profile fields are not automatically distance fields; scale radial distance by profile slope so grazing rays do not overstep and tear the shoulder.", "Heavy/specialized SDF evaluators should not live inside the generic packed primitive-id hit helper when that helper is called for every int4 component. Detect specialized ids in the froxel loop and invoke the evaluator once per relevant froxel; otherwise the shader compiler clones the path into a startup-time punishment device.", "D3D12 pixel shader UAV registers share the output namespace. If a shader writes SV_Target0, bind the first manual UAV at u1, not u0.", "D3D12 shader routing derives its editable source directory from --shader-source/AQUARIUM_SHADER_SOURCE, then watches D3D12Grid/Medium/Scene/Post/Smoke HLSL files directly. Shader/PSO builds run on a background task. During initial startup, D3D12 should not touch or present the swapchain until the first pipeline set is ready; the host keeps repainting the Win32 splash instead. This can flicker slightly, but it avoids black loading frames and stale DirectWrite loading text in live backbuffers. Hot reload keeps the previous pipeline set if compilation fails.", diff --git a/state/scratch.md b/state/scratch.md index b61e3e7..bd7a55b 100644 --- a/state/scratch.md +++ b/state/scratch.md @@ -77,7 +77,10 @@ reusing field identity/travel/control. previous cursor world anchors so the TAA resolve can reproject cursor hits with object motion instead of camera-only motion. Keep heavy SDF evaluators outside generic packed-id hit helpers, and keep this one analytic/cheap; - sampled profile-segment distance stalled D3D12 pipeline compilation. + sampled profile-segment distance stalled D3D12 pipeline compilation. The + analytic profile field still must be conservative: `radial - radius(z)` + oversteps at grazing views, so the cursor evaluator scales radial distance by + the profile slope and marches with smaller steps. ## Hot Context