diff --git a/src/Aquarium.Engine/Render/D3D12Renderer.cs b/src/Aquarium.Engine/Render/D3D12Renderer.cs index 638f475..b98d916 100644 --- a/src/Aquarium.Engine/Render/D3D12Renderer.cs +++ b/src/Aquarium.Engine/Render/D3D12Renderer.cs @@ -2696,6 +2696,7 @@ public sealed class D3D12Renderer : IAquariumRenderer context.CommandList.SetGraphicsRootDescriptorTable(RootTemporalGaussians, frameResources.TemporalGaussianDescriptor.Gpu); context.CommandList.SetGraphicsRootDescriptorTable(RootCurrentReservoirGuide, frameResources.SceneReservoirGuideDescriptor.Gpu); context.CommandList.SetGraphicsRootDescriptorTable(RootHistoryReservoirGuide, frameResources.HistoryReservoirGuideDescriptor.Gpu); + context.CommandList.SetGraphicsRootDescriptorTable(RootBlueNoise, frameResources.BlueNoiseDescriptor.Gpu); context.CommandList.RSSetViewports(viewport); context.CommandList.RSSetScissorRects(scissorRect); @@ -4517,7 +4518,7 @@ public sealed class D3D12Renderer : IAquariumRenderer false, srcBlend: Blend.One, destBlend: Blend.One, - blendOp: BlendOperation.Max, + blendOp: BlendOperation.Add, srcBlendAlpha: Blend.One, destBlendAlpha: Blend.One, blendOpAlpha: BlendOperation.Min, diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl b/src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl index 1c1dcf2..4cc19ad 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl @@ -43,6 +43,7 @@ Texture2D bloomTexture6 : register(t35); Texture2D bloomTexture7 : register(t36); Texture2D currentReservoirGuideTexture : register(t26); Texture2D historyReservoirGuideTexture : register(t27); +Texture2D blueNoiseTexture : register(t28); SamplerState sourceSampler : register(s0); #include "D3D12Aces2.hlsl" @@ -271,6 +272,33 @@ float3 presentColor(float3 scene, float2 uv, float bloomScale) return aces(exposedScene + bloomContribution); } +float blueNoiseAt(float2 uv, uint salt) +{ + uint width; + uint height; + blueNoiseTexture.GetDimensions(width, height); + uint2 dimensions = max(uint2(width, height), uint2(1, 1)); + uint2 pixel = (uint2)floor(saturate(uv) * resolution); + uint2 offset = uint2((uint)frameIndex * 19u + salt * 53u, (uint)frameIndex * 31u + salt * 97u); + return blueNoiseTexture.Load(int3((pixel + offset) % dimensions, 0)); +} + +float3 ditherDisplay(float3 color, float2 uv) +{ + float noise = blueNoiseAt(uv, 11u) - 0.5; + return saturate(color + noise / 255.0); +} + +float3 bloomBrightPass(float3 exposedColor) +{ + float luma = luminance(exposedColor); + const float threshold = 1.0; + const float knee = 0.35; + float soft = saturate((luma - threshold + knee) / max(2.0 * knee, 0.0001)); + float contribution = max(luma - threshold, 0.0) + soft * soft * knee; + return exposedColor * saturate(contribution / max(luma, 0.0001)); +} + float3 clampBloomFirefly(float2 uv, float3 centerColor) { float2 texel = 1.0 / resolution; @@ -305,8 +333,8 @@ float3 clampBloomFirefly(float2 uv, float3 centerColor) float4 D3D12BloomPrefilterPS(VertexOut input) : SV_Target0 { - float3 color = sourceTexture.SampleLevel(sourceSampler, input.uv, 0.0).rgb; - return float4(clampBloomFirefly(input.uv, color) * max(exposure, 0.001), 1.0); + float3 color = sourceTexture.SampleLevel(sourceSampler, input.uv, 0.0).rgb * max(exposure, 0.001); + return float4(bloomBrightPass(clampBloomFirefly(input.uv, color)), 1.0); } float4 D3D12BloomDownsamplePS(VertexOut input) : SV_Target0 @@ -501,7 +529,7 @@ ResolveOut D3D12ResolvePS(VertexOut input) finalColor = float3(currentReservoirConfidence, saturate(reservoirSampleAge / MAX_HISTORY_AGE), currentReservoirDomainValidity); } ResolveOut output; - output.finalColor = float4(finalColor, 1.0); + output.finalColor = float4(ditherDisplay(finalColor, input.uv), 1.0); output.historyColor = float4(resolved, currentTravel); output.historyMetadata = currentMetadata; output.historyControl = float4(currentControl.xyz, combinedHistoryAge); diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12TubeField.hlsl b/src/Aquarium.Engine/Render/Shaders/D3D12TubeField.hlsl index db1593d..a3385f8 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12TubeField.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/D3D12TubeField.hlsl @@ -490,7 +490,8 @@ SceneOut D3D12TubeFieldPS(TubeFieldVertexOut input) float coverage = 1.0 - smoothstep(0.0, aa, sdf); float sampleX = lerp(input.tubeData.y, input.tubeData.z, closestT); float value = SampleCurve((uint)round(input.tubeData.x), sampleX); - float3 rampColor = TubeFieldRamp.SampleLevel(TubeFieldRampSampler, float2(saturate(value), 0.5), 0.0).rgb; + float materialValue = saturate(value); + float3 rampColor = TubeFieldRamp.SampleLevel(TubeFieldRampSampler, float2(materialValue, 0.5), 0.0).rgb; float3 ray = rayDirectionForPixel(baseSamplePx, jitterPixels, cameraPosition, cameraTarget); float3 forward; float3 right; @@ -508,9 +509,9 @@ SceneOut D3D12TubeFieldPS(TubeFieldVertexOut input) discard; } - bool exactTubeMaterial = input.material.x >= 15.5 && input.material.y >= 0.99; + bool exactTubeMaterial = input.tubeData.w < 0.0; float3 emissionColor = exactTubeMaterial ? float3(1.0, 0.035560537, 0.0) : rampColor; - float emission = exactTubeMaterial ? max(input.material.x, 0.0) : value * value * max(input.material.x, 0.0); + float emission = exactTubeMaterial ? max(input.material.x, 0.0) : materialValue * materialValue * max(input.material.x, 0.0); float3 color = emissionColor * emission * glowFacing * claimCoverage; float travel = lerp(input.segmentTravel.x, input.segmentTravel.y, closestT); diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 636d48c..cd40c7f 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -269,3 +269,5 @@ {"lesson":"The named D3D12 program-output texture is an external publication surface, so Fensalir must not leave it in CopyDest after publishing. D3D12Renderer now transitions the shared program texture back to Common after copying the completed backbuffer, letting OBS/EVE/native readers transition it for GPU-side reads without inheriting stale internal producer state. Fensalir build passed; Mimir's Eve relay reader now transitions the shared texture Common -> CopySource -> Common before readback.","timestamp":"2026-05-27T21:25:38+01:00","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","state/map.yaml"],"source":"OBS direct program texture source cut","topic":"program-output-shared-texture-state"} {"lesson":"Fensalir now owns the reusable blackbody ramp as a built-in local Texture2D field resource. The asset lives at Assets/Textures/Gradients/blackbody.png, is copied with engine texture assets, and AquariumBuiltInFieldResources exposes the stable resource key/path/declaration for clients so client render DSL does not depend on project-local absolute asset paths.","timestamp":"2026-05-28T00:00:00+01:00","files":["src/Aquarium.Engine.Contracts/Render/AquariumBuiltInFieldResources.cs","src/Aquarium.Engine/Assets/Textures/Gradients/blackbody.png","state/evidence.jsonl"],"source":"Mimir spectrum dashboard ramp promotion","topic":"built-in-blackbody-ramp-resource"} {"lesson":"TubeField proxy geometry no longer owns final scene visibility by last-writer render-target overwrite. The TubeField render pipeline now blends generated tube evidence as a pixel-local candidate resolve: HDR color keeps the strongest candidate, travel keeps the nearest candidate, and control/reservoir-guide lanes keep strongest coverage metadata. This removes the rolling spectrum dashboard's destructive last-spline-wins holes while leaving dense-history composition and true multi-candidate reservoir storage as later cuts.","timestamp":"2026-05-28T14:39:05+01:00","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","state/evidence.jsonl"],"source":"TubeField spectrum dashboard visibility cut","topic":"tubefield-candidate-resolve-blend"} +{"lesson":"The Sonic-Ether-style bloom pyramid must start from bright-pass energy, not the whole exposed scene. Feeding low-level TubeField tails into every bloom octave created dark-region haze/banding that looked like black fog. D3D12Post now applies a soft bright threshold before bloom downsampling and adds blue-noise display dither after ACES. A depth-write experiment for TubeField was rejected because conservative proxy envelopes wrote incorrect depths and cut holes in valid tube evidence; TubeField remains a depthless candidate envelope until a real multi-candidate reservoir stores color and travel together.","timestamp":"2026-05-28T14:49:39+01:00","files":["src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","src/Aquarium.Engine/Render/D3D12Renderer.cs","state/evidence.jsonl"],"source":"TubeField bloom/fog visual QA","topic":"bloom-brightpass-display-dither"} +{"lesson":"TubeField blackbody ramp sampling was correct on X, but the old single-tube proof material branch treated high emission scale plus material.y near 1 as an exact red/orange proof tube and bypassed the ramp. Spectrum TubeFields now sample the ramp from saturated normalized amplitude on X and use amplitude squared for emission intensity; the exact proof branch is only reachable through an explicit negative tubeData.w sentinel. The high-end blue is expected to survive mostly as a cool fringe after ACES/SE bloom because the blackbody asset's right edge is pale blue and peak emission tonemaps toward white.","timestamp":"2026-05-28T15:06:53+01:00","files":["src/Aquarium.Engine/Render/Shaders/D3D12TubeField.hlsl","state/evidence.jsonl"],"source":"Mimir spectrum dashboard blackbody ramp QA","topic":"tubefield-blackbody-ramp-material"}