Fix stochastic Grid temporal accumulation

This commit is contained in:
Meta Vens 2026-05-08 23:18:55 +01:00
commit 2dd6da3bac
6 changed files with 22 additions and 3 deletions

View file

@ -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.

View file

@ -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.

View file

@ -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);

View file

@ -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"}

View file

@ -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."
],

View file

@ -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.