From 3ef78937a86aa515f1ee077850794b30bfaa48e4 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 18 May 2026 22:21:34 +0100 Subject: [PATCH] Fuse visual samples with acoustic timing oracle --- docs/temporal-sdf-gaussian-field.md | 25 +++++-- .../Render/AquariumRenderPlan.cs | 59 ++++++++++++++++ src/Aquarium.Engine/Render/D3D12Renderer.cs | 67 ++++++++++++++++++- .../Features/D3D12AcousticConstraintPacket.cs | 10 +++ .../Render/Shaders/D3D12LocalCastFusion.hlsl | 51 ++++++++++++-- .../GpuSensorFrameContractTests.cs | 56 ++++++++++++++++ 6 files changed, 257 insertions(+), 11 deletions(-) create mode 100644 src/Aquarium.Engine/Render/Features/D3D12AcousticConstraintPacket.cs diff --git a/docs/temporal-sdf-gaussian-field.md b/docs/temporal-sdf-gaussian-field.md index 015505e..984ee12 100644 --- a/docs/temporal-sdf-gaussian-field.md +++ b/docs/temporal-sdf-gaussian-field.md @@ -104,15 +104,32 @@ Ownership: - `D3D12Renderer` owns GPU sensor camera metadata storage, UAV-capable temporal Gaussian storage, dispatch, and the transition back to shader-resource state for the draw. +- `AquariumAcousticFieldFrame` carries the ultrasonic chirplet timing oracle and + room/position constraints. Visual evidence may arrive late and be refined, but + acoustic timing is the clock witness for aligning the delayed broadcast world. +- `AquariumCalibrationEventFrame` carries deliberate calibration actions such + as claps. A clap gives the system one event that every camera can see and the + audio timing oracle can timestamp to microsecond-scale uncertainty, making it + the cheap, brutal alignment hammer for camera clock offsets and pose drift. Current Aquarium cut: the contract, D3D12 camera metadata buffer, external texture importer, and sensor SRV table exist. A producer may provide either a duplicated shared handle or a named shared handle for each camera/Leap plane. When sensor textures are present, Aquarium can dispatch fusion without fallback -seeds and write RGB-derived Gaussian samples into the temporal buffer. Next cut: -replace the first-pass per-texture sampling with calibrated stereo/flow/feature -kernels, Leap packed-map channel extraction, and confidence-weighted surface -correspondence. +seeds and write RGB-derived Gaussian samples into the temporal buffer. Those +samples are no longer isolated per-camera flecks: the shader computes a compact +per-sample visual descriptor, compares it against a neighboring camera stream, +raises confidence when stochastic samples appear to correspond, and shrinks the +kernel toward the matched surface. Acoustic constraints from the ultrasonic +chirplet loop bias confidence and velocity near measured room/position returns. + +Next cut: replace the first-pass descriptor comparison with calibrated +epipolar/flow search, Leap packed-map channel extraction, and a persistent GPU +correspondence/refinement buffer that can update camera pose and surface tracks +over the several-second broadcast delay window. Deliberate clap events should +feed that buffer as high-confidence timing correspondences: visual impact frame +per camera against acoustic oracle time, then pose/clock correction under the +same delayed broadcast horizon. The first shader pass also uses camera-facing proxy planes to evaluate each kernel. True ray-integrated volume compositing, Gaussian depth sorting, and diff --git a/src/Aquarium.Engine.Contracts/Render/AquariumRenderPlan.cs b/src/Aquarium.Engine.Contracts/Render/AquariumRenderPlan.cs index 0c27465..9802bf0 100644 --- a/src/Aquarium.Engine.Contracts/Render/AquariumRenderPlan.cs +++ b/src/Aquarium.Engine.Contracts/Render/AquariumRenderPlan.cs @@ -336,6 +336,61 @@ public sealed class AquariumGpuSensorFrame public bool HasInput => Cameras.Count > 0 || ExternalTextures.Count > 0; } +public enum AquariumAcousticConstraintKind +{ + Unknown, + UltrasonicReflector, + VoiceTdoa, + SpeakerProbe, + ClapImpact, +} + +public readonly record struct AquariumAcousticConstraint( + string StableKey, + AquariumAcousticConstraintKind Kind, + Vector3 Position, + Vector3 Velocity, + float RadiusMeters, + float Confidence, + long TimestampNs); + +public sealed class AquariumAcousticFieldFrame +{ + public static AquariumAcousticFieldFrame Empty { get; } = new(); + + public IReadOnlyList Constraints { get; init; } = []; + + public long TimingOracleNs { get; init; } + + public float TimingConfidence { get; init; } + + public float TimingUncertaintyMicroseconds { get; init; } + + public float AccumulationWindowSeconds { get; init; } + + public float PresentationDelaySeconds { get; init; } + + public bool HasInput => Constraints.Count > 0; +} + +public readonly record struct AquariumClapCalibrationEvent( + string StableKey, + Vector3 Position, + long AcousticOracleNs, + long VisualObservedNs, + float TimingUncertaintyMicroseconds, + float VisualConfidence, + float AcousticConfidence); + +public sealed class AquariumCalibrationEventFrame +{ + public static AquariumCalibrationEventFrame Empty { get; } = new(); + + public IReadOnlyList ClapEvents { get; init; } = []; + + public bool HasInput => ClapEvents.Count > 0; +} + public sealed class AquariumGpuFusionField { public static AquariumGpuFusionField Empty { get; } = new(); @@ -376,5 +431,9 @@ public sealed class AquariumSceneState public AquariumGpuSensorFrame GpuSensorFrame { get; init; } = AquariumGpuSensorFrame.Empty; + public AquariumAcousticFieldFrame AcousticFieldFrame { get; init; } = AquariumAcousticFieldFrame.Empty; + + public AquariumCalibrationEventFrame CalibrationEventFrame { get; init; } = AquariumCalibrationEventFrame.Empty; + public AquariumGpuFusionField GpuFusionField { get; init; } = AquariumGpuFusionField.Empty; } diff --git a/src/Aquarium.Engine/Render/D3D12Renderer.cs b/src/Aquarium.Engine/Render/D3D12Renderer.cs index 2670ada..d2eb45d 100644 --- a/src/Aquarium.Engine/Render/D3D12Renderer.cs +++ b/src/Aquarium.Engine/Render/D3D12Renderer.cs @@ -33,6 +33,7 @@ public sealed class D3D12Renderer : IAquariumRenderer private const int MaxSdfObjectCount = 64; private const int MaxGpuSensorCameraCount = 32; private const int MaxGpuSensorTextureCount = 8; + private const int MaxAcousticConstraintCount = 128; private const int GpuSensorSamplesPerTexture = 131_072; private const int MaxTemporalGaussianCount = 1_048_576; private const float SurfaceTransparentMinZ = -1.85f; @@ -59,7 +60,8 @@ public sealed class D3D12Renderer : IAquariumRenderer private const int RootFusionSeeds = 1; private const int RootFusionSensorCameras = 2; private const int RootFusionSensorTextures = 3; - private const int RootFusionOutput = 4; + private const int RootFusionAcousticConstraints = 4; + private const int RootFusionOutput = 5; private static readonly DebugUi.DebugUiOption[] RenderDebugOptions = [ new(0, "Final"), @@ -137,6 +139,7 @@ public sealed class D3D12Renderer : IAquariumRenderer private readonly D3D12StructuredBuffer sdfLightBuffer; private readonly D3D12StructuredBuffer sdfObjectBuffer; private readonly D3D12StructuredBuffer gpuSensorCameraBuffer; + private readonly D3D12StructuredBuffer acousticConstraintBuffer; private readonly D3D12StructuredBuffer gpuFusionSeedBuffer; private readonly D3D12StructuredBuffer temporalGaussianBuffer; private readonly Dictionary externalSensorTextures = new(StringComparer.Ordinal); @@ -145,11 +148,13 @@ public sealed class D3D12Renderer : IAquariumRenderer private readonly AquariumSdfLight[] sdfLights = new AquariumSdfLight[MaxSdfLightCount]; private readonly AquariumSdfObject[] sdfObjects = new AquariumSdfObject[MaxSdfObjectCount]; private readonly D3D12GpuSensorCameraPacket[] gpuSensorCameras = new D3D12GpuSensorCameraPacket[MaxGpuSensorCameraCount]; + private readonly D3D12AcousticConstraintPacket[] acousticConstraints = new D3D12AcousticConstraintPacket[MaxAcousticConstraintCount]; private readonly D3D12GpuFusionSeedPacket[] gpuFusionSeeds = new D3D12GpuFusionSeedPacket[MaxTemporalGaussianCount]; private readonly D3D12TemporalGaussianPacket[] temporalGaussians = new D3D12TemporalGaussianPacket[MaxTemporalGaussianCount]; private int temporalGaussianCount; private int gpuSensorCameraCount; private int gpuSensorTextureCount; + private int acousticConstraintCount; private int gpuFusionSeedCount; private bool temporalGaussiansGpuGenerated; private Viewport viewport; @@ -250,11 +255,13 @@ public sealed class D3D12Renderer : IAquariumRenderer sdfLightBuffer = new D3D12StructuredBuffer(device, MaxSdfLightCount, Marshal.SizeOf(), "Aquarium D3D12 Sdf Light Buffer"); sdfObjectBuffer = new D3D12StructuredBuffer(device, MaxSdfObjectCount, Marshal.SizeOf(), "Aquarium D3D12 Sdf Object Buffer"); gpuSensorCameraBuffer = new D3D12StructuredBuffer(device, MaxGpuSensorCameraCount, Marshal.SizeOf(), "Aquarium D3D12 GPU Sensor Camera Buffer"); + acousticConstraintBuffer = new D3D12StructuredBuffer(device, MaxAcousticConstraintCount, Marshal.SizeOf(), "Aquarium D3D12 Acoustic Constraint Buffer"); gpuFusionSeedBuffer = new D3D12StructuredBuffer(device, MaxTemporalGaussianCount, Marshal.SizeOf(), "Aquarium D3D12 LocalCast GPU Fusion Seed Buffer"); temporalGaussianBuffer = new D3D12StructuredBuffer(device, MaxTemporalGaussianCount, Marshal.SizeOf(), "Aquarium D3D12 Temporal Gaussian Buffer", allowUnorderedAccess: true); resourceRegistry.Add("sdf-light-buffer", sdfLightBuffer); resourceRegistry.Add("sdf-object-buffer", sdfObjectBuffer); resourceRegistry.Add("gpu-sensor-camera-buffer", gpuSensorCameraBuffer); + resourceRegistry.Add("acoustic-constraint-buffer", acousticConstraintBuffer); resourceRegistry.Add("gpu-fusion-seed-buffer", gpuFusionSeedBuffer); resourceRegistry.Add("temporal-gaussian-buffer", temporalGaussianBuffer); commandList = device.CreateCommandList(0, CommandListType.Direct, frames[frameIndex].CommandAllocator, null); @@ -547,7 +554,12 @@ public sealed class D3D12Renderer : IAquariumRenderer temporalGaussianCount, gpuSensorCameraCount, gpuSensorTextureCount, - gpuFusionSeedCount))); + gpuFusionSeedCount), + new Vector4( + acousticConstraintCount, + activeAccumulationWindow, + activePresentationDelay, + frame.Scene.AcousticFieldFrame.HasInput ? 1.0f : 0.0f))); frameResources.FrameConstantsDescriptor = frameResources.TransientShaderDescriptors.Allocate(); device.CreateConstantBufferView( new ConstantBufferViewDescription(frameConstants.GpuVirtualAddress, frameConstants.SizeInBytes), @@ -566,6 +578,8 @@ public sealed class D3D12Renderer : IAquariumRenderer gpuSensorCameraBuffer.CreateShaderResourceView(device, frameResources.GpuSensorCameraDescriptor); frameResources.GpuSensorTextureDescriptor = frameResources.TransientShaderDescriptors.AllocateRange(MaxGpuSensorTextureCount); CreateGpuSensorTextureViews(frame.Scene.GpuSensorFrame, frameResources.GpuSensorTextureDescriptor); + frameResources.AcousticConstraintDescriptor = frameResources.TransientShaderDescriptors.Allocate(); + acousticConstraintBuffer.CreateShaderResourceView(device, frameResources.AcousticConstraintDescriptor); frameResources.GpuFusionSeedDescriptor = frameResources.TransientShaderDescriptors.Allocate(); gpuFusionSeedBuffer.CreateShaderResourceView(device, frameResources.GpuFusionSeedDescriptor); frameResources.TemporalGaussianDescriptor = frameResources.TransientShaderDescriptors.Allocate(); @@ -786,6 +800,7 @@ public sealed class D3D12Renderer : IAquariumRenderer studioPmremTexture.Dispose(); temporalGaussianBuffer.Dispose(); gpuFusionSeedBuffer.Dispose(); + acousticConstraintBuffer.Dispose(); gpuSensorCameraBuffer.Dispose(); foreach (var texture in externalSensorTextures.Values) { @@ -1446,6 +1461,7 @@ public sealed class D3D12Renderer : IAquariumRenderer sdfLightBuffer.Upload(activeCommandList, frameResources.UploadRing, sdfLights); sdfObjectBuffer.Upload(activeCommandList, frameResources.UploadRing, sdfObjects); gpuSensorCameraBuffer.UploadPartial(activeCommandList, frameResources.UploadRing, gpuSensorCameras.AsSpan(0, gpuSensorCameraCount)); + acousticConstraintBuffer.UploadPartial(activeCommandList, frameResources.UploadRing, acousticConstraints.AsSpan(0, acousticConstraintCount)); if (temporalGaussiansGpuGenerated) { gpuFusionSeedBuffer.UploadPartial(activeCommandList, frameResources.UploadRing, gpuFusionSeeds.AsSpan(0, gpuFusionSeedCount)); @@ -1480,6 +1496,7 @@ public sealed class D3D12Renderer : IAquariumRenderer activeCommandList.SetComputeRootDescriptorTable(RootFusionSeeds, frameResources.GpuFusionSeedDescriptor.Gpu); activeCommandList.SetComputeRootDescriptorTable(RootFusionSensorCameras, frameResources.GpuSensorCameraDescriptor.Gpu); activeCommandList.SetComputeRootDescriptorTable(RootFusionSensorTextures, frameResources.GpuSensorTextureDescriptor.Gpu); + activeCommandList.SetComputeRootDescriptorTable(RootFusionAcousticConstraints, frameResources.AcousticConstraintDescriptor.Gpu); activeCommandList.SetComputeRootDescriptorTable(RootFusionOutput, frameResources.TemporalGaussianUnorderedAccessDescriptor.Gpu); activeCommandList.Dispatch((uint)((temporalGaussianCount + 127) / 128), 1, 1); temporalGaussianBuffer.Transition(activeCommandList, ResourceStates.PixelShaderResource | ResourceStates.NonPixelShaderResource); @@ -1585,6 +1602,7 @@ public sealed class D3D12Renderer : IAquariumRenderer temporalGaussianCount = 0; gpuSensorCameraCount = 0; gpuSensorTextureCount = 0; + acousticConstraintCount = 0; gpuFusionSeedCount = 0; temporalGaussiansGpuGenerated = false; heightFieldBrushConstants = D3D12HeightFieldBrushConstants.FromBrushes(scene.HeightFieldBrushes); @@ -1607,6 +1625,21 @@ public sealed class D3D12Renderer : IAquariumRenderer gpuSensorCameras[index] = ToGpuSensorCameraPacket(scene.GpuSensorFrame.Cameras[index]); } + acousticConstraintCount = Math.Min(scene.AcousticFieldFrame.Constraints.Count, MaxAcousticConstraintCount); + for (var index = 0; index < acousticConstraintCount; index++) + { + acousticConstraints[index] = ToAcousticConstraintPacket(scene.AcousticFieldFrame.Constraints[index]); + } + + var clapCapacity = MaxAcousticConstraintCount - acousticConstraintCount; + var clapCount = Math.Min(scene.CalibrationEventFrame.ClapEvents.Count, clapCapacity); + for (var index = 0; index < clapCount; index++) + { + acousticConstraints[acousticConstraintCount + index] = ToClapConstraintPacket(scene.CalibrationEventFrame.ClapEvents[index]); + } + + acousticConstraintCount += clapCount; + if (scene.GpuFusionField.Seeds.Count > 0) { var seedCount = Math.Min(scene.GpuFusionField.Seeds.Count, MaxTemporalGaussianCount); @@ -1636,6 +1669,24 @@ public sealed class D3D12Renderer : IAquariumRenderer } } + private static D3D12AcousticConstraintPacket ToAcousticConstraintPacket(AquariumAcousticConstraint constraint) + { + var confidence = Math.Clamp(constraint.Confidence, 0.0f, 1.0f); + return new D3D12AcousticConstraintPacket( + new Vector4(constraint.Position, MathF.Max(0.001f, constraint.RadiusMeters)), + new Vector4(constraint.Velocity, confidence), + new Vector4((int)constraint.Kind, constraint.TimestampNs * 0.000000001f, 0.0f, 0.0f)); + } + + private static D3D12AcousticConstraintPacket ToClapConstraintPacket(AquariumClapCalibrationEvent clap) + { + var confidence = Math.Clamp(clap.VisualConfidence * clap.AcousticConfidence, 0.0f, 1.0f); + return new D3D12AcousticConstraintPacket( + new Vector4(clap.Position, 0.24f), + new Vector4(Vector3.Zero, confidence), + new Vector4((int)AquariumAcousticConstraintKind.ClapImpact, clap.AcousticOracleNs * 0.000000001f, clap.TimingUncertaintyMicroseconds, 0.0f)); + } + private static D3D12GpuSensorCameraPacket ToGpuSensorCameraPacket(AquariumGpuSensorCamera camera) { static Vector4 Row0(Matrix4x4 matrix) => new(matrix.M11, matrix.M12, matrix.M13, matrix.M14); @@ -2171,6 +2222,12 @@ public sealed class D3D12Renderer : IAquariumRenderer 28, 0, D3D12.DescriptorRangeOffsetAppend); + var acousticConstraintRange = new DescriptorRange( + DescriptorRangeType.ShaderResourceView, + 1, + 36, + 0, + D3D12.DescriptorRangeOffsetAppend); var outputRange = new DescriptorRange( DescriptorRangeType.UnorderedAccessView, 1, @@ -2183,6 +2240,7 @@ public sealed class D3D12Renderer : IAquariumRenderer new RootParameter(new RootDescriptorTable([seedRange]), ShaderVisibility.All), new RootParameter(new RootDescriptorTable([sensorCameraRange]), ShaderVisibility.All), new RootParameter(new RootDescriptorTable([sensorTextureRange]), ShaderVisibility.All), + new RootParameter(new RootDescriptorTable([acousticConstraintRange]), ShaderVisibility.All), new RootParameter(new RootDescriptorTable([outputRange]), ShaderVisibility.All), }; var description = new RootSignatureDescription( @@ -2414,7 +2472,8 @@ public sealed class D3D12Renderer : IAquariumRenderer float BloomIntensity, float BloomVeilIntensity, Vector4 CursorWorlds, - Vector4 TemporalGaussianInfo); + Vector4 TemporalGaussianInfo, + Vector4 GpuFusionInfo); private sealed record D3D12ShaderPaths( string HeightField, @@ -2506,6 +2565,8 @@ public sealed class D3D12Renderer : IAquariumRenderer public D3D12DescriptorSlot GpuSensorTextureDescriptor { get; set; } + public D3D12DescriptorSlot AcousticConstraintDescriptor { get; set; } + public D3D12DescriptorSlot GpuFusionSeedDescriptor { get; set; } public D3D12DescriptorSlot TemporalGaussianDescriptor { get; set; } diff --git a/src/Aquarium.Engine/Render/Features/D3D12AcousticConstraintPacket.cs b/src/Aquarium.Engine/Render/Features/D3D12AcousticConstraintPacket.cs new file mode 100644 index 0000000..8ef9b53 --- /dev/null +++ b/src/Aquarium.Engine/Render/Features/D3D12AcousticConstraintPacket.cs @@ -0,0 +1,10 @@ +using System.Numerics; +using System.Runtime.InteropServices; + +namespace Aquarium.Engine.Render.Features; + +[StructLayout(LayoutKind.Sequential)] +internal readonly record struct D3D12AcousticConstraintPacket( + Vector4 PositionRadius, + Vector4 VelocityConfidence, + Vector4 KindTimePad); diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12LocalCastFusion.hlsl b/src/Aquarium.Engine/Render/Shaders/D3D12LocalCastFusion.hlsl index 0af2beb..b57f716 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12LocalCastFusion.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/D3D12LocalCastFusion.hlsl @@ -23,6 +23,7 @@ cbuffer AquariumFrame : register(b0) float bloomVeilIntensity; float4 cursorWorlds; float4 temporalGaussianInfo; + float4 gpuFusionInfo; }; struct GpuFusionSeed @@ -61,9 +62,17 @@ struct GpuSensorCamera float4 sensorFromWorld2; }; +struct AcousticConstraint +{ + float4 positionRadius; + float4 velocityConfidence; + float4 kindTimePad; +}; + StructuredBuffer fusionSeeds : register(t26); StructuredBuffer sensorCameras : register(t27); Texture2D sensorTextures[8] : register(t28); +StructuredBuffer acousticConstraints : register(t36); RWStructuredBuffer temporalGaussiansOut : register(u0); float Hash01(uint value) @@ -100,6 +109,32 @@ float4 LoadSensorTexture(uint slot, int3 pixel) } } +float AcousticSupport(float3 center, out float3 velocityBias) +{ + uint count = (uint)gpuFusionInfo.x; + velocityBias = float3(0.0, 0.0, 0.0); + float support = 0.0; + float weightSum = 0.0; + [loop] + for (uint index = 0u; index < min(count, 128u); index++) + { + AcousticConstraint constraint = acousticConstraints[index]; + float radius = max(0.001, constraint.positionRadius.w); + float distanceMeters = distance(center, constraint.positionRadius.xyz); + float weight = saturate(1.0 - distanceMeters / radius) * saturate(constraint.velocityConfidence.w); + support = max(support, weight); + velocityBias += constraint.velocityConfidence.xyz * weight; + weightSum += weight; + } + + if (weightSum > 0.0001) + { + velocityBias /= weightSum; + } + + return support; +} + [numthreads(128, 1, 1)] void D3D12LocalCastFusionCS(uint3 dispatchThreadId : SV_DispatchThreadID) { @@ -150,7 +185,13 @@ void D3D12LocalCastFusionCS(uint3 dispatchThreadId : SV_DispatchThreadID) uint x = (localIndex * 73u + (uint)(Hash01(localIndex) * 37.0)) % width; uint y = (localIndex / width * 41u + (uint)(Hash01(localIndex ^ 0x9e3779b9u) * 29.0)) % height; float4 rgba = LoadSensorTexture(textureSlot, int3((int)x, (int)y, 0)); + uint pairSlot = (textureSlot + 1u) % max(1u, textureCount); + float4 pairRgba = LoadSensorTexture(pairSlot, int3((int)x, (int)y, 0)); float luma = dot(rgba.rgb, float3(0.2126, 0.7152, 0.0722)); + float pairLuma = dot(pairRgba.rgb, float3(0.2126, 0.7152, 0.0722)); + float descriptor = frac(luma * 3.17 + rgba.r * 1.91 + rgba.g * 2.37 + Hash01(localIndex ^ 0x27d4eb2du) * 0.07); + float pairDescriptor = frac(pairLuma * 3.17 + pairRgba.r * 1.91 + pairRgba.g * 2.37); + float visualMatch = 1.0 - saturate(abs(descriptor - pairDescriptor) * 3.0 + distance(rgba.rgb, pairRgba.rgb) * 0.35); float fx = max(1.0, camera.intrinsics.x); float fy = max(1.0, camera.intrinsics.y); float cx = camera.intrinsics.z; @@ -162,14 +203,16 @@ void D3D12LocalCastFusionCS(uint3 dispatchThreadId : SV_DispatchThreadID) float focalPixels = max(1.0, 0.5 * (fx + fy)); float screenFitRadius = targetPixels * depth / focalPixels; float radius = clamp(screenFitRadius, 0.0015, 0.018); - float confidence = saturate(0.25 + abs(luma - 0.5) * 1.5); + float3 acousticVelocity; + float acousticSupport = AcousticSupport(center, acousticVelocity); + float confidence = saturate((0.20 + abs(luma - 0.5) * 1.15) * lerp(0.55, 1.25, visualMatch) + acousticSupport * 0.35); gaussian.centerHistoryWeight = float4(center, confidence); gaussian.previousCenterFieldId = float4(center, (float)(textureSlot + 1u)); - gaussian.velocityConfidence = float4(0.0, 0.0, 0.0, confidence); - gaussian.radiiFalloff = float4(radius * 1.65, radius, radius * 1.25, 5.8); + gaussian.velocityConfidence = float4(acousticVelocity, confidence); + gaussian.radiiFalloff = float4(radius * lerp(1.85, 1.25, visualMatch), radius, radius * lerp(1.45, 1.05, visualMatch), 5.8); gaussian.orientation = float4(0.0, 0.0, 0.0, 1.0); gaussian.colorOpacity = float4(rgba.rgb * 1.35, saturate(0.08 + confidence * 0.42)); - gaussian.shapePad = float4(1.85, (float)x / (float)width, (float)y / (float)height, camera.textureRangeTime.z); + gaussian.shapePad = float4(lerp(2.35, 1.45, visualMatch), descriptor, visualMatch, acousticSupport); temporalGaussiansOut[index] = gaussian; } diff --git a/tests/Aquarium.Engine.Tests/GpuSensorFrameContractTests.cs b/tests/Aquarium.Engine.Tests/GpuSensorFrameContractTests.cs index 969fff5..734fa52 100644 --- a/tests/Aquarium.Engine.Tests/GpuSensorFrameContractTests.cs +++ b/tests/Aquarium.Engine.Tests/GpuSensorFrameContractTests.cs @@ -49,4 +49,60 @@ public sealed class GpuSensorFrameContractTests Assert.Equal("LocalCastBridge/KiyoProLeft/Bgra", scene.GpuSensorFrame.ExternalTextures[0].SharedHandleName); Assert.Equal(18.0f, scene.GpuSensorFrame.AccumulationWindowSeconds, 6); } + + [Fact] + public void SceneStateCarriesAcousticTimingOracleWithRoomConstraints() + { + var acoustic = new AquariumAcousticFieldFrame + { + TimingOracleNs = 99_000_000_123, + TimingConfidence = 0.98f, + TimingUncertaintyMicroseconds = 2.5f, + AccumulationWindowSeconds = 6.0f, + PresentationDelaySeconds = 2.0f, + Constraints = + [ + new AquariumAcousticConstraint( + "ultrasonic-wall-return:front", + AquariumAcousticConstraintKind.UltrasonicReflector, + new Vector3(0.0f, 1.2f, 1.1f), + Vector3.Zero, + 0.18f, + 0.87f, + 99_000_000_123) + ], + }; + + var scene = new AquariumSceneState { AcousticFieldFrame = acoustic }; + + Assert.True(scene.AcousticFieldFrame.HasInput); + Assert.Equal(99_000_000_123, scene.AcousticFieldFrame.TimingOracleNs); + Assert.Equal(2.5f, scene.AcousticFieldFrame.TimingUncertaintyMicroseconds, 6); + Assert.Equal(AquariumAcousticConstraintKind.UltrasonicReflector, scene.AcousticFieldFrame.Constraints[0].Kind); + } + + [Fact] + public void SceneStateCarriesClapCalibrationEventAlignedToAcousticOracle() + { + var events = new AquariumCalibrationEventFrame + { + ClapEvents = + [ + new AquariumClapCalibrationEvent( + "clap:host:0001", + new Vector3(0.12f, 0.4f, 1.35f), + AcousticOracleNs: 123_456_789_000, + VisualObservedNs: 123_456_805_000, + TimingUncertaintyMicroseconds: 1.8f, + VisualConfidence: 0.82f, + AcousticConfidence: 0.97f) + ], + }; + + var scene = new AquariumSceneState { CalibrationEventFrame = events }; + + Assert.True(scene.CalibrationEventFrame.HasInput); + Assert.Equal(123_456_789_000, scene.CalibrationEventFrame.ClapEvents[0].AcousticOracleNs); + Assert.True(scene.CalibrationEventFrame.ClapEvents[0].AcousticConfidence > scene.CalibrationEventFrame.ClapEvents[0].VisualConfidence); + } }