From 2dd6da3bac7eafa7de0396b3e70f49e431611084 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 8 May 2026 23:18:55 +0100 Subject: [PATCH] Fix stochastic Grid temporal accumulation --- docs/hlsl-renderer.md | 3 +++ docs/tsr-inspired-taa-spec.md | 10 ++++++++++ src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl | 7 ++++--- state/evidence.jsonl | 1 + state/memory.json | 1 + state/scratch.md | 3 +++ 6 files changed, 22 insertions(+), 3 deletions(-) diff --git a/docs/hlsl-renderer.md b/docs/hlsl-renderer.md index 10aea03..778a075 100644 --- a/docs/hlsl-renderer.md +++ b/docs/hlsl-renderer.md @@ -178,6 +178,9 @@ ramps history authority as that age grows. Gate 3D fixes travel validation to compare previous history travel against the reprojected point's expected distance from the previous camera, not the current frame's camera-to-hit travel. +Gate 3E gives stochastic Grid history its own validation path: it bypasses +opaque-surface neighborhood color clamp/color-delta rejection while still using +field, travel, normal, coverage, reactive, and age checks. It deliberately does not pretend to solve general non-rigid field velocity, volumetric history, or history resurrection yet. diff --git a/docs/tsr-inspired-taa-spec.md b/docs/tsr-inspired-taa-spec.md index 6da5c7a..9a4b092 100644 --- a/docs/tsr-inspired-taa-spec.md +++ b/docs/tsr-inspired-taa-spec.md @@ -187,6 +187,16 @@ Current Gate 3D implementation: travel, because camera motion changes the ray distance even when the world hit is stable +Current Gate 3E implementation: + +- stochastic Grid history bypasses opaque-surface neighborhood color clamping + and current-frame color-delta rejection +- Grid validation still uses field id, travel, normal, coverage continuity, + reactive weight, and history age +- this prevents a current dither miss from declaring the true neighborhood to be + background and crushing the very history that should accumulate stochastic + coverage + This is intentionally still a surface/stochastic coverage contract. It prepares the resolver for volumetrics without lying that a single hit depth describes a whole participating medium. diff --git a/src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl b/src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl index 077937b..572826e 100644 --- a/src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl @@ -1383,6 +1383,7 @@ ResolveOut AquariumResolvePS(VertexOut input) float travelTolerance = max(0.045, expectedPreviousTravel * 0.018); float travelWeight = 1.0 - smoothstep(travelTolerance, travelTolerance * 4.0, travelDelta); float fieldWeight = abs(previousFieldId - currentFieldId) < 0.25 ? 1.0 : 0.0; + bool isGridField = abs(currentFieldId - FIELD_ID_GRID) < 0.25; float normalWeight = 0.0; if (dot(previousNormal, previousNormal) > 0.01 && dot(currentNormal, currentNormal) > 0.01) { @@ -1392,11 +1393,11 @@ ResolveOut AquariumResolvePS(VertexOut input) float3 neighborhoodMin; float3 neighborhoodMax; currentNeighborhood(input.uv, neighborhoodMin, neighborhoodMax); - float3 clampedHistory = clamp(previous.rgb, neighborhoodMin, neighborhoodMax); + float3 clampedHistory = isGridField ? previous.rgb : clamp(previous.rgb, neighborhoodMin, neighborhoodMax); float colorDelta = length(clampedHistory - currentColor); - float colorWeight = 1.0 - smoothstep(0.18, 1.2, colorDelta); + float colorWeight = isGridField ? 1.0 : 1.0 - smoothstep(0.18, 1.2, colorDelta); float reactiveWeight = 1.0 - currentReactive; - float coverageWeight = currentFieldId == FIELD_ID_GRID ? smoothstep(0.02, 0.55, currentCoverage) : 1.0; + float coverageWeight = isGridField ? smoothstep(0.02, 0.55, currentCoverage) : 1.0; float coverageContinuityWeight = 1.0 - smoothstep(0.10, 0.50, abs(previousCoverage - currentCoverage)); float mediumContinuityWeight = 1.0 - smoothstep(0.04, 0.35, abs(previousMediumOpacity - currentMediumOpacity)); float historyConfidence = smoothstep(0.0, 6.0, previousHistoryAge); diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 2868ccc..b6e85ab 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -23,3 +23,4 @@ {"area":"renderer/taa","lesson":"TAA Gate 3B gives temporal-control data its own history ping-pong. Resolve now samples previous control at the reprojected UV and reduces history across stochastic coverage or reserved medium-opacity discontinuities, giving future volumetrics a real continuity signal instead of a one-frame mask.","files":["docs/tsr-inspired-taa-spec.md","docs/hlsl-renderer.md","src/Aquarium.Engine/Render/D3D11Renderer.cs","src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl","state/memory.json","state/scratch.md"],"verification":["dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4"],"ts":"2026-05-08"} {"area":"renderer/taa","lesson":"TAA Gate 3C stores accepted history age in temporal-control history w. The resolver grows age only when validation passes, resets it on failure, and ramps history authority with age so a newly reprojected sample can contribute without immediately carrying full stable-history weight.","files":["docs/tsr-inspired-taa-spec.md","docs/hlsl-renderer.md","src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl","state/memory.json","state/scratch.md"],"verification":["dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4"],"ts":"2026-05-08"} {"area":"renderer/taa","lesson":"TAA Gate 3D fixes travel validation under camera motion. Previous history travel must be compared to the reprojected previous-world position's distance from the previous camera, not to current-frame travel; otherwise stable history is falsely rejected whenever camera motion changes ray distance.","files":["docs/tsr-inspired-taa-spec.md","docs/hlsl-renderer.md","src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl","state/memory.json","state/scratch.md"],"verification":["dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4"],"ts":"2026-05-08"} +{"area":"renderer/taa","lesson":"TAA Gate 3E fixes stochastic Grid accumulation. Opaque-surface neighborhood clamping and current-frame color-delta rejection collapse Grid history on dither-miss frames because the current sample looks like background; Grid history now bypasses those color checks and validates through field, travel, normal, coverage, reactive, and age terms.","files":["docs/tsr-inspired-taa-spec.md","docs/hlsl-renderer.md","src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl","state/memory.json","state/scratch.md"],"verification":["dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4"],"ts":"2026-05-08"} diff --git a/state/memory.json b/state/memory.json index f67ce8f..910b317 100644 --- a/state/memory.json +++ b/state/memory.json @@ -54,6 +54,7 @@ "TAA Gate 3B ping-pongs temporal-control history. Resolve now compares previous/current coverage and reserved medium opacity at the reprojected UV, reducing history across composition and future medium discontinuities.", "TAA Gate 3C stores accepted history age in temporal-control history w. Validation grows age, failed validation resets it, and history authority ramps with age so fresh history can contribute without instantly gaining full trust.", "TAA travel validation must compare previous history travel to the reprojected previous-world point's distance from the previous camera. Comparing previous travel directly to current travel falsely rejects stable history during camera motion.", + "Stochastic Grid TAA must not use opaque-surface neighborhood color clamp or current-frame color-delta rejection. A dither miss makes the current color look like background; Grid history should validate through field/travel/normal/coverage/reactive/age instead.", "Bruneton-style atmospheric scattering is the later sky/planet solution, not the first Grid fog pass. Use LUTs, explicit texture mappings, and unit-tested physical terms when Aquarium reaches ground-to-space atmosphere.", "GigaVoxels-style ray-guided sparse bricks are only for large sparse field/world storage. Do not turn early fog into a monolithic persistent volume cache." ], diff --git a/state/scratch.md b/state/scratch.md index 41f00c9..30477fc 100644 --- a/state/scratch.md +++ b/state/scratch.md @@ -66,3 +66,6 @@ prototype integrated along the camera ray before surface composition. - Temporal Gate 3D: travel validation compares previous history travel against the reprojected point's expected distance from the previous camera. Do not compare previous travel directly to current travel under camera motion. +- Temporal Gate 3E: stochastic Grid history bypasses opaque-surface color clamp + and color-delta rejection. A current dither miss is not evidence that the + true Grid color is background.