diff --git a/docs/hlsl-renderer.md b/docs/hlsl-renderer.md index 1552947..da54332 100644 --- a/docs/hlsl-renderer.md +++ b/docs/hlsl-renderer.md @@ -170,6 +170,9 @@ Gate 3A adds a current-frame temporal-control target. It carries reactive strength, stochastic/composition coverage, and a reserved medium-opacity slot; the resolve now reduces history for low-coverage reactive Grid samples before future volumetrics arrive. +Gate 3B ping-pongs that control target as history too, so the resolver can +compare previous/current coverage and reserved medium opacity at the reprojected +UV. 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 7d74f3d..574528c 100644 --- a/docs/tsr-inspired-taa-spec.md +++ b/docs/tsr-inspired-taa-spec.md @@ -158,6 +158,16 @@ w = reserved - the resolve combines reactive and coverage weights with travel, field, normal, and neighborhood-color validation +Current Gate 3B implementation: + +- temporal-control history ping-pongs alongside color/travel and field/normal + history +- resolve samples previous-frame temporal control at the reprojected UV +- coverage discontinuity reduces history +- medium-opacity discontinuity reduces history, even though real volumetrics do + not write the channel yet +- current temporal control is written into the history set for the next frame + 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/D3D11Renderer.cs b/src/Aquarium.Engine/Render/D3D11Renderer.cs index 1e2d070..d19339a 100644 --- a/src/Aquarium.Engine/Render/D3D11Renderer.cs +++ b/src/Aquarium.Engine/Render/D3D11Renderer.cs @@ -53,12 +53,18 @@ public sealed class D3D11Renderer : IDisposable private readonly ID3D11Texture2D historyMetadataTextureA; private readonly ID3D11RenderTargetView historyMetadataRenderTargetViewA; private readonly ID3D11ShaderResourceView historyMetadataShaderResourceViewA; + private readonly ID3D11Texture2D historyControlTextureA; + private readonly ID3D11RenderTargetView historyControlRenderTargetViewA; + private readonly ID3D11ShaderResourceView historyControlShaderResourceViewA; private readonly ID3D11Texture2D historyTextureB; private readonly ID3D11RenderTargetView historyRenderTargetViewB; private readonly ID3D11ShaderResourceView historyShaderResourceViewB; private readonly ID3D11Texture2D historyMetadataTextureB; private readonly ID3D11RenderTargetView historyMetadataRenderTargetViewB; private readonly ID3D11ShaderResourceView historyMetadataShaderResourceViewB; + private readonly ID3D11Texture2D historyControlTextureB; + private readonly ID3D11RenderTargetView historyControlRenderTargetViewB; + private readonly ID3D11ShaderResourceView historyControlShaderResourceViewB; private readonly ID3D11SamplerState gridSampler; private readonly ID3D11SamplerState ditherSampler; private readonly ID3D11Buffer frameConstantBuffer; @@ -151,12 +157,18 @@ public sealed class D3D11Renderer : IDisposable historyMetadataTextureA = CreateHdrTexture(width, height); historyMetadataRenderTargetViewA = device.CreateRenderTargetView(historyMetadataTextureA); historyMetadataShaderResourceViewA = device.CreateShaderResourceView(historyMetadataTextureA); + historyControlTextureA = CreateHdrTexture(width, height); + historyControlRenderTargetViewA = device.CreateRenderTargetView(historyControlTextureA); + historyControlShaderResourceViewA = device.CreateShaderResourceView(historyControlTextureA); historyTextureB = CreateHdrTexture(width, height); historyRenderTargetViewB = device.CreateRenderTargetView(historyTextureB); historyShaderResourceViewB = device.CreateShaderResourceView(historyTextureB); historyMetadataTextureB = CreateHdrTexture(width, height); historyMetadataRenderTargetViewB = device.CreateRenderTargetView(historyMetadataTextureB); historyMetadataShaderResourceViewB = device.CreateShaderResourceView(historyMetadataTextureB); + historyControlTextureB = CreateHdrTexture(width, height); + historyControlRenderTargetViewB = device.CreateRenderTargetView(historyControlTextureB); + historyControlShaderResourceViewB = device.CreateShaderResourceView(historyControlTextureB); startupProgress?.Invoke("Loading Aetheria blue-noise dither texture"); ditherTexture = CreateDitherTexture(Path.Combine(AppContext.BaseDirectory, DitherTextureRelativePath)); ditherShaderResourceView = device.CreateShaderResourceView(ditherTexture); @@ -268,12 +280,18 @@ public sealed class D3D11Renderer : IDisposable historyMetadataShaderResourceViewB.Dispose(); historyMetadataRenderTargetViewB.Dispose(); historyMetadataTextureB.Dispose(); + historyControlShaderResourceViewB.Dispose(); + historyControlRenderTargetViewB.Dispose(); + historyControlTextureB.Dispose(); historyShaderResourceViewA.Dispose(); historyRenderTargetViewA.Dispose(); historyTextureA.Dispose(); historyMetadataShaderResourceViewA.Dispose(); historyMetadataRenderTargetViewA.Dispose(); historyMetadataTextureA.Dispose(); + historyControlShaderResourceViewA.Dispose(); + historyControlRenderTargetViewA.Dispose(); + historyControlTextureA.Dispose(); sceneShaderResourceView.Dispose(); sceneRenderTargetView.Dispose(); sceneTexture.Dispose(); @@ -365,6 +383,7 @@ public sealed class D3D11Renderer : IDisposable context.PSUnsetShaderResource(5); context.PSUnsetShaderResource(6); context.PSUnsetShaderResource(7); + context.PSUnsetShaderResource(8); context.OMSetRenderTargets(gridHeightRenderTargetView); context.RSSetViewport(0.0f, 0.0f, GridHeightTextureSize, GridHeightTextureSize, 0.0f, 1.0f); context.ClearRenderTargetView(gridHeightRenderTargetView, new Color4(0.0f, 0.0f, 0.0f, 0.0f)); @@ -383,6 +402,7 @@ public sealed class D3D11Renderer : IDisposable context.PSUnsetShaderResource(5); context.PSUnsetShaderResource(6); context.PSUnsetShaderResource(7); + context.PSUnsetShaderResource(8); context.OMSetRenderTargets(new[] { sceneRenderTargetView, sceneMetadataRenderTargetView, sceneControlRenderTargetView }); context.RSSetViewport(0.0f, 0.0f, width, height, 0.0f, 1.0f); context.ClearRenderTargetView(sceneRenderTargetView, new Color4(0.0f, 0.0f, 0.0f, 0.0f)); @@ -407,13 +427,16 @@ public sealed class D3D11Renderer : IDisposable var historyWriteView = frameIndex % 2 == 0 ? historyRenderTargetViewB : historyRenderTargetViewA; var historyMetadataReadView = frameIndex % 2 == 0 ? historyMetadataShaderResourceViewA : historyMetadataShaderResourceViewB; var historyMetadataWriteView = frameIndex % 2 == 0 ? historyMetadataRenderTargetViewB : historyMetadataRenderTargetViewA; + var historyControlReadView = frameIndex % 2 == 0 ? historyControlShaderResourceViewA : historyControlShaderResourceViewB; + var historyControlWriteView = frameIndex % 2 == 0 ? historyControlRenderTargetViewB : historyControlRenderTargetViewA; context.PSUnsetShaderResource(3); context.PSUnsetShaderResource(4); context.PSUnsetShaderResource(5); context.PSUnsetShaderResource(6); context.PSUnsetShaderResource(7); - context.OMSetRenderTargets(new[] { renderTargetView, historyWriteView, historyMetadataWriteView }); + context.PSUnsetShaderResource(8); + context.OMSetRenderTargets(new[] { renderTargetView, historyWriteView, historyMetadataWriteView, historyControlWriteView }); context.RSSetViewport(0.0f, 0.0f, width, height, 0.0f, 1.0f); context.ClearRenderTargetView(renderTargetView, new Color4(0.0f, 0.0f, 0.0f, 1.0f)); context.IASetInputLayout(null); @@ -426,6 +449,7 @@ public sealed class D3D11Renderer : IDisposable context.PSSetShaderResource(5, sceneMetadataShaderResourceView); context.PSSetShaderResource(6, historyMetadataReadView); context.PSSetShaderResource(7, sceneControlShaderResourceView); + context.PSSetShaderResource(8, historyControlReadView); context.PSSetSampler(0, gridSampler); context.Draw(3, 0); } diff --git a/src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl b/src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl index cca6652..1a85b9e 100644 --- a/src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl @@ -24,6 +24,7 @@ Texture2D historyTexture : register(t4); Texture2D currentSceneMetadataTexture : register(t5); Texture2D historyMetadataTexture : register(t6); Texture2D currentSceneControlTexture : register(t7); +Texture2D historyControlTexture : register(t8); SamplerState gridSampler : register(s0); SamplerState ditherSampler : register(s1); @@ -1337,6 +1338,7 @@ struct ResolveOut float4 finalColor : SV_Target0; float4 historyColor : SV_Target1; float4 historyMetadata : SV_Target2; + float4 historyControl : SV_Target3; }; ResolveOut AquariumResolvePS(VertexOut input) @@ -1352,6 +1354,7 @@ ResolveOut AquariumResolvePS(VertexOut input) float3 currentNormal = currentMetadata.yzw; float currentReactive = saturate(currentControl.x); float currentCoverage = saturate(currentControl.y); + float currentMediumOpacity = saturate(currentControl.z); float historyWeight = 0.0; float3 historyColor = currentColor; @@ -1366,9 +1369,12 @@ ResolveOut AquariumResolvePS(VertexOut input) { float4 previous = historyTexture.SampleLevel(gridSampler, previousUv, 0.0); float4 previousMetadata = historyMetadataTexture.SampleLevel(gridSampler, previousUv, 0.0); + float4 previousControl = historyControlTexture.SampleLevel(gridSampler, previousUv, 0.0); float previousTravel = previous.a; float previousFieldId = previousMetadata.x; float3 previousNormal = previousMetadata.yzw; + float previousCoverage = saturate(previousControl.y); + float previousMediumOpacity = saturate(previousControl.z); float travelDelta = abs(previousTravel - currentTravel); float travelTolerance = max(0.045, currentTravel * 0.018); float travelWeight = 1.0 - smoothstep(travelTolerance, travelTolerance * 4.0, travelDelta); @@ -1387,9 +1393,11 @@ ResolveOut AquariumResolvePS(VertexOut input) float colorWeight = 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 coverageContinuityWeight = 1.0 - smoothstep(0.10, 0.50, abs(previousCoverage - currentCoverage)); + float mediumContinuityWeight = 1.0 - smoothstep(0.04, 0.35, abs(previousMediumOpacity - currentMediumOpacity)); historyColor = clampedHistory; - historyWeight = 0.82 * travelWeight * colorWeight * fieldWeight * normalWeight * reactiveWeight * coverageWeight; + historyWeight = 0.82 * travelWeight * colorWeight * fieldWeight * normalWeight * reactiveWeight * coverageWeight * coverageContinuityWeight * mediumContinuityWeight; } } @@ -1398,6 +1406,7 @@ ResolveOut AquariumResolvePS(VertexOut input) output.finalColor = float4(aces(resolved), 1.0); output.historyColor = float4(resolved, currentTravel); output.historyMetadata = currentMetadata; + output.historyControl = currentControl; return output; } diff --git a/state/evidence.jsonl b/state/evidence.jsonl index e9f2033..d162b2b 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -20,3 +20,4 @@ {"area":"renderer/taa","lesson":"TAA Gate 2A adds renderer metadata to history validation. Scene and history now carry material id plus surface normal; resolve rejects material mismatches and normal discontinuities. Grid stochastic surfaces write Grid travel/normal even on dither-miss pixels, preventing temporal accumulation from reprojecting against the body or background behind the diegetic Grid surface.","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 2B replaces coarse material identity with stable field ids and adds analytic object-motion reprojection for orbiting SDF bodies. Planet hits now move from current planet center to previous planet center before history projection, so history follows rigid body motion instead of relying only on camera reprojection.","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 3A adds a current-frame temporal-control target separate from field/normal metadata. It carries reactive strength, stochastic/composition coverage, a reserved medium-opacity slot, and a spare channel; the resolve now reduces history for low-coverage reactive Grid samples while keeping the volumetric contract explicit for later medium history.","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/map.yaml","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 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"} diff --git a/state/memory.json b/state/memory.json index b85fe5e..29e073b 100644 --- a/state/memory.json +++ b/state/memory.json @@ -51,6 +51,7 @@ "TAA Gate 2A adds scene/history metadata with field identity and surface normal rejection. Grid stochastic surfaces must record Grid travel/normal even on dither-miss pixels so history accumulates the diegetic Grid surface instead of the solid behind it.", "TAA Gate 2B uses stable field ids and analytic object-motion reprojection for orbiting planets: current planet hit positions are offset from current center to previous center before projecting into history.", "TAA Gate 3A adds a separate current-frame temporal-control target: reactive strength, stochastic/composition coverage, reserved medium opacity, and reserved spare. The resolver reduces history for low-coverage reactive Grid samples; future volumetrics must extend this contract rather than pretending one opaque hit depth is enough.", + "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.", "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 8b37eb5..300607f 100644 --- a/state/scratch.md +++ b/state/scratch.md @@ -57,3 +57,6 @@ prototype integrated along the camera ray before surface composition. from field/normal metadata. Current channels are reactive strength, stochastic coverage, reserved medium opacity, and reserved spare; the resolve uses the first two to reduce history for low-coverage reactive Grid samples. +- Temporal Gate 3B: temporal control now has its own ping-pong history. Resolve + samples previous control at the reprojected UV and reduces history across + coverage or reserved medium-opacity discontinuities.