Soften cursor profile seam

This commit is contained in:
Meta Vens 2026-05-10 07:07:04 +01:00
commit 69244ade75
4 changed files with 14 additions and 4 deletions

View file

@ -276,12 +276,19 @@ float cursorTopProfileSlope(float t)
float cursorBottomProfileRadius(float t)
{
return 1.0 - sqrt(saturate(t));
static const float SqrtSoftening = 0.035;
float root0 = sqrt(SqrtSoftening);
float root1 = sqrt(1.0 + SqrtSoftening);
float x = (sqrt(saturate(t) + SqrtSoftening) - root0) / (root1 - root0);
return 1.0 - x;
}
float cursorBottomProfileSlope(float t)
{
return -0.5 * rsqrt(max(saturate(t), 0.001));
static const float SqrtSoftening = 0.035;
float root0 = sqrt(SqrtSoftening);
float root1 = sqrt(1.0 + SqrtSoftening);
return -0.5 * rsqrt(saturate(t) + SqrtSoftening) / (root1 - root0);
}
float cursorTopSdf(float3 p)

View file

@ -116,3 +116,4 @@
{"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"]}
{"timestamp":"2026-05-10T07:06:19.6550636+01:00","topic":"d3d12-cursor-profile-seam","lesson":"Do not join a raw `1 - sqrt(x)` profile at `x = 0`; the infinite slope at the waist seam creates noisy normals and march instability. Soften the sqrt input with a small epsilon and renormalize the curve so the endpoints stay pinned while the seam slope becomes finite.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","state/memory.json","state/scratch.md"]}

View file

@ -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 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.",
"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 softened/renormalized `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. Avoid infinite-slope joins such as raw `sqrt` at a seam.",
"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.",

View file

@ -80,7 +80,9 @@ reusing field identity/travel/control.
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.
the profile slope and marches with smaller steps. The bottom `1 - sqrt(x)`
profile is softened/renormalized near `x = 0` so the waist seam does not
inherit an infinite slope.
## Hot Context