diff --git a/docs/hlsl-renderer.md b/docs/hlsl-renderer.md index 81b17ff..ad5570c 100644 --- a/docs/hlsl-renderer.md +++ b/docs/hlsl-renderer.md @@ -68,6 +68,11 @@ Current frame order: tonemapping, and raymarching unless a specific diegetic surface asks for the trouble. +The shader far distance is frame-derived, not a fixed constant. C# sends the +distance from the camera to the Grid origin plus the Grid radius, which matches +the circular Grid fade boundary and avoids wasting raymarch work past the +visible field. + The target currently stores height in `.r` only. The next useful expansion is to store packed gradients in `.g/.b` during the Grid pass so the raymarcher can use one texture fetch for height and a cheaper normal path when fidelity allows it. diff --git a/src/Aquarium.Engine/Render/D3D11Renderer.cs b/src/Aquarium.Engine/Render/D3D11Renderer.cs index 54f18f8..531e915 100644 --- a/src/Aquarium.Engine/Render/D3D11Renderer.cs +++ b/src/Aquarium.Engine/Render/D3D11Renderer.cs @@ -136,6 +136,8 @@ public sealed class D3D11Renderer : IDisposable { TryHotReloadShaders(); + var gridOrigin = new Vector3(frame.Grid.Center.X, frame.Grid.Center.Y, 0.0f); + var farDistance = Vector3.Distance(frame.CameraPosition, gridOrigin) + MathF.Max(frame.Grid.Radius, 0.001f); var constants = new FrameConstants( new float2(width, height), frame.TimeSeconds, @@ -143,7 +145,8 @@ public sealed class D3D11Renderer : IDisposable (float3)frame.CameraPosition, 0.0f, (float2)frame.Grid.Center, - new float2(0.0f, 0.0f)); + farDistance, + 0.0f); BuildFroxelPrimitiveTable(frame); context.UpdateSubresource(in constants, frameConstantBuffer); @@ -447,7 +450,8 @@ public sealed class D3D11Renderer : IDisposable float3 CameraPosition, float CameraPad, float2 GridCenter, - float2 Pad0); + float FarDistance, + float Pad0); private readonly record struct FroxelCell(int X, int Y, int Z); diff --git a/src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl b/src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl index ca4f632..c8b04d3 100644 --- a/src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl @@ -6,7 +6,8 @@ cbuffer AquariumFrame : register(b0) float3 cameraPosition; float _pad0; float2 gridCenter; - float2 _pad1; + float farDistance; + float _pad1; }; Texture2D gridHeightTexture : register(t0); @@ -14,7 +15,6 @@ StructuredBuffer froxelPrimitiveIds : register(t1); SamplerState gridSampler : register(s0); static const float PI = 3.14159265359; -static const float FAR_DISTANCE = 90.0; static const float SURFACE_EPSILON = 0.0015; static const float3 SUN_POSITION = float3(0.0, 0.0, 2.2); static const float SUN_RADIUS = 1.12; @@ -783,7 +783,7 @@ bool raymarch(float3 rayOrigin, float3 rayDirection, out float3 hitPosition, out previousTerrainGap = terrainGap; travel += max(terrainStep, 0.026); - if (travel > FAR_DISTANCE) + if (travel > farDistance) { return false; } diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 7e1a1bf..6251e18 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -3,3 +3,4 @@ {"ts":"2026-05-08","topic":"engine_doctrine_distillation","summary":"Distilled only engine-relevant doctrine from the older Aquarium state: camera/Grid invariants, world-space anchors/domains, shader-owned visible world, conservative raymarch broad phase, diegetic lighting, DirectWrite overlay text, CultCache reload state, and hot reload failure behavior.","files":["docs/aquarium-engine-doctrine.md","state/memory.json","state/map.yaml"],"verification":["dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4"]} {"topic":"grid_derivative_linework","summary":"Ported the Aetheria UI isoline idea into the Aquarium Grid shader: height contours and gradient-angle field lines now derive from the deferred Grid height field, and Cartesian Gridlines use fwidth-based masks so line width stays stable in pixels across zoom.","files":["src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl","docs/hlsl-renderer.md"],"verification":["dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4"],"ts":"2026-05-08"} {"topic":"dev_reload_visible_headless_split","summary":"Fixed dev-reload so headless smoke runs use separate PID state and logs from the visible dev window, preventing headless verification from stopping the active window. Added -Reopen to relaunch the last visible slot without rebuilding.","files":["scripts/dev-reload.ps1","README.md","state/evidence.jsonl"],"verification":[".\\scripts\\dev-reload.ps1 -Reopen",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4","visible Aquarium PID remained running after headless smoke"],"ts":"2026-05-08"} +{"topic":"grid_far_distance","summary":"Replaced the shader fixed raymarch far distance with a per-frame value equal to camera distance from the Grid origin plus Grid radius, matching the circular Grid fade boundary.","files":["src/Aquarium.Engine/Render/D3D11Renderer.cs","src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl","docs/hlsl-renderer.md"],"verification":["dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4"],"ts":"2026-05-08"}