Separate density slice debug from transport

This commit is contained in:
Meta Vens 2026-05-09 02:50:43 +01:00
commit 217449a33a
5 changed files with 36 additions and 7 deletions

View file

@ -230,11 +230,12 @@ packs stable field instances into a structured buffer shared with HLSL. A
half-resolution medium pass writes a 4x4 frustum slice atlas into diagnostic and
transport textures before the scene pass. Each atlas texel reconstructs a world
position and samples registered medium density there; resolve integrates those
stored cells front-to-back for density, transmittance, and source diagnostics.
Modes `9`, `10`, and `11` show medium density, transmittance, and source
respectively. Final composition uses `surface * transmittance + in-scattering`,
gated by the persisted Medium Composite control. The default is `0`, so the pass
can be inspected without changing the presented frame until the medium is tuned.
stored cells front-to-back for transport diagnostics. Mode `9` is a separate
world-anchored density slice at Grid altitude, while modes `10` and `11` show
transport transmittance and source respectively. Final composition uses `surface
* transmittance + in-scattering`, gated by the persisted Medium Composite
control. The default is `0`, so the pass can be inspected without changing the
presented frame until the medium is tuned.
The running window also has a Direct2D debug panel toggled with `F2`. It follows
the CultLib code-first composition style rather than an immediate-mode toolkit:

View file

@ -41,7 +41,7 @@ public sealed class D3D11Renderer : IDisposable
new(6, "Field Identity"),
new(7, "Bloom"),
new(8, "Exposed Luminance"),
new(9, "Medium Density"),
new(9, "Density Slice"),
new(10, "Medium Transmittance"),
new(11, "Medium Source"),
];

View file

@ -1473,6 +1473,27 @@ float3 debugFieldIdColor(float fieldId)
return float3(1.0, 0.0, 1.0);
}
float mediumDensitySliceDebug(float3 rayDirection)
{
float sliceZ = 0.0;
float denominator = rayDirection.z;
if (abs(denominator) < 0.0001)
{
return 0.0;
}
float travel = (sliceZ - cameraPosition.z) / denominator;
if (travel <= 0.0 || travel >= farDistance)
{
return 0.0;
}
float3 p = cameraPosition + rayDirection * travel;
float gridMask = 1.0 - smoothstep(gridRadius * 0.98, gridRadius * 1.04, length(p.xy - gridCenter));
float3 scattering;
return registeredMediumDensity(p, scattering) * gridMask;
}
struct SceneOut
{
float4 colorTravel : SV_Target0;
@ -1816,7 +1837,9 @@ ResolveOut AquariumResolvePS(VertexOut input)
}
else if (renderDebugMode >= 8.5 && renderDebugMode < 9.5)
{
finalColor = lerp(float3(0.01, 0.025, 0.04), float3(0.28, 0.78, 1.0), currentMediumDensity);
float3 debugRay = rayDirectionForPixel(pixel, jitterPixels, cameraPosition, gridCenter);
float densitySlice = mediumDensitySliceDebug(debugRay);
finalColor = lerp(float3(0.01, 0.025, 0.04), float3(0.28, 0.78, 1.0), densitySlice);
}
else if (renderDebugMode >= 9.5 && renderDebugMode < 10.5)
{

View file

@ -50,3 +50,4 @@
{"area":"renderer/volumetrics","lesson":"Registered medium diagnostics now come from a separate half-resolution medium pass instead of being integrated inside the scene shader. The pass samples the field instance buffer, writes density/transmittance/source into a medium texture, and scene/resolve stages sample that texture for debug/control. Final composition remains unchanged until the compositor is explicit.","files":["src/Aquarium.Engine/Render/D3D11Renderer.cs","src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl","src/Aquarium.Engine.Contracts/GraphicsSettings.cs","docs/sdf-field-renderer-plan.md","docs/hlsl-renderer.md","state/map.yaml","state/memory.json","state/scratch.md"],"verification":["dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4","direct headless startup with --render-debug 11 compiled shaders and loaded persisted debug mode 11"],"ts":"2026-05-09"}
{"area":"renderer/volumetrics","lesson":"Medium composition is now explicit and gated: the half-resolution medium pass writes diagnostic and transport textures, and resolve can composite surface * transmittance + in-scattering through a persisted Medium Composite setting. The default remains zero so final presentation does not change until the medium is intentionally enabled and tuned.","files":["src/Aquarium.Engine.Contracts/GraphicsSettings.cs","src/Aquarium.Engine.Live/State/AquariumGraphicsSettingsState.cs","src/Aquarium.Engine.Live/State/AquariumCultStateStore.cs","src/Aquarium.Engine/Render/D3D11Renderer.cs","src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl","docs/cult-runtime-surface.md","docs/hlsl-renderer.md","docs/sdf-field-renderer-plan.md","state/map.yaml","state/memory.json","state/scratch.md"],"verification":["dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4","direct headless startup in final mode with default Medium Composite 0"],"ts":"2026-05-09"}
{"area":"renderer/volumetrics","lesson":"The first medium density view was too screen-ray dependent: it stored a completed half-res ray integral, so debug texture detail read as view-space soup. The pass now stores a 4x4 frustum slice atlas where each texel reconstructs a world point and evaluates field-local density; resolve integrates those stored cells front-to-back. Erosion noise is stationary in field-local space.","files":["src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl","docs/hlsl-renderer.md","docs/sdf-field-renderer-plan.md","state/memory.json","state/scratch.md"],"verification":["dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4"],"ts":"2026-05-09"}
{"area":"renderer/volumetrics","lesson":"Do not label a view-dependent transport projection as Medium Density. Mode 9 now evaluates the registered medium field on a world-anchored Grid-altitude slice, while modes 10 and 11 remain frustum transport diagnostics. Density debugging and transport debugging are different tools.","files":["src/Aquarium.Engine/Render/D3D11Renderer.cs","src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl","docs/hlsl-renderer.md","state/scratch.md"],"verification":["dotnet build Aquarium.Engine.slnx"],"ts":"2026-05-09"}

View file

@ -148,6 +148,10 @@ prototype integrated along the camera ray before surface composition.
reconstructs a world point and evaluates field-local density there; resolve
integrates the stored cells front-to-back. Removed the time term from erosion
noise so the texture itself is stationary under inspection.
- Follow-up correction: mode 9 is no longer the frustum atlas mean. It is a
world-anchored density slice at Grid altitude (`z = 0`) so density-field
texture can be inspected without confusing it with view-dependent transport
slices. Modes 10/11 remain transport diagnostics.
- Debug UI control grammar now includes named option rows. Render Debug uses an
option/dropdown selector instead of a numeric slider so the expanding debug
mode list remains legible.