Replace cursor SDF with spinning top profile
This commit is contained in:
parent
3e92664c7d
commit
88c9987c62
4 changed files with 42 additions and 28 deletions
|
|
@ -260,36 +260,48 @@ bool traceSphereInInterval(float3 origin, float3 direction, float3 center, float
|
|||
return travel >= intervalStart && travel <= intervalEnd;
|
||||
}
|
||||
|
||||
float superFormulaRadius(float angle, float m, float n1, float n2, float n3)
|
||||
float cursorTopProfileRadius(float t)
|
||||
{
|
||||
float c = abs(cos(m * angle * 0.25));
|
||||
float s = abs(sin(m * angle * 0.25));
|
||||
return pow(pow(c, n2) + pow(s, n3), -1.0 / n1);
|
||||
float x = saturate(t);
|
||||
return x * x * (3.0 - 2.0 * x);
|
||||
}
|
||||
|
||||
float cursorSuperFormulaSdf(float3 p)
|
||||
float cursorBottomProfileRadius(float t)
|
||||
{
|
||||
return 1.0 - sqrt(saturate(t));
|
||||
}
|
||||
|
||||
float cursorTopSdf(float3 p)
|
||||
{
|
||||
static const float BottomHeight = 0.625;
|
||||
static const float TopHeight = 1.25;
|
||||
static const float WaistRadius = 0.78;
|
||||
|
||||
float3 center = float3(cursorWorlds.xy, CURSOR_RADIUS);
|
||||
float3 local = (p - center) / CURSOR_RADIUS;
|
||||
float distanceFromCenter = max(length(local), 0.0001);
|
||||
float theta = atan2(local.y, local.x);
|
||||
float phi = asin(clamp(local.z / distanceFromCenter, -1.0, 1.0));
|
||||
float radiusTheta = superFormulaRadius(theta, 7.0, 0.34, 1.7, 1.7);
|
||||
float radiusPhi = superFormulaRadius(phi, 5.0, 0.42, 1.35, 1.35);
|
||||
float surfaceRadius = saturate(radiusTheta * radiusPhi) * 0.72 + 0.28;
|
||||
return (distanceFromCenter - surfaceRadius) * CURSOR_RADIUS;
|
||||
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
|
||||
? WaistRadius * cursorTopProfileRadius(topT)
|
||||
: WaistRadius * cursorBottomProfileRadius(bottomT);
|
||||
float radialDistance = samplePoint.x - profileRadius;
|
||||
float topDistance = samplePoint.y - TopHeight;
|
||||
float bottomDistance = -BottomHeight - samplePoint.y;
|
||||
float boundedDistance = max(radialDistance, max(topDistance, bottomDistance));
|
||||
return boundedDistance * CURSOR_RADIUS;
|
||||
}
|
||||
|
||||
float3 cursorSuperFormulaNormal(float3 p)
|
||||
float3 cursorTopNormal(float3 p)
|
||||
{
|
||||
float epsilon = 0.006;
|
||||
float dx = cursorSuperFormulaSdf(p + float3(epsilon, 0.0, 0.0)) - cursorSuperFormulaSdf(p - float3(epsilon, 0.0, 0.0));
|
||||
float dy = cursorSuperFormulaSdf(p + float3(0.0, epsilon, 0.0)) - cursorSuperFormulaSdf(p - float3(0.0, epsilon, 0.0));
|
||||
float dz = cursorSuperFormulaSdf(p + float3(0.0, 0.0, epsilon)) - cursorSuperFormulaSdf(p - float3(0.0, 0.0, epsilon));
|
||||
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));
|
||||
return normalize(float3(dx, dy, dz));
|
||||
}
|
||||
|
||||
bool traceCursorSuperFormula(float3 origin, float3 direction, float intervalStart, float intervalEnd, out float travel, out float3 normal)
|
||||
bool traceCursorTop(float3 origin, float3 direction, float intervalStart, float intervalEnd, out float travel, out float3 normal)
|
||||
{
|
||||
float sphereTravel;
|
||||
float3 center = float3(cursorWorlds.xy, CURSOR_RADIUS);
|
||||
|
|
@ -317,10 +329,10 @@ bool traceCursorSuperFormula(float3 origin, float3 direction, float intervalStar
|
|||
}
|
||||
|
||||
float3 p = origin + direction * travel;
|
||||
float distanceValue = cursorSuperFormulaSdf(p);
|
||||
float distanceValue = cursorTopSdf(p);
|
||||
if (abs(distanceValue) < max(0.0025, travel * 0.00025))
|
||||
{
|
||||
normal = cursorSuperFormulaNormal(p);
|
||||
normal = cursorTopNormal(p);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -415,7 +427,7 @@ void considerFroxelPrimitiveHits(float3 origin, float3 direction, int froxelInde
|
|||
{
|
||||
float hitTravel;
|
||||
float3 hitNormal;
|
||||
if (traceCursorSuperFormula(origin, direction, intervalStart, min(intervalEnd, nearest.travel), hitTravel, hitNormal))
|
||||
if (traceCursorTop(origin, direction, intervalStart, min(intervalEnd, nearest.travel), hitTravel, hitNormal))
|
||||
{
|
||||
nearest.hit = true;
|
||||
nearest.travel = hitTravel;
|
||||
|
|
|
|||
|
|
@ -114,3 +114,4 @@
|
|||
{"timestamp":"2026-05-10T05:00:00.0000000+01:00","topic":"d3d12-event-expected-radiance","lesson":"Do not blue-noise dither a single transparent event candidate. Debug coverage/weight can look smooth while final breaks down if the event color lane still carries binary hit/miss radiance. For the current Grid-only event, write expected premultiplied radiance (`color * coverage`) and reserve blue-noise stochastic selection for a future multi-event chooser where several transparent samples compete.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","src/Aquarium.Engine/Render/D3D12Renderer.cs","state/memory.json","state/scratch.md"]}
|
||||
{"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"]}
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@
|
|||
"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. Do not rely on camera-only reprojection for interactive bodies.",
|
||||
"Heavy 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 expensive evaluator once per relevant froxel; otherwise the shader compiler clones the path into a startup-time punishment device.",
|
||||
"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)`.",
|
||||
"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.",
|
||||
"Use Vortice at the graphics API membrane. Keep CultMath as the CPU math grammar. Do not let third-party math opinions leak inward unless the conversion is explicit.",
|
||||
|
|
|
|||
|
|
@ -69,14 +69,15 @@ 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 SuperFormula SDF: `AquariumFrame` now carries the mouse cursor
|
||||
- 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 an approximate 3D
|
||||
SuperFormula SDF, with normals from the same SDF. Frame constants pack current
|
||||
and previous cursor world anchors so the TAA resolve can reproject cursor hits
|
||||
existing view-froxel solid table and traces it as a revolved 2D profile: the
|
||||
upper two-thirds grows top-to-waist with `3x^2 - 2x^3`, and the lower third
|
||||
shrinks waist-to-bottom with `1 - sqrt(x)`. 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, or the shader compiler duplicates the
|
||||
expensive path across every slot and startup stalls.
|
||||
outside generic packed-id hit helpers, and keep this one analytic/cheap;
|
||||
sampled profile-segment distance stalled D3D12 pipeline compilation.
|
||||
|
||||
## Hot Context
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue