Replace cursor top with droplet locator

This commit is contained in:
Meta Vens 2026-05-10 07:27:36 +01:00
commit 641ad66ec2
5 changed files with 53 additions and 70 deletions

View file

@ -39,7 +39,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
private const int BloomLevelCount = 3;
private const float SunRadius = 1.12f;
private const float CursorBodyRadius = 0.56f;
private const float CursorBodyBoundRadius = 1.46f;
private const float CursorBodyBoundRadius = 0.72f;
private const Format SceneHdrFormat = Format.R16G16B16A16_Float;
private const string GridShaderRelativePath = "Render/Shaders/D3D12Grid.hlsl";
private const string SmokeShaderRelativePath = "Render/Shaders/D3D12Smoke.hlsl";

View file

@ -37,7 +37,7 @@ static const float FIELD_ID_CURSOR = 5.0;
static const float FIELD_ID_PLANET_BASE = 10.0;
static const int CURSOR_PRIMITIVE_ID = PLANET_COUNT + 1;
static const float CURSOR_RADIUS = 0.56;
static const float CURSOR_BOUND_RADIUS = 1.46;
static const float CURSOR_BOUND_RADIUS = 0.72;
static const int MEDIUM_FROXEL_ATLAS_COLUMNS = 8;
static const int MEDIUM_FROXEL_ATLAS_ROWS = 4;
static const int MEDIUM_FROXEL_DOWNSCALE = 8;
@ -260,76 +260,63 @@ bool traceSphereInInterval(float3 origin, float3 direction, float3 center, float
return travel >= intervalStart && travel <= intervalEnd;
}
float cursorTopProfileRadius(float t)
float smootherstep(float t)
{
float u = saturate(t);
float x = u * u * (0.55 + 0.45 * u);
float x = saturate(t);
return x * x * x * (x * (x * 6.0 - 15.0) + 10.0);
}
float cursorTopProfileSlope(float t)
float cursorLocatorProfileRadius(float z)
{
float u = saturate(t);
float x = u * u * (0.55 + 0.45 * u);
float shapedSlope = 1.1 * u + 1.35 * u * u;
float smootherstepSlope = 30.0 * x * x * (1.0 - x) * (1.0 - x);
return smootherstepSlope * shapedSlope;
static const float ContactZ = -1.0;
static const float BellyZ = -0.42;
static const float NeckZ = 0.18;
static const float TipZ = 0.95;
static const float BellyRadius = 0.26;
static const float NeckRadius = 0.055;
if (z < BellyZ)
{
float t = (z - ContactZ) / (BellyZ - ContactZ);
return BellyRadius * smootherstep(t);
}
if (z < NeckZ)
{
float t = (z - BellyZ) / (NeckZ - BellyZ);
return lerp(BellyRadius, NeckRadius, smootherstep(t));
}
float t = (z - NeckZ) / (TipZ - NeckZ);
return NeckRadius * (1.0 - smootherstep(t));
}
float cursorBottomProfileRadius(float t)
float cursorLocatorSdf(float3 p)
{
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)
{
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)
{
static const float BottomHeight = 0.625;
static const float TopHeight = 2.50;
static const float WaistRadius = 0.70;
static const float SeamBlendHeight = 0.07;
static const float ContactZ = -1.0;
static const float TipZ = 0.95;
float3 center = float3(cursorWorlds.xy, CURSOR_RADIUS);
float3 local = (p - center) / CURSOR_RADIUS;
float2 samplePoint = float2(length(local.xy), local.z);
float topT = saturate((TopHeight - samplePoint.y) / TopHeight);
float bottomT = saturate(-samplePoint.y / BottomHeight);
float topRadius = WaistRadius * cursorTopProfileRadius(topT);
float bottomRadius = WaistRadius * cursorBottomProfileRadius(bottomT);
float topSlope = -WaistRadius * cursorTopProfileSlope(topT) / TopHeight;
float bottomSlope = -WaistRadius * cursorBottomProfileSlope(bottomT) / BottomHeight;
float seamBlend = smoothstep(-SeamBlendHeight, SeamBlendHeight, samplePoint.y);
float profileRadius = lerp(bottomRadius, topRadius, seamBlend);
float profileSlope = lerp(bottomSlope, topSlope, seamBlend);
float profileRadius = cursorLocatorProfileRadius(samplePoint.y);
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(surfaceDistance, max(topDistance, bottomDistance));
float topDistance = samplePoint.y - TipZ;
float bottomDistance = ContactZ - samplePoint.y;
float boundedDistance = max(radialDistance, max(topDistance, bottomDistance));
return boundedDistance * CURSOR_RADIUS;
}
float3 cursorTopNormal(float3 p)
float3 cursorLocatorNormal(float3 p)
{
float epsilon = 0.006;
float dx = cursorTopSdf(p + float3(epsilon, 0.0, 0.0)) - cursorTopSdf(p - float3(epsilon, 0.0, 0.0));
float dy = cursorTopSdf(p + float3(0.0, epsilon, 0.0)) - cursorTopSdf(p - float3(0.0, epsilon, 0.0));
float dz = cursorTopSdf(p + float3(0.0, 0.0, epsilon)) - cursorTopSdf(p - float3(0.0, 0.0, epsilon));
float dx = cursorLocatorSdf(p + float3(epsilon, 0.0, 0.0)) - cursorLocatorSdf(p - float3(epsilon, 0.0, 0.0));
float dy = cursorLocatorSdf(p + float3(0.0, epsilon, 0.0)) - cursorLocatorSdf(p - float3(0.0, epsilon, 0.0));
float dz = cursorLocatorSdf(p + float3(0.0, 0.0, epsilon)) - cursorLocatorSdf(p - float3(0.0, 0.0, epsilon));
return normalize(float3(dx, dy, dz));
}
bool traceCursorTop(float3 origin, float3 direction, float intervalStart, float intervalEnd, out float travel, out float3 normal)
bool traceCursorLocator(float3 origin, float3 direction, float intervalStart, float intervalEnd, out float travel, out float3 normal)
{
float sphereTravel;
float3 center = float3(cursorWorlds.xy, CURSOR_RADIUS);
@ -357,14 +344,14 @@ bool traceCursorTop(float3 origin, float3 direction, float intervalStart, float
}
float3 p = origin + direction * travel;
float distanceValue = cursorTopSdf(p);
float distanceValue = cursorLocatorSdf(p);
if (abs(distanceValue) < max(0.0025, travel * 0.00025))
{
normal = cursorTopNormal(p);
normal = cursorLocatorNormal(p);
return true;
}
travel += max(abs(distanceValue) * 0.58, 0.003);
travel += max(abs(distanceValue) * 0.36, 0.0025);
}
return false;
@ -455,7 +442,7 @@ void considerFroxelPrimitiveHits(float3 origin, float3 direction, int froxelInde
{
float hitTravel;
float3 hitNormal;
if (traceCursorTop(origin, direction, intervalStart, min(intervalEnd, nearest.travel), hitTravel, hitNormal))
if (traceCursorLocator(origin, direction, intervalStart, min(intervalEnd, nearest.travel), hitTravel, hitNormal))
{
nearest.hit = true;
nearest.travel = hitTravel;

View file

@ -119,3 +119,4 @@
{"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"]}
{"timestamp":"2026-05-10T07:10:43.9346067+01:00","topic":"d3d12-cursor-profile-art-direction","lesson":"The cursor spinning-top profile reads better when the upper falloff is less abrupt and the waist shelf is smaller. Use shaped smoothstep with exponent 2.25 instead of 2.8, reduce waist radius from 0.78 to 0.70, and blend upper/lower profile radius and slope across a narrow waist band so it feels like a plausible object rather than two perfect curves meeting at a knife seam.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","state/memory.json","state/scratch.md"]}
{"timestamp":"2026-05-10T07:17:08.0401608+01:00","topic":"d3d12-cursor-tall-top-profile","lesson":"The cursor top needed more height and less high mass. Doubling the upper profile height to 2.50 local units and using a polynomial-shaped smootherstep (`x = t*t*(0.55 + 0.45*t)`, then quintic smootherstep) keeps the spire slim up high and flatter near the waist without reintroducing fractional `pow` compile stalls. The taller shape requires matching shader and CPU froxel bound radii of 1.46.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","state/memory.json","state/scratch.md"]}
{"timestamp":"2026-05-10T07:26:31.5212759+01:00","topic":"d3d12-cursor-droplet-locator","lesson":"The symmetric spinning-top cursor read as a space station, and the first droplet/needle pass read as a candle flame. The live cursor profile is now a smaller droplet/needle locator: local z=-1 contacts the Grid, a modest belly peaks near z=-0.42, the needle ends near z=0.95, and CPU/HLSL bounds are 0.72. Keep this profile cheap; numeric slope probes and fractional pow made D3D12 initial pipeline compile exceed the headless startup timeout.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","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 section is tall and grows top-to-waist with a polynomial-shaped smootherstep (`x = t*t*(0.55 + 0.45*t)`, then quintic smootherstep), lower third shrinks waist-to-bottom with softened/renormalized `1 - sqrt(x)`, and a narrow seam blend avoids a perfect mathematical join. Keep the shader bound radius and CPU froxel bound radius matched. 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, and avoid fractional `pow` in this hot profile path because it can stall D3D12 shader pipeline compilation.",
"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 small droplet/needle locator, not a SuperFormula and not the rejected spinning-top/space-station profile: local `z = -1` contacts the Grid, the modest belly peaks near local `z = -0.42`, and the needle ends near local `z = 0.95`. Keep the shader bound radius and CPU froxel bound radius matched. Profile fields are not automatically distance fields; for this hot profile path, prefer conservative step scale and cheap polynomial pieces over sampled profile distance, numeric slope probes, or fractional `pow`, all of which can stall D3D12 shader pipeline compilation.",
"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

@ -69,24 +69,19 @@ reusing field identity/travel/control.
panning. D3D12 now stores fixed world-space `CloudCenters`; Grid can remain a
moving visibility window, but medium bodies must not ride it unless simulation
state explicitly moves them.
- Cursor spinning-top SDF: `AquariumFrame` now carries the mouse cursor
projected onto the Grid XY plane. D3D12 bins a cursor primitive into the
existing view-froxel solid table and traces it as a revolved 2D profile: the
upper section is twice the earlier height and grows top-to-waist with a
polynomial-shaped smootherstep (`x = t*t*(0.55 + 0.45*t)`, then quintic
smootherstep), and the lower third shrinks waist-to-bottom with softened
`1 - sqrt(x)`. A narrow profile-space blend around the waist seam keeps the
object from reading as two perfect mathematical surfaces jammed together.
The shader and CPU froxel binning both need the enlarged cursor bound radius
(`1.46`) or the taller tip gets clipped out of candidate discovery. Frame
- Cursor locator SDF: `AquariumFrame` carries the mouse cursor projected onto
the Grid XY plane. D3D12 bins a cursor primitive into the existing view-froxel
solid table and traces it as a small droplet/needle locator: local `z = -1`
kisses the Grid plane, the modest belly peaks near local `z = -0.42`, and the
upper needle ends at local `z = 0.95`. Shader and CPU froxel bounds must stay
matched (`0.72` currently) or candidate discovery clips the cursor. Frame
constants pack current and 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 and fractional
`pow` in the profile path both 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.
Keep heavy SDF evaluators outside generic packed-id hit helpers, and keep this
profile analytic/cheap: sampled profile-segment distance, numeric slope
probing, and fractional `pow` all stalled D3D12 pipeline compilation. The
earlier spinning-top profile read as a space station or candle flame; keep it
as evidence, not live cursor doctrine.
## Hot Context