Add propagated light debug view

This commit is contained in:
Meta Vens 2026-05-10 15:43:03 +01:00
commit dc7195a2a0
10 changed files with 57 additions and 11 deletions

View file

@ -27,7 +27,8 @@ temporary visual reference until the old backend is deleted.
transport, and light-injection render targets from the field instance buffer,
then runs a propagation pass into the light texture consumed by fog integration
and solid diffuse shading. Render debug mode `11` displays D3D12 froxel
density, matching the renderer path rather than a temporary bring-up view.
density and mode `12` displays propagated froxel light, matching the renderer
path rather than a temporary bring-up view.
- The D3D12 scene pass now renders Self, planets, medium transport, and the
first transparent candidate event through the D3D12 frame graph. Grid line
transparency is no longer baked into the medium froxel atlas; the scene

View file

@ -289,7 +289,8 @@ reconstructs a world position, samples registered medium density, and injects
light from `FieldFlags.Emitter` surfaces using finite solid angle and cheap
path transmittance. Mode `9` previews direct registered-medium density at the
selected ray step, mode `10` previews direct ray transmittance to that step, and
mode `11` shows integrated froxel density. Final composition uses density,
mode `11` shows integrated froxel density. Mode `12` shows propagated froxel
light. Final composition uses density,
transmittance, and propagated light front-to-back; the persisted Medium
Composite control still scales the visible medium while the light contract
remains renderer-owned.

View file

@ -9,7 +9,7 @@ public readonly record struct GraphicsSettings(
int MediumDebugStep)
{
public const int MinRenderDebugMode = 0;
public const int MaxRenderDebugMode = 11;
public const int MaxRenderDebugMode = 12;
public const float MinSceneExposure = 0.02f;
public const float MaxSceneExposure = 1.2f;
public const float MinBloomIntensity = 0.0f;

View file

@ -47,6 +47,7 @@ public sealed class D3D11Renderer : IAquariumRenderer
new(9, "Medium Ray Density"),
new(10, "Medium Ray Transmittance"),
new(11, "Froxel Density"),
new(12, "Froxel Light"),
];
private const float SunRadius = 1.12f;

View file

@ -60,6 +60,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
new(9, "Medium Ray Density"),
new(10, "Medium Ray Transmittance"),
new(11, "Froxel Density"),
new(12, "Froxel Light"),
];
private readonly IDXGIFactory4 factory;
@ -81,6 +82,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
private ID3D12PipelineState? mediumVolumePipelineState;
private ID3D12PipelineState? mediumLightPropagationPipelineState;
private ID3D12PipelineState? mediumDensityDebugPipelineState;
private ID3D12PipelineState? mediumLightDebugPipelineState;
private ID3D12PipelineState? bloomPrefilterPipelineState;
private ID3D12PipelineState? bloomDownsamplePipelineState;
private ID3D12PipelineState? bloomBlurHorizontalPipelineState;
@ -470,6 +472,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
&& mediumVolumePipelineState is not null
&& mediumLightPropagationPipelineState is not null
&& mediumDensityDebugPipelineState is not null
&& mediumLightDebugPipelineState is not null
&& bloomPrefilterPipelineState is not null
&& bloomDownsamplePipelineState is not null
&& bloomBlurHorizontalPipelineState is not null
@ -645,6 +648,8 @@ public sealed class D3D12Renderer : IAquariumRenderer
mediumLightPropagation.Name = "Aquarium D3D12 Medium Light Propagation Pipeline";
var mediumDensityDebug = CreateMediumDensityDebugPipelineState(paths.Smoke);
mediumDensityDebug.Name = "Aquarium D3D12 Medium Density Debug Pipeline";
var mediumLightDebug = CreateMediumLightDebugPipelineState(paths.Smoke);
mediumLightDebug.Name = "Aquarium D3D12 Medium Light Debug Pipeline";
var bloomPrefilter = CreateBloomPrefilterPipelineState(paths.Post);
bloomPrefilter.Name = "Aquarium D3D12 Bloom Prefilter Pipeline";
var bloomDownsample = CreateBloomDownsamplePipelineState(paths.Post);
@ -663,6 +668,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
mediumVolume,
mediumLightPropagation,
mediumDensityDebug,
mediumLightDebug,
bloomPrefilter,
bloomDownsample,
bloomBlurHorizontal,
@ -1035,17 +1041,32 @@ public sealed class D3D12Renderer : IAquariumRenderer
try
{
var showMediumDensity = RenderDebugMode == 11;
var showMediumLight = RenderDebugMode == 12;
var historyReadIndex = temporalFrameIndex & 1;
var historyWriteIndex = 1 - historyReadIndex;
if (showMediumDensity)
if (showMediumDensity || showMediumLight)
{
mediumVolumeRenderTarget.Transition(context.CommandList, ResourceStates.PixelShaderResource);
var sourceDescriptor = showMediumDensity
? frameResources.MediumTargetsDescriptor
: frameResources.MediumLightDescriptor;
var pipelineState = showMediumDensity
? mediumDensityDebugPipelineState!
: mediumLightDebugPipelineState!;
if (showMediumDensity)
{
mediumVolumeRenderTarget.Transition(context.CommandList, ResourceStates.PixelShaderResource);
}
else
{
mediumLightRenderTarget.Transition(context.CommandList, ResourceStates.PixelShaderResource);
}
context.BackBuffer.Transition(context.CommandList, ResourceStates.RenderTarget);
context.CommandList.SetDescriptorHeaps(frameResources.TransientShaderDescriptors.Heap);
context.CommandList.SetPipelineState(mediumDensityDebugPipelineState!);
context.CommandList.SetPipelineState(pipelineState);
context.CommandList.SetGraphicsRootSignature(fullscreenRootSignature);
context.CommandList.SetGraphicsRootDescriptorTable(1, frameResources.MediumTargetsDescriptor.Gpu);
context.CommandList.SetGraphicsRootDescriptorTable(1, sourceDescriptor.Gpu);
context.CommandList.RSSetViewports(viewport);
context.CommandList.RSSetScissorRects(scissorRect);
context.CommandList.OMSetRenderTargets(context.RenderTargetView, null);
@ -1802,6 +1823,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
mediumVolumePipelineState!,
mediumLightPropagationPipelineState!,
mediumDensityDebugPipelineState!,
mediumLightDebugPipelineState!,
bloomPrefilterPipelineState!,
bloomDownsamplePipelineState!,
bloomBlurHorizontalPipelineState!,
@ -1818,6 +1840,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
mediumVolumePipelineState = pipelines.MediumVolume;
mediumLightPropagationPipelineState = pipelines.MediumLightPropagation;
mediumDensityDebugPipelineState = pipelines.MediumDensityDebug;
mediumLightDebugPipelineState = pipelines.MediumLightDebug;
bloomPrefilterPipelineState = pipelines.BloomPrefilter;
bloomDownsamplePipelineState = pipelines.BloomDownsample;
bloomBlurHorizontalPipelineState = pipelines.BloomBlurHorizontal;
@ -1834,6 +1857,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
mediumVolumePipelineState = null;
mediumLightPropagationPipelineState = null;
mediumDensityDebugPipelineState = null;
mediumLightDebugPipelineState = null;
bloomPrefilterPipelineState = null;
bloomDownsamplePipelineState = null;
bloomBlurHorizontalPipelineState = null;
@ -2086,6 +2110,11 @@ public sealed class D3D12Renderer : IAquariumRenderer
return CreateFullscreenPipelineState(path, "FullscreenTriangleVS", "D3D12MediumDensityDebugPS", Format.B8G8R8A8_UNorm);
}
private ID3D12PipelineState CreateMediumLightDebugPipelineState(string path)
{
return CreateFullscreenPipelineState(path, "FullscreenTriangleVS", "D3D12MediumLightDebugPS", Format.B8G8R8A8_UNorm);
}
private ID3D12PipelineState CreateBloomPrefilterPipelineState(string path)
{
return CreateFullscreenPipelineState(path, "FullscreenTriangleVS", "D3D12BloomPrefilterPS", SceneHdrFormat);
@ -2417,6 +2446,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
ID3D12PipelineState MediumVolume,
ID3D12PipelineState MediumLightPropagation,
ID3D12PipelineState MediumDensityDebug,
ID3D12PipelineState MediumLightDebug,
ID3D12PipelineState BloomPrefilter,
ID3D12PipelineState BloomDownsample,
ID3D12PipelineState BloomBlurHorizontal,
@ -2430,6 +2460,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
BloomBlurHorizontal.Dispose();
BloomDownsample.Dispose();
BloomPrefilter.Dispose();
MediumLightDebug.Dispose();
MediumDensityDebug.Dispose();
MediumLightPropagation.Dispose();
MediumVolume.Dispose();

View file

@ -99,7 +99,7 @@ internal sealed class DirectWriteOverlay : IDisposable
if (renderDebugMode > 0)
{
renderTarget.DrawText(
$"render debug {renderDebugMode} F1 cycle 0-9 select",
$"render debug {renderDebugMode} F1 cycle debug panel selects",
smallFormat,
RectFromEdges(18, 56, Math.Min(width - 18, 420), 80),
quietTextBrush,

View file

@ -64,3 +64,13 @@ float4 D3D12MediumDensityDebugPS(VertexOut input) : SV_Target0
fog *= lerp(0.45, 1.0, transmittance);
return float4(max(clear, fog), 1.0);
}
float4 D3D12MediumLightDebugPS(VertexOut input) : SV_Target0
{
float3 light = max(sourceTexture.SampleLevel(sourceSampler, input.uv, 0.0).rgb, 0.0);
float luminance = dot(light, float3(0.2126, 0.7152, 0.0722));
float exposure = 1.0 - exp(-luminance * 0.85);
float3 chroma = light / max(luminance, 0.0001);
float3 color = saturate(chroma * exposure);
return float4(max(float3(0.004, 0.008, 0.012), color), 1.0);
}

View file

@ -132,3 +132,4 @@
{"timestamp":"2026-05-10T08:27:10+01:00","topic":"medium-temporal-ghosting","lesson":"D3D12 medium color history caused strong fog ghosting after emissive injection: medium-classified pixels used the main surface-history lane and the medium lane also blended previous full-frame color. Final resolve now excludes medium pixels from surface history and keeps mediumHistoryWeight at zero. Medium packet age/travel/density may remain diagnostic, but fog color history needs a real light-volume/medium reprojection contract before it can affect final presentation.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","state/memory.json","state/scratch.md"]}
{"timestamp":"2026-05-10T08:38:10+01:00","topic":"medium-radiance-reprojection","lesson":"D3D12 medium radiance now has a separate temporal lane instead of borrowing final scene history. Scene writes `sceneMediumColor`; resolve subtracts current medium from scene color before surface history, reprojects medium packet travel to sample `historyMediumColor`, validates by medium travel/opacity/density, and composites resolved surface plus resolved medium plus events. Cold shader compilation may exceed the default 30s headless watchdog, but warm verification passes.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","state/memory.json","state/scratch.md"]}
{"timestamp":"2026-05-10T15:35:00+01:00","topic":"medium-light-propagation","lesson":"D3D12 medium lighting now has separate injection and propagated-light froxel targets. The medium pass writes density, transport, and raw emitter injection from `FieldFlags.Emitter`; a propagation pass samples neighboring froxels with density attenuation; scene fog integration and solid diffuse shading consume the propagated light field. Glossy cursor specular still needs a future directional/probe source rather than pretending RGBA froxel irradiance is enough for metal reflections.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Medium.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","docs/hlsl-renderer.md","docs/d3d12-migration.md","state/memory.json","state/scratch.md"]}
{"timestamp":"2026-05-10T15:45:00+01:00","topic":"propagated-light-debug","lesson":"Renderer-owned lighting needs its own inspection surface. D3D12 debug mode 12 now shows the propagated froxel light target directly, separate from froxel density, so lighting failures can be diagnosed as injection, propagation, or integration problems instead of guessed from the final composite.","files":["src/Aquarium.Engine.Contracts/GraphicsSettings.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Smoke.hlsl","src/Aquarium.Engine/Render/DirectWriteOverlay.cs","docs/hlsl-renderer.md","docs/d3d12-migration.md","state/memory.json","state/scratch.md"]}

View file

@ -84,7 +84,7 @@
"Grid temporal control coverage is the line/support signal. Do not mark the whole low-support Grid surface reactive; that turns debug control mode red everywhere and reintroduces stale history-murder logic.",
"Temporal control background coverage must be zero. Opaque hits can write coverage 1, and Grid hits write line/support coverage; empty background must not appear as stable covered history in mode 5.",
"Projection jitter is currently scaled to zero. If Self or planet surfaces visibly judder, the resolve is not hiding jitter and the correct live choice is no jitter until opaque and Grid paths both prove stable.",
"Temporal debug views are live keys: F1 cycles, 0 final, 1 raw current scene, 2 reprojected history, 3 history age, 4 history weight, 5 current temporal control, 6 current field identity. Use these before guessing whether TAA is sampling, validating, or presenting the wrong signal.",
"Temporal/debug views are live keys: F1 cycles; 0 final, 1 raw current scene, 2 reprojected history, 3 history age, 4 history weight, 5 current temporal control, 6 current field identity, 7 bloom, 8 exposed luminance, 9 medium ray density, 10 medium ray transmittance, 11 froxel density, 12 propagated froxel light. Use these before guessing whether TAA, medium, or lighting is sampling, validating, or presenting the wrong signal.",
"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

@ -119,8 +119,9 @@ reusing field identity/travel/control.
density attenuation, into the propagated light target. Scene medium
integration now uses density/transmittance plus propagated light instead of
hard-baked transport color, and solid diffuse shading samples the same froxel
light field. Cursor brass specular still uses direct emitter loops until the
renderer owns directional/probe lighting for glossy surfaces.
light field. Debug mode `12` visualizes the propagated froxel light. Cursor
brass specular still uses direct emitter loops until the renderer owns
directional/probe lighting for glossy surfaces.
- Cursor locator SDF: `AquariumFrame` carries the mouse cursor projected onto
the Grid XY plane. D3D12 bins a cursor primitive into the existing view-froxel
solid table and traces it as an asymmetric teardrop lobe: local `z = -1`