From 1fb689fd8da3cf3a1947fb8a622fc38196876c28 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 10 May 2026 07:52:03 +0100 Subject: [PATCH] Use MathWorld teardrop cursor profile --- .../Render/Shaders/D3D12Scene.hlsl | 26 +++++++------------ state/evidence.jsonl | 3 ++- state/memory.json | 2 +- state/scratch.md | 10 +++---- 4 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl b/src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl index 2f17ecb..8b5742a 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl @@ -263,26 +263,18 @@ bool traceSphereInInterval(float3 origin, float3 direction, float3 center, float float cursorLocatorProfileRadius(float z) { static const float ContactZ = -1.0; - static const float BulbCenterZ = -0.46; - static const float BulbRadius = 0.54; - static const float TipStartZ = -0.10; static const float TipZ = 1.15; - static const float TipBaseRadius = 0.34; + static const float RadiusScale = 0.78; float u = saturate((z - ContactZ) / (TipZ - ContactZ)); - float sphereY = (z - BulbCenterZ) / BulbRadius; - float bulbRadius = BulbRadius * sqrt(saturate(1.0 - sphereY * sphereY)); - float tipT = saturate((z - TipStartZ) / (TipZ - TipStartZ)); - float taper = (1.0 - tipT); - float tipRadius = TipBaseRadius * taper * taper * taper; - float blend = smoothstep(-0.24, 0.10, z); - float baseRadius = lerp(bulbRadius, tipRadius, blend); - baseRadius = max(baseRadius, 0.0); - float rippleEnvelope = smoothstep(0.08, 0.22, u) * (1.0 - smoothstep(0.72, 0.92, u)); - float rippleWave = 0.5 + 0.5 * sin(z * 28.0 - timeSeconds * 4.0); - float rippleRidge = rippleWave * rippleWave * rippleWave; - float rippleRadius = min(0.018, baseRadius * 0.10) * rippleRidge * rippleEnvelope; - return baseRadius + rippleRadius; + float x = u * 2.0 - 1.0; + float halfTerm = (1.0 - x) * 0.5; + float teardropWeight = halfTerm * halfTerm * halfTerm; + float baseRadius = RadiusScale * sqrt(saturate(1.0 - x * x)) * teardropWeight; + float rippleEnvelope = smoothstep(0.08, 0.22, u) * (1.0 - smoothstep(0.76, 0.94, u)); + float rippleWave = sin(z * 28.0 - timeSeconds * 4.0); + float rippleRadius = min(0.014, baseRadius * 0.07) * rippleWave * rippleEnvelope; + return max(baseRadius + rippleRadius, 0.0); } float cursorLocatorSdf(float3 p) diff --git a/state/evidence.jsonl b/state/evidence.jsonl index ae17ad2..bc46f20 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -121,6 +121,7 @@ {"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"]} {"timestamp":"2026-05-10T07:31:25.0639878+01:00","topic":"d3d12-cursor-asymmetric-teardrop","lesson":"The segmented droplet/needle profile still read as a constructed seed/locator rather than a mathematical teardrop. The live cursor profile is a single asymmetric lobe with radius proportional to normalized `u * (1 - u)^2`, contact at local z=-1, tip at local z=1.15, and bound radius 0.72. This biases the mass downward while keeping the evaluator polynomial and cheap.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","state/memory.json","state/scratch.md"]} -{"timestamp":"2026-05-10T07:35:54.0685316+01:00","topic":"d3d12-cursor-sdf-ripples","lesson":"Cursor surface juice should compose through the SDF, not only through shading. The teardrop radius now gets small latitudinal ridge offsets from `sin(localZ * 28 - time * 4)`, and the shader glow uses the same phase so normals, silhouette, and highlight all agree.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","state/memory.json","state/scratch.md"]} +{"timestamp":"2026-05-10T07:35:54.0685316+01:00","topic":"d3d12-cursor-sdf-ripples","lesson":"Cursor surface juice should compose through the SDF, not only through shading. The teardrop radius gets small signed latitudinal offsets from `sin(localZ * 28 - time * 4)`, so crests and troughs both exist in the actual SDF instead of only seeing the positive half-wave as outward shelves.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","state/memory.json","state/scratch.md"]} {"timestamp":"2026-05-10T07:41:01.6985223+01:00","topic":"d3d12-diegetic-cursor-material","lesson":"Cursor ripples should be SDF geometry, not emissive glow. The cursor material is now brass/metallic with Self-lit diffuse, brass specular, and Fresnel reflection; the old cyan glow was removed. The remaining constant ambient diffuse floors on cursor and planet shading were also cut so only diegetic light shapes solid bodies.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","state/memory.json","state/scratch.md"]} {"timestamp":"2026-05-10T07:43:40.3417470+01:00","topic":"d3d12-cursor-round-bulb-polish","lesson":"To avoid pagoda shelves and make the cursor bulb read more spherical, derive the lower profile from a sphere around local z=-0.46, blend into a strengthened cubic taper starting near local z=-0.10, and reduce ripple amplitude. Brass should read polished: use a tight high-power specular core plus a smaller shoulder, with no ambient diffuse floor.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","state/memory.json","state/scratch.md"]} +{"timestamp":"2026-05-10T07:47:46.8566891+01:00","topic":"d3d12-cursor-mathworld-teardrop","lesson":"Use the actual MathWorld teardrop curve for the cursor profile instead of hand-sculpted bulb/taper pieces. With x=cos(t) and y=sin(t)*sin^m(t/2), revolving around the x axis gives radius `sqrt(1 - x^2) * ((1 - x) / 2)^(m/2)`. The current shader uses m=6, avoiding fractional pow while giving the higher-exponent teardrop silhouette.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","state/memory.json","state/scratch.md"],"source":"https://mathworld.wolfram.com/TeardropCurve.html"} diff --git a/state/memory.json b/state/memory.json index 30cdecc..7e02c3b 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 an asymmetric teardrop lobe, not a SuperFormula and not the rejected spinning-top/space-station profile: local `z = -1` contacts the Grid, local `z = 1.15` is the top tip, the bulb is sphere-derived around local `z = -0.46`, and the upper section uses a strengthened cubic taper. Cursor latitudinal ripples belong in the SDF radius function first; material is brass/metallic, sharper-specular, non-emissive, and has no ambient diffuse floor. 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.", + "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 uses the MathWorld teardrop curve profile with m=6, revolved around vertical: x=cos(t), y=sin(t)*sin^m(t/2), so radius from vertical x is `sqrt(1 - x^2) * ((1 - x) / 2)^3`. Cursor latitudinal ripples belong in the SDF radius function first; material is brass/metallic, sharper-specular, non-emissive, and has no ambient diffuse floor. 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.", diff --git a/state/scratch.md b/state/scratch.md index 594d481..448e12b 100644 --- a/state/scratch.md +++ b/state/scratch.md @@ -72,11 +72,11 @@ reusing field identity/travel/control. - 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 an asymmetric teardrop lobe: local `z = -1` - kisses the Grid plane, local `z = 1.15` is the top tip, the lower bulb is - sphere-derived around local `z = -0.46`, and the upper section blends into a - strengthened cubic taper so the bulb reads round instead of pagoda/seed. - Shader and CPU froxel bounds must stay matched (`0.72` currently) or - candidate discovery clips the cursor. Frame constants pack + kisses the Grid plane, local `z = 1.15` is the top tip, and radius follows the + MathWorld teardrop curve profile with `m = 6`: from `x = cos(t)`, + `y = sin(t) * sin^m(t/2)`, the revolved profile is + `sqrt(1 - x^2) * ((1 - x) / 2)^3`. 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 profile