Add native debug UI controls

This commit is contained in:
Meta Vens 2026-05-09 01:04:11 +01:00
commit 37a3f46499
12 changed files with 579 additions and 24 deletions

View file

@ -9,8 +9,8 @@ Aquarium now has a first shader-owned image path.
- The renderer draws one fullscreen triangle.
- The pixel shader raymarches the Grid heightfield, Self sun, and orbiting
planets.
- C# feeds only frame constants: resolution, time, Grid radius, and camera
position.
- C# feeds only explicit frame constants: resolution, time, Grid radius, camera
position, presentation controls, temporal state, and debug mode.
- CultMath is referenced as the CPU-side math grammar. Vortice math stays at the
graphics API membrane.
@ -225,6 +225,13 @@ field identity, `7` is bloom contribution, and `8` is exposed luminance. The
startup mode can still be set with `--render-debug` or
`AQUARIUM_RENDER_DEBUG_MODE`.
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:
controls are retained rows bound to `Func<T>`/`Action<T>` pairs. The first panel
drives render debug mode, exposure, bloom intensity, and bloom veil. Those HDR
controls feed the shader constant buffer directly; they are not cosmetic labels
painted over hardcoded renderer state.
It deliberately does not pretend to solve general non-rigid field velocity,
volumetric history, or history resurrection yet.
@ -237,6 +244,13 @@ format drama. This path is for debug UI, terminal text, inspectors, and future
CultUI overlay surfaces. Diegetic labels that live in the scene still belong in
the renderer as MSDF/SDF billboards.
The debug controls live in `Render/Ui/DebugUi.cs`. The intended grammar is a
native version of CultLib's generator API: panels, sections, sliders, toggles,
and buttons are declared in code and bound to engine state with explicit read
and write delegates. The visual language is flat and compact: dark panel,
slab rows, thin dividers, orange accent, and pale values. It is debug UI, but it
does not have permission to be ugly by default.
The overlay owns a private DirectWrite font collection built from bundled Google
Fonts files in `Assets/Fonts`: Montserrat for thin small-cap display text and
Ubuntu Sans for body/debug copy. The runtime does not depend on those fonts

View file

@ -6,6 +6,8 @@ public sealed class InputState
{
private readonly HashSet<KeyCode> downKeys = [];
private readonly HashSet<KeyCode> pressedKeys = [];
private readonly HashSet<MouseButton> downMouseButtons = [];
private readonly HashSet<MouseButton> pressedMouseButtons = [];
public Vector2 MousePosition { get; private set; }
@ -13,19 +15,26 @@ public sealed class InputState
public float WheelDelta { get; private set; }
public bool MiddleMouseDown { get; private set; }
public bool LeftMouseDown => IsMouseDown(MouseButton.Left);
public bool RightMouseDown { get; private set; }
public bool MiddleMouseDown => IsMouseDown(MouseButton.Middle);
public bool RightMouseDown => IsMouseDown(MouseButton.Right);
public bool IsKeyDown(KeyCode key) => downKeys.Contains(key);
public bool IsKeyPressed(KeyCode key) => pressedKeys.Contains(key);
public bool IsMouseDown(MouseButton button) => downMouseButtons.Contains(button);
public bool IsMousePressed(MouseButton button) => pressedMouseButtons.Contains(button);
public void BeginFrame()
{
MouseDelta = Vector2.Zero;
WheelDelta = 0.0f;
pressedKeys.Clear();
pressedMouseButtons.Clear();
}
public void SetMousePosition(Vector2 position)
@ -41,14 +50,18 @@ public sealed class InputState
public void SetMouseButton(MouseButton button, bool isDown)
{
switch (button)
if (isDown)
{
case MouseButton.Middle:
MiddleMouseDown = isDown;
break;
case MouseButton.Right:
RightMouseDown = isDown;
break;
if (!downMouseButtons.Contains(button))
{
pressedMouseButtons.Add(button);
}
downMouseButtons.Add(button);
}
else
{
downMouseButtons.Remove(button);
}
}
@ -72,6 +85,7 @@ public sealed class InputState
public enum MouseButton
{
Left,
Middle,
Right,
}
@ -92,4 +106,5 @@ public enum KeyCode
Digit7,
Digit8,
RenderDebugCycle,
DebugUiToggle,
}

View file

@ -43,6 +43,7 @@ public static class AquariumHost
var deltaSeconds = (float)(now - lastFrame).TotalSeconds;
lastFrame = now;
renderer.UpdateDebugUi(input);
runtimeLoader.Update(deltaSeconds, input);
ApplyRendererDebugInput(renderer, input);
renderer.Render(runtimeLoader.Runtime.Frame);

View file

@ -12,6 +12,8 @@ public sealed class Win32Window : IDisposable
private const uint WM_KEYDOWN = 0x0100;
private const uint WM_KEYUP = 0x0101;
private const uint WM_MOUSEMOVE = 0x0200;
private const uint WM_LBUTTONDOWN = 0x0201;
private const uint WM_LBUTTONUP = 0x0202;
private const uint WM_RBUTTONDOWN = 0x0204;
private const uint WM_RBUTTONUP = 0x0205;
private const uint WM_MBUTTONDOWN = 0x0207;
@ -58,6 +60,7 @@ public sealed class Win32Window : IDisposable
private const int VK_7 = 0x37;
private const int VK_8 = 0x38;
private const int VK_F1 = 0x70;
private const int VK_F2 = 0x71;
private const int WHEEL_DELTA = 120;
private readonly WndProc windowProcedure;
@ -125,6 +128,14 @@ public sealed class Win32Window : IDisposable
case WM_MOUSEWHEEL:
input.AddWheelDelta(GetSignedHighWord(wParam) / (float)WHEEL_DELTA);
return IntPtr.Zero;
case WM_LBUTTONDOWN:
input.SetMouseButton(MouseButton.Left, true);
SetCapture(handle);
return IntPtr.Zero;
case WM_LBUTTONUP:
input.SetMouseButton(MouseButton.Left, false);
ReleaseCapture();
return IntPtr.Zero;
case WM_MBUTTONDOWN:
input.SetMouseButton(MouseButton.Middle, true);
SetCapture(handle);
@ -653,6 +664,9 @@ public sealed class Win32Window : IDisposable
case VK_F1:
input.SetKey(KeyCode.RenderDebugCycle, isDown);
break;
case VK_F2:
input.SetKey(KeyCode.DebugUiToggle, isDown);
break;
}
}

View file

@ -3,6 +3,8 @@ using Vortice.D3DCompiler;
using Vortice.Direct3D11;
using Vortice.DXGI;
using Vortice.Mathematics;
using Aquarium.Engine.Input;
using Aquarium.Engine.Render.Ui;
using CultMath;
using System.Diagnostics;
using System.Numerics;
@ -17,7 +19,9 @@ public sealed class D3D11Renderer : IDisposable
private static readonly TimeSpan ShaderReloadPollInterval = TimeSpan.FromMilliseconds(250);
private static readonly TimeSpan ShaderReloadWriteSettleTime = TimeSpan.FromMilliseconds(150);
private const float TemporalJitterScale = 0.0f;
private const float SceneExposure = 0.16f;
private const float DefaultSceneExposure = 0.16f;
private const float DefaultBloomIntensity = 0.072f;
private const float DefaultBloomVeilIntensity = 0.014f;
private const int GridHeightTextureSize = 128;
private const int DitherTextureSize = 512;
private const int BloomLevelCount = 3;
@ -36,6 +40,7 @@ public sealed class D3D11Renderer : IDisposable
private readonly ID3D11DeviceContext context;
private readonly ID3D11RenderTargetView renderTargetView;
private readonly DirectWriteOverlay overlay;
private readonly DebugUi debugUi;
private readonly ID3D11Texture2D gridHeightTexture;
private readonly ID3D11RenderTargetView gridHeightRenderTargetView;
private readonly ID3D11ShaderResourceView gridHeightShaderResourceView;
@ -143,6 +148,7 @@ public sealed class D3D11Renderer : IDisposable
renderTargetView = device.CreateRenderTargetView(backBuffer);
using var backBufferSurface = swapChain.GetBuffer<IDXGISurface>(0);
overlay = new DirectWriteOverlay(backBufferSurface, width, height);
debugUi = CreateDebugUi();
startupProgress?.Invoke("Compiling aquarium shaders");
var initialShaders = CompileShaderSet(this.shaderPath);
@ -223,7 +229,7 @@ public sealed class D3D11Renderer : IDisposable
MaxLOD = float.MaxValue,
});
frameConstantBuffer = device.CreateBuffer(
96,
112,
BindFlags.ConstantBuffer,
ResourceUsage.Default,
CpuAccessFlags.None,
@ -276,7 +282,10 @@ public sealed class D3D11Renderer : IDisposable
(float2)jitter,
(float2)previousJitter,
RenderDebugMode,
SceneExposure);
SceneExposure,
BloomIntensity,
BloomVeilIntensity,
(float2)Vector2.Zero);
BuildFroxelPrimitiveTable(frame);
context.UpdateSubresource(in constants, frameConstantBuffer);
@ -286,7 +295,7 @@ public sealed class D3D11Renderer : IDisposable
RenderBloom();
ResolveTemporal();
context.Flush();
overlay.Render(frame, RenderDebugMode);
overlay.Render(frame, RenderDebugMode, debugUi);
swapChain.Present(1, PresentFlags.None);
previousCameraPosition = frame.CameraPosition;
@ -298,11 +307,43 @@ public sealed class D3D11Renderer : IDisposable
public int RenderDebugMode { get; set; }
public float SceneExposure { get; set; } = DefaultSceneExposure;
public float BloomIntensity { get; set; } = DefaultBloomIntensity;
public float BloomVeilIntensity { get; set; } = DefaultBloomVeilIntensity;
public bool DebugUiVisible
{
get => debugUi.IsVisible;
set => debugUi.IsVisible = value;
}
public void UpdateDebugUi(InputState input)
{
debugUi.Update(input);
}
public void CycleRenderDebugMode()
{
RenderDebugMode = (RenderDebugMode + 1) % 9;
}
private DebugUi CreateDebugUi()
{
return new DebugUi("Aetheric Field Tester")
.Panel(panel => panel
.Section("View")
.Slider("Render Debug", () => RenderDebugMode, value => RenderDebugMode = Math.Clamp(value, 0, 8), 0, 8)
.Button("Reset View", () => RenderDebugMode = 0)
.Section("HDR")
.Slider("Exposure", () => SceneExposure, value => SceneExposure = Math.Clamp(value, 0.02f, 1.2f), 0.02f, 1.2f, "0.###")
.Slider("Bloom Intensity", () => BloomIntensity, value => BloomIntensity = Math.Clamp(value, 0.0f, 0.24f), 0.0f, 0.24f, "0.###")
.Slider("Bloom Veil", () => BloomVeilIntensity, value => BloomVeilIntensity = Math.Clamp(value, 0.0f, 0.08f), 0.0f, 0.08f, "0.###")
.Section("Overlay")
.Toggle("Panel Visible", () => DebugUiVisible, value => DebugUiVisible = value));
}
public void Dispose()
{
overlay.Dispose();
@ -842,7 +883,10 @@ public sealed class D3D11Renderer : IDisposable
float2 JitterPixels,
float2 PreviousJitterPixels,
float RenderDebugMode,
float Exposure);
float Exposure,
float BloomIntensity,
float BloomVeilIntensity,
float2 Padding);
private readonly record struct FroxelCell(int X, int Y, int Z);

View file

@ -3,6 +3,7 @@ using Vortice.Direct2D1;
using Vortice.DirectWrite;
using Vortice.DXGI;
using Vortice.Mathematics;
using Aquarium.Engine.Render.Ui;
using D2DFactoryType = Vortice.Direct2D1.FactoryType;
using DWriteFactoryType = Vortice.DirectWrite.FactoryType;
@ -17,6 +18,11 @@ internal sealed class DirectWriteOverlay : IDisposable
private readonly ID2D1RenderTarget renderTarget;
private readonly ID2D1SolidColorBrush primaryTextBrush;
private readonly ID2D1SolidColorBrush quietTextBrush;
private readonly ID2D1SolidColorBrush panelBrush;
private readonly ID2D1SolidColorBrush rowBrush;
private readonly ID2D1SolidColorBrush outlineBrush;
private readonly ID2D1SolidColorBrush accentBrush;
private readonly ID2D1SolidColorBrush dimAccentBrush;
private readonly IDWriteTextFormat titleFormat;
private readonly IDWriteTextFormat smallFormat;
private readonly int width;
@ -55,11 +61,16 @@ internal sealed class DirectWriteOverlay : IDisposable
primaryTextBrush = renderTarget.CreateSolidColorBrush(new Color4(0.88f, 0.96f, 1.0f, 0.92f));
quietTextBrush = renderTarget.CreateSolidColorBrush(new Color4(0.54f, 0.68f, 0.72f, 0.72f));
panelBrush = renderTarget.CreateSolidColorBrush(new Color4(0.018f, 0.022f, 0.032f, 0.96f));
rowBrush = renderTarget.CreateSolidColorBrush(new Color4(0.085f, 0.084f, 0.12f, 0.96f));
outlineBrush = renderTarget.CreateSolidColorBrush(new Color4(0.28f, 0.34f, 0.36f, 0.72f));
accentBrush = renderTarget.CreateSolidColorBrush(new Color4(1.0f, 0.38f, 0.055f, 0.96f));
dimAccentBrush = renderTarget.CreateSolidColorBrush(new Color4(0.20f, 0.20f, 0.22f, 0.95f));
titleFormat = CreateTextFormat("Montserrat", 18.0f, FontWeight.Thin);
smallFormat = CreateTextFormat("Ubuntu Sans", 11.0f, FontWeight.Regular);
}
public void Render(AquariumFrame frame, int renderDebugMode)
public void Render(AquariumFrame frame, int renderDebugMode, DebugUi? debugUi)
{
renderTarget.BeginDraw();
DrawHeader(
@ -88,6 +99,17 @@ internal sealed class DirectWriteOverlay : IDisposable
new Rect(18, Math.Max(64, height - 36), Math.Min(width - 18, 420), height - 12),
quietTextBrush,
DrawTextOptions.Clip);
debugUi?.Draw(
renderTarget,
titleFormat,
smallFormat,
panelBrush,
rowBrush,
outlineBrush,
primaryTextBrush,
quietTextBrush,
accentBrush,
dimAccentBrush);
renderTarget.EndDraw();
}
@ -97,6 +119,11 @@ internal sealed class DirectWriteOverlay : IDisposable
titleFormat.Dispose();
smallCapsTypography.Dispose();
fontCollection.Dispose();
dimAccentBrush.Dispose();
accentBrush.Dispose();
outlineBrush.Dispose();
rowBrush.Dispose();
panelBrush.Dispose();
quietTextBrush.Dispose();
primaryTextBrush.Dispose();
renderTarget.Dispose();

View file

@ -15,6 +15,9 @@ cbuffer AquariumFrame : register(b0)
float2 previousJitterPixels;
float renderDebugMode;
float exposure;
float bloomIntensity;
float bloomVeilIntensity;
float2 presentationPadding;
};
Texture2D<float4> gridHeightTexture : register(t0);
@ -55,8 +58,6 @@ static const float FIELD_ID_GRID = 1.0;
static const float FIELD_ID_SELF = 2.0;
static const float FIELD_ID_PLANET_BASE = 10.0;
static const float MAX_HISTORY_AGE = 32.0;
static const float BLOOM_INTENSITY = 0.072;
static const float BLOOM_VEIL_INTENSITY = 0.014;
static const float GRID_HEIGHT_TEXEL_COUNT = 128.0;
static const int FROXEL_COUNT_X = 8;
static const int FROXEL_COUNT_Y = 8;
@ -1590,7 +1591,7 @@ ResolveOut AquariumResolvePS(VertexOut input)
bloomTexture0.SampleLevel(gridSampler, input.uv, 0.0).rgb * 0.42 +
bloomTexture1.SampleLevel(gridSampler, input.uv, 0.0).rgb * 0.34 +
bloomTexture2.SampleLevel(gridSampler, input.uv, 0.0).rgb * 0.24;
float3 presentedColor = exposedColor + bloomColor * BLOOM_INTENSITY + luminance(bloomColor) * BLOOM_VEIL_INTENSITY;
float3 presentedColor = exposedColor + bloomColor * bloomIntensity + luminance(bloomColor) * bloomVeilIntensity;
float3 finalColor = aces(presentedColor);
if (renderDebugMode > 0.5 && renderDebugMode < 1.5)
{
@ -1618,7 +1619,7 @@ ResolveOut AquariumResolvePS(VertexOut input)
}
else if (renderDebugMode >= 6.5 && renderDebugMode < 7.5)
{
finalColor = aces(bloomColor * BLOOM_INTENSITY + luminance(bloomColor) * BLOOM_VEIL_INTENSITY);
finalColor = aces(bloomColor * bloomIntensity + luminance(bloomColor) * bloomVeilIntensity);
}
else if (renderDebugMode >= 7.5 && renderDebugMode < 8.5)
{

View file

@ -0,0 +1,430 @@
using System.Globalization;
using System.Numerics;
using Aquarium.Engine.Input;
using Vortice.Direct2D1;
using Vortice.DirectWrite;
using Vortice.Mathematics;
namespace Aquarium.Engine.Render.Ui;
internal sealed class DebugUi
{
private const float PanelLeft = 18.0f;
private const float PanelTop = 82.0f;
private const float PanelWidth = 360.0f;
private const float HeaderHeight = 42.0f;
private const float RowHeight = 31.0f;
private const float RowGap = 6.0f;
private const float SectionHeight = 22.0f;
private const float LabelWidth = 168.0f;
private const float TrackWidth = 116.0f;
private const float TrackHeight = 5.0f;
private readonly List<DebugUiControl> controls = [];
private int? activeSliderId;
private Rect panelBounds;
public DebugUi(string title)
{
Title = title;
}
public string Title { get; }
public bool IsVisible { get; set; } = true;
public bool WantsMouse { get; private set; }
public DebugUi Panel(Action<DebugUiPanel> compose)
{
var panel = new DebugUiPanel(controls);
compose(panel);
return this;
}
public void Update(InputState input)
{
if (input.IsKeyPressed(KeyCode.DebugUiToggle))
{
IsVisible = !IsVisible;
}
if (!IsVisible)
{
WantsMouse = false;
activeSliderId = null;
return;
}
Layout();
var mouse = input.MousePosition;
WantsMouse = Contains(panelBounds, mouse);
if (!input.LeftMouseDown)
{
activeSliderId = null;
}
if (activeSliderId is { } sliderId)
{
if (controls.FirstOrDefault(control => control.Id == sliderId) is SliderControl activeSlider)
{
activeSlider.Drag(mouse);
}
return;
}
if (!input.IsMousePressed(MouseButton.Left))
{
return;
}
for (var index = controls.Count - 1; index >= 0; index--)
{
var control = controls[index];
if (!control.HitTest(mouse))
{
continue;
}
control.Click(mouse);
if (control is SliderControl slider)
{
activeSliderId = slider.Id;
slider.Drag(mouse);
}
break;
}
}
public void Draw(
ID2D1RenderTarget target,
IDWriteTextFormat titleFormat,
IDWriteTextFormat smallFormat,
ID2D1SolidColorBrush panelBrush,
ID2D1SolidColorBrush rowBrush,
ID2D1SolidColorBrush outlineBrush,
ID2D1SolidColorBrush primaryBrush,
ID2D1SolidColorBrush quietBrush,
ID2D1SolidColorBrush accentBrush,
ID2D1SolidColorBrush dimAccentBrush)
{
if (!IsVisible)
{
return;
}
Layout();
target.FillRectangle(panelBounds, panelBrush);
target.DrawRectangle(panelBounds, outlineBrush, 1.0f);
target.DrawLine(
new Vector2(panelBounds.Left, panelBounds.Top + HeaderHeight),
new Vector2(panelBounds.Right, panelBounds.Top + HeaderHeight),
outlineBrush,
1.0f);
target.DrawText(
Title,
titleFormat,
new Rect(panelBounds.Left + 12.0f, panelBounds.Top + 8.0f, panelBounds.Right - 12.0f, panelBounds.Top + HeaderHeight - 4.0f),
primaryBrush,
DrawTextOptions.Clip);
foreach (var control in controls)
{
control.Draw(target, smallFormat, rowBrush, outlineBrush, primaryBrush, quietBrush, accentBrush, dimAccentBrush);
}
target.DrawText(
"F2 hide",
smallFormat,
new Rect(panelBounds.Left + 12.0f, panelBounds.Bottom - 26.0f, panelBounds.Right - 12.0f, panelBounds.Bottom - 8.0f),
quietBrush,
DrawTextOptions.Clip);
}
private void Layout()
{
var y = PanelTop + HeaderHeight + 10.0f;
foreach (var control in controls)
{
var height = control is SectionControl ? SectionHeight : RowHeight;
control.Bounds = new Rect(PanelLeft + 10.0f, y, PanelLeft + PanelWidth - 10.0f, y + height);
y += height + (control is SectionControl ? 2.0f : RowGap);
}
panelBounds = new Rect(PanelLeft, PanelTop, PanelLeft + PanelWidth, y + 30.0f);
}
private static bool Contains(Rect bounds, Vector2 point)
{
return point.X >= bounds.Left
&& point.X <= bounds.Right
&& point.Y >= bounds.Top
&& point.Y <= bounds.Bottom;
}
public sealed class DebugUiPanel
{
private readonly List<DebugUiControl> controls;
internal DebugUiPanel(List<DebugUiControl> controls)
{
this.controls = controls;
}
public DebugUiPanel Section(string title)
{
controls.Add(new SectionControl(title));
return this;
}
public DebugUiPanel Button(string label, Action action)
{
controls.Add(new ButtonControl(label, action));
return this;
}
public DebugUiPanel Toggle(string label, Func<bool> read, Action<bool> write)
{
controls.Add(new ToggleControl(label, read, write));
return this;
}
public DebugUiPanel Slider(string label, Func<float> read, Action<float> write, float min, float max, string format = "0.###")
{
controls.Add(new FloatSliderControl(label, read, write, min, max, format));
return this;
}
public DebugUiPanel Slider(string label, Func<int> read, Action<int> write, int min, int max)
{
controls.Add(new IntSliderControl(label, read, write, min, max));
return this;
}
}
internal abstract class DebugUiControl(string label)
{
private static int nextId;
public int Id { get; } = nextId++;
protected string Label { get; } = label;
public Rect Bounds { get; set; }
public virtual bool HitTest(Vector2 mouse) => Contains(Bounds, mouse);
public virtual void Click(Vector2 mouse)
{
}
public abstract void Draw(
ID2D1RenderTarget target,
IDWriteTextFormat format,
ID2D1SolidColorBrush rowBrush,
ID2D1SolidColorBrush outlineBrush,
ID2D1SolidColorBrush primaryBrush,
ID2D1SolidColorBrush quietBrush,
ID2D1SolidColorBrush accentBrush,
ID2D1SolidColorBrush dimAccentBrush);
protected void DrawRow(ID2D1RenderTarget target, ID2D1SolidColorBrush rowBrush, ID2D1SolidColorBrush outlineBrush)
{
target.FillRectangle(Bounds, rowBrush);
target.DrawLine(
new Vector2(Bounds.Left, Bounds.Bottom),
new Vector2(Bounds.Right, Bounds.Bottom),
outlineBrush,
1.0f);
}
protected Rect LabelBounds()
{
return new Rect(Bounds.Left + 8.0f, Bounds.Top + 6.0f, Bounds.Left + LabelWidth, Bounds.Bottom);
}
protected Rect ValueBounds()
{
return new Rect(Bounds.Left + LabelWidth + 10.0f, Bounds.Top + 6.0f, Bounds.Right - TrackWidth - 20.0f, Bounds.Bottom);
}
}
private sealed class SectionControl(string label) : DebugUiControl(label)
{
public override bool HitTest(Vector2 mouse) => false;
public override void Draw(
ID2D1RenderTarget target,
IDWriteTextFormat format,
ID2D1SolidColorBrush rowBrush,
ID2D1SolidColorBrush outlineBrush,
ID2D1SolidColorBrush primaryBrush,
ID2D1SolidColorBrush quietBrush,
ID2D1SolidColorBrush accentBrush,
ID2D1SolidColorBrush dimAccentBrush)
{
target.DrawText(Label.ToUpperInvariant(), format, Bounds, accentBrush, DrawTextOptions.Clip);
target.DrawLine(
new Vector2(Bounds.Left + 118.0f, Bounds.Top + 11.0f),
new Vector2(Bounds.Right, Bounds.Top + 11.0f),
outlineBrush,
1.0f);
}
}
private sealed class ButtonControl(string label, Action action) : DebugUiControl(label)
{
public override void Click(Vector2 mouse) => action();
public override void Draw(
ID2D1RenderTarget target,
IDWriteTextFormat format,
ID2D1SolidColorBrush rowBrush,
ID2D1SolidColorBrush outlineBrush,
ID2D1SolidColorBrush primaryBrush,
ID2D1SolidColorBrush quietBrush,
ID2D1SolidColorBrush accentBrush,
ID2D1SolidColorBrush dimAccentBrush)
{
DrawRow(target, rowBrush, outlineBrush);
target.DrawText(Label, format, LabelBounds(), accentBrush, DrawTextOptions.Clip);
target.DrawText("apply", format, ValueBounds(), primaryBrush, DrawTextOptions.Clip);
}
}
private sealed class ToggleControl(string label, Func<bool> read, Action<bool> write) : DebugUiControl(label)
{
public override void Click(Vector2 mouse) => write(!read());
public override void Draw(
ID2D1RenderTarget target,
IDWriteTextFormat format,
ID2D1SolidColorBrush rowBrush,
ID2D1SolidColorBrush outlineBrush,
ID2D1SolidColorBrush primaryBrush,
ID2D1SolidColorBrush quietBrush,
ID2D1SolidColorBrush accentBrush,
ID2D1SolidColorBrush dimAccentBrush)
{
DrawRow(target, rowBrush, outlineBrush);
target.DrawText(Label.ToUpperInvariant(), format, LabelBounds(), accentBrush, DrawTextOptions.Clip);
var box = new Rect(Bounds.Right - 28.0f, Bounds.Top + 8.0f, Bounds.Right - 13.0f, Bounds.Bottom - 8.0f);
target.DrawRectangle(box, read() ? accentBrush : outlineBrush, 1.0f);
if (read())
{
target.DrawLine(new Vector2(box.Left + 3.0f, box.Top + 8.0f), new Vector2(box.Left + 7.0f, box.Bottom - 3.0f), accentBrush, 2.0f);
target.DrawLine(new Vector2(box.Left + 7.0f, box.Bottom - 3.0f), new Vector2(box.Right - 2.0f, box.Top + 3.0f), accentBrush, 2.0f);
}
}
}
private abstract class SliderControl(string label) : DebugUiControl(label)
{
public override bool HitTest(Vector2 mouse)
{
return Contains(Bounds, mouse);
}
public void Drag(Vector2 mouse)
{
var track = TrackBounds();
var normalized = Math.Clamp((mouse.X - track.Left) / Math.Max(1.0f, track.Right - track.Left), 0.0f, 1.0f);
WriteNormalized(normalized);
}
public override void Click(Vector2 mouse)
{
Drag(mouse);
}
protected abstract float ReadNormalized();
protected abstract void WriteNormalized(float value);
protected abstract string ReadDisplay();
public override void Draw(
ID2D1RenderTarget target,
IDWriteTextFormat format,
ID2D1SolidColorBrush rowBrush,
ID2D1SolidColorBrush outlineBrush,
ID2D1SolidColorBrush primaryBrush,
ID2D1SolidColorBrush quietBrush,
ID2D1SolidColorBrush accentBrush,
ID2D1SolidColorBrush dimAccentBrush)
{
DrawRow(target, rowBrush, outlineBrush);
target.DrawText(Label.ToUpperInvariant(), format, LabelBounds(), accentBrush, DrawTextOptions.Clip);
target.DrawText(ReadDisplay(), format, ValueBounds(), primaryBrush, DrawTextOptions.Clip);
var track = TrackBounds();
var t = ReadNormalized();
var fill = new Rect(track.Left, track.Top, track.Left + (track.Right - track.Left) * t, track.Bottom);
target.FillRectangle(track, dimAccentBrush);
target.FillRectangle(fill, accentBrush);
var thumbX = fill.Right;
target.FillRectangle(new Rect(thumbX - 4.0f, track.Top - 4.0f, thumbX + 4.0f, track.Bottom + 4.0f), accentBrush);
}
private Rect TrackBounds()
{
var right = Bounds.Right - 12.0f;
var left = right - TrackWidth;
var centerY = (Bounds.Top + Bounds.Bottom) * 0.5f;
return new Rect(left, centerY - TrackHeight * 0.5f, right, centerY + TrackHeight * 0.5f);
}
}
private sealed class FloatSliderControl(
string label,
Func<float> read,
Action<float> write,
float min,
float max,
string format) : SliderControl(label)
{
protected override float ReadNormalized()
{
return Math.Clamp((read() - min) / Math.Max(0.000001f, max - min), 0.0f, 1.0f);
}
protected override void WriteNormalized(float value)
{
write(min + (max - min) * value);
}
protected override string ReadDisplay()
{
return read().ToString(format, CultureInfo.InvariantCulture);
}
}
private sealed class IntSliderControl(
string label,
Func<int> read,
Action<int> write,
int min,
int max) : SliderControl(label)
{
protected override float ReadNormalized()
{
return Math.Clamp((read() - min) / Math.Max(1.0f, max - min), 0.0f, 1.0f);
}
protected override void WriteNormalized(float value)
{
write((int)MathF.Round(min + (max - min) * value));
}
protected override string ReadDisplay()
{
return read().ToString(CultureInfo.InvariantCulture);
}
}
}

View file

@ -40,3 +40,4 @@
{"area":"renderer/taa","lesson":"Gate 3M cuts temporal color history out of final presentation while projection jitter is disabled. The resolver still writes history, metadata, control, age, and weight for debug/future volumetrics, but mode 0 now presents current-frame color after analytic Grid reconstruction instead of letting stale opaque-surface history ghost the frame.","files":["src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl","docs/hlsl-renderer.md","docs/tsr-inspired-taa-spec.md","state/memory.json","state/scratch.md"],"verification":["dotnet build Aquarium.Engine.slnx","Shader hot reload applied with no stderr after Gate 3M cut"],"ts":"2026-05-09"}
{"area":"renderer/hdr","lesson":"Modern HDR/PBR presentation should be built as scene-linear lighting, explicit exposure, pre-tonemap bloom/veil, and an explicit display transform. Aquarium should avoid thresholded 2000s bloom; broad low-intensity bloom should spread existing HDR energy and be inspected with luminance/bloom debug views before SDF volumetrics land.","files":["research/rendering/hdr-pbr-presentation.md","state/map.yaml","state/memory.json","state/scratch.md"],"verification":["research pass over ACES, Unreal exposure/bloom docs, Jimenez COD AW post-processing, Hable filmic tonemapping, and Frostbite PBR notes"],"ts":"2026-05-09"}
{"area":"renderer/hdr","lesson":"Aquarium now has the first HDR presentation pipe before volumetrics: fixed manual exposure, half/quarter/eighth pre-tonemap bloom targets, firefly-safe downsampling, separable horizontal/vertical blur per level, low-gain bloom/veil composite before the ACES fit, and debug modes for bloom contribution and exposed luminance. This replaces the tempting full-res gather prototype with a proper hierarchical shape.","files":["src/Aquarium.Engine/Render/D3D11Renderer.cs","src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl","src/Aquarium.Engine.Contracts/Input/InputState.cs","src/Aquarium.Engine/AquariumHost.cs","src/Aquarium.Engine/Platform/Win32Window.cs","src/Aquarium.Engine/Render/DirectWriteOverlay.cs","docs/hlsl-renderer.md","docs/tsr-inspired-taa-spec.md","research/rendering/hdr-pbr-presentation.md","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-09"}
{"area":"renderer/debug-ui","lesson":"Aquarium debug UI now uses a native Direct2D/DirectWrite retained panel inspired by CultLib code-first composition: controls are bound by explicit read/write delegates and styled as flat compact rows rather than importing Unity prefabs or ImGui chrome. The first panel toggles with F2 and drives render debug mode plus HDR exposure, bloom intensity, and bloom veil through shader constants.","files":["src/Aquarium.Engine/Render/Ui/DebugUi.cs","src/Aquarium.Engine/Render/DirectWriteOverlay.cs","src/Aquarium.Engine/Render/D3D11Renderer.cs","src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl","src/Aquarium.Engine.Contracts/Input/InputState.cs","src/Aquarium.Engine/Platform/Win32Window.cs","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"],"ts":"2026-05-09"}

View file

@ -13,6 +13,7 @@ current_model:
renderer: src/Aquarium.Engine/Render/D3D11Renderer.cs
shader: src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl
overlay_text: src/Aquarium.Engine/Render/DirectWriteOverlay.cs
debug_ui: src/Aquarium.Engine/Render/Ui/DebugUi.cs
runtime_loader: src/Aquarium.Engine/Live/LiveRuntimeLoader.cs
dev_reload: scripts/dev-reload.ps1
dev_watch: scripts/dev-watch.ps1
@ -58,14 +59,15 @@ renderer_state:
- Primitive froxel/bin table for body broad phase.
- Stable planet-local displaced SDF domains.
- DirectWrite overlay text after scene rendering.
- Direct2D/DirectWrite debug UI panel with code-first controls bound to renderer state.
- Splash screen with bundled app icon and GameCult typefaces.
next:
- Add explicit renderer debug modes for hits, normals, depth, bins, and lighting.
- Extend explicit renderer debug modes for hits, normals, depth, bins, and lighting.
- Restore HDR scene target, gentle pre-tonemap bloom, and ACES as explicit passes.
- Add volumetrics as an explicit renderer-owned field pass, starting from Wronski/Hillaire-style frustum volume lighting with Self as the first emitter.
- Evolve solids and clouds toward one SDF field registry with material and medium regimes.
- Extend TSR-inspired temporal resolve with general animated-field velocity, richer reactive masks, and true volumetric history.
- Promote exposure and HDR presentation controls into typed CultCache renderer state.
- Promote exposure and HDR presentation controls from process-local debug UI into typed CultCache renderer state.
- Move Grid gradients into the Grid target for cheaper terrain normals.
- Rebuild lighting as an Aquarium-owned field before adding richer fog.
- Add diegetic labels and object-local menus after the renderer and text contracts are stable.
@ -73,7 +75,7 @@ renderer_state:
next_actions:
- Keep main as the live development branch.
- Verify publish output after every packaging-affecting change.
- Add renderer debug controls through the DirectWrite overlay path.
- Grow renderer debug controls through the Direct2D/DirectWrite overlay path.
- Use research/volumetrics/synthesis.md before designing fog, atmospheric scattering, clouds, or sparse volume storage.
- Use research/volumetrics/recent-volumetrics-and-gpu-sdf.md before designing GPU SDF, cloud traversal, learned field storage, or radiance caching.
- Check research/volumetrics/transcript-addendum.md before relying on slide decks as evidence; video transcripts can change the renderer lesson.

View file

@ -72,6 +72,7 @@
],
"text_and_ui": [
"Overlay text uses DirectWrite/Direct2D after scene rendering. It is crisp final-pixel UI for debug surfaces, terminals, inspectors, and splash/status text.",
"Aquarium debug controls should follow the CultLib code-first binding style without importing Unity prefab assumptions: panels, sections, sliders, toggles, and buttons bound by explicit read/write delegates, drawn as flat Direct2D/DirectWrite overlay UI.",
"Bundled fonts are Montserrat for thin small-cap display text and Ubuntu Sans for body/debug copy. Runtime must not depend on fonts installed in Windows.",
"Scene/diegetic labels should use renderer-owned MSDF/SDF billboards when they live in world space. Overlay text should not be shoved into HDR just because it is convenient.",
"Debug UI is allowed as an explicit escape hatch. Object-owned radial surfaces remain the target interaction grammar."

View file

@ -113,6 +113,11 @@ prototype integrated along the camera ray before surface composition.
eighth bloom targets, firefly-safe downsample, separable horizontal/vertical
blur per level, pre-tonemap bloom/veil composite, mode 7 bloom contribution,
and mode 8 exposed luminance.
- Debug UI pass: Aquarium now has a native Direct2D/DirectWrite debug panel
toggled with F2. It uses a CultLib-inspired code-first control API with
retained bound sliders/toggles/buttons instead of Unity prefabs or ImGui
chrome. First live controls are render debug mode, exposure, bloom intensity,
bloom veil, and panel visibility; the HDR controls feed shader constants.
- Dev watcher correction: live runtime reload now waits for the host stdout log
to acknowledge the exact new live DLL path before declaring success. A pointer
write alone is not proof. `dev-watch.ps1 -ReopenWhenClosed` reopens the last