diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl b/src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl index 83e00bd..816b493 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl @@ -43,16 +43,6 @@ static const float CURSOR_RADIUS = 0.56; static const float CURSOR_BOUND_RADIUS = 0.72; static const float PI = 3.14159265359; static const float GRID_HEIGHT_TEXEL_COUNT = 128.0; -static const float TERRAIN_ISOLINE_SPACING = 0.12; -static const float GRID_LINE_WORLD_CELL = 2.0; -static const float GRID_MAJOR_LINE_WORLD_CELL = GRID_LINE_WORLD_CELL * 5.0; -static const float GRID_LINE_PIXEL_WIDTH = 0.46; -static const float GRID_MAJOR_LINE_PIXEL_WIDTH = 0.82; -static const float GRID_LINE_PIXEL_FADE = 0.95; -static const float TERRAIN_ISOLINE_PIXEL_WIDTH = 0.54; -static const float TERRAIN_FIELD_LINE_PIXEL_WIDTH = 0.38; -static const float3 GRID_COLOR = float3(0.30, 0.90, 0.82); -static const float GRID_ALPHA_SCALE = 0.56; static const int BODY_LIGHT_COUNT = 8; static const float STUDIO_PMREM_MAX_LOD = 8.0; static const float STUDIO_PMREM_SPECULAR_INTENSITY = 0.34; @@ -178,52 +168,6 @@ float3 terrainNormal(float3 p) return normalize(float3(-gradient.x, -gradient.y, 1.0)); } -float periodicLineMask(float coordinate, float pixelWidth, float pixelFade) -{ - float distanceToLine = min(frac(coordinate), 1.0 - frac(coordinate)); - float coordinatePerPixel = max(fwidth(coordinate), 0.00001); - float distancePixels = distanceToLine / coordinatePerPixel; - return 1.0 - smoothstep(pixelWidth, pixelWidth + pixelFade, distancePixels); -} - -float gridLine(float2 p) -{ - float2 minorDomain = p / GRID_LINE_WORLD_CELL; - float2 majorDomain = p / GRID_MAJOR_LINE_WORLD_CELL; - - float minor = max( - periodicLineMask(minorDomain.x, GRID_LINE_PIXEL_WIDTH, GRID_LINE_PIXEL_FADE), - periodicLineMask(minorDomain.y, GRID_LINE_PIXEL_WIDTH, GRID_LINE_PIXEL_FADE)); - float major = max( - periodicLineMask(majorDomain.x, GRID_MAJOR_LINE_PIXEL_WIDTH, GRID_LINE_PIXEL_FADE), - periodicLineMask(majorDomain.y, GRID_MAJOR_LINE_PIXEL_WIDTH, GRID_LINE_PIXEL_FADE)); - - return saturate(minor * 0.58 + major); -} - -float isolineMask(float height) -{ - float contourDomain = height / TERRAIN_ISOLINE_SPACING; - float contour = periodicLineMask(contourDomain, TERRAIN_ISOLINE_PIXEL_WIDTH, GRID_LINE_PIXEL_FADE); - float contourDerivative = max(fwidth(contourDomain), 0.00001); - float slopeFade = smoothstep(0.025, 0.25, contourDerivative); - return contour * slopeFade; -} - -float fieldLineMask(float2 gradient) -{ - float slope = length(gradient); - if (slope < 0.0001) - { - return 0.0; - } - - float angleDomain = (atan2(gradient.y, gradient.x) / PI + 1.0) * 6.0; - float angleLine = periodicLineMask(angleDomain, TERRAIN_FIELD_LINE_PIXEL_WIDTH, GRID_LINE_PIXEL_FADE); - float slopeStrength = smoothstep(0.015, 0.16, slope); - return angleLine * slopeStrength; -} - bool traceSphere(float3 origin, float3 direction, float3 center, float radius, out float travel) { float3 oc = origin - center; @@ -473,19 +417,11 @@ bool traceGridSurfaceDirect(float3 origin, float3 direction, float intervalStart return false; } -float3 gridEventColor(float3 p, out float alpha) +float3 gridMirrorRadiance(float3 p, float3 direction, out float3 normal) { - float height = terrainHeight(p.xy); - float2 gradient = terrainGradient(p.xy); - float gridAmount = gridLine(p.xy); - float contour = isolineMask(height); - float fieldLine = fieldLineMask(gradient); - float support = saturate(gridAmount * 0.58 + contour * 0.22 + fieldLine * 0.16); - float3 color = GRID_COLOR * gridAmount * 1.05; - color += float3(0.98, 1.0, 0.78) * contour * 0.34; - color += float3(0.36, 0.92, 1.0) * fieldLine * 0.22; - alpha = saturate(support * GRID_ALPHA_SCALE); - return color; + normal = terrainNormal(p); + float3 reflectionDirection = reflect(direction, normal); + return studioPmremTexture.SampleLevel(gridSampler, reflectionDirection, 0.0).rgb; } RayMarchResult traverseRay(float2 uv, float2 screenUv, float3 origin, float3 direction) @@ -512,19 +448,15 @@ RayMarchResult traverseRay(float2 uv, float2 screenUv, float3 origin, float3 dir float3 gridPosition; float gridTravel; bool gridHit = traceGridSurfaceDirect(origin, direction, 0.0, stopTravel, gridPosition, gridTravel); - float gridAlpha = 0.0; - float3 gridColor = 0.0; if (gridHit) { - gridColor = gridEventColor(gridPosition, gridAlpha); - gridHit = gridAlpha > 0.001; - } - - if (gridHit) - { - result.eventTravel = gridTravel; - result.eventCoverage = gridAlpha; - result.eventColor = gridColor * gridAlpha; + float3 gridNormal; + result.color = gridMirrorRadiance(gridPosition, direction, gridNormal); + result.travel = gridTravel; + result.fieldId = FIELD_ID_GRID; + result.normal = gridNormal; + result.coverage = 1.0; + return result; } if (nearestSolid.hit) diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 0ffcb39..f8d407f 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -6,3 +6,4 @@ {"timestamp":"2026-05-11T05:32:00+01:00","topic":"body-light-lane","lesson":"Blue-noise assets are retained for future dithering. Self and future other Selves emit through an explicit body light buffer; generic field instances are not the lighting authority.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","state/map.yaml","state/memory.json"]} {"timestamp":"2026-05-11T06:18:00+01:00","topic":"pmrem-cubemap-bake","lesson":"Studio HDR reflection lighting is baked as a PMREM DDS cubemap: roughness selects higher mips, and the bake samples the source latlong by output direction so cubemap faces are generated from one continuous domain instead of filtered as isolated square images.","files":["scripts/bake-pmrem-cubemap.py","src/Aquarium.Engine/Assets/Textures/studio3_pmrem.dds","state/map.yaml","state/memory.json"],"source":"E:\\Projects\\EpiphanyAquarium\\public\\textures\\studio3.hdr"} {"timestamp":"2026-05-11T06:28:00+01:00","topic":"pmrem-scene-binding","lesson":"The Studio3 PMREM asset is live in the scene as a D3D12 TextureCube bound at t22. The renderer owns a narrow RGBA16F DX10 DDS cubemap loader, keeps upload resources alive until the copy fence completes, and the scene shader uses roughness-scaled SampleLevel for specular material reflections only.","files":["src/Aquarium.Engine/Render/D3D12CubeTexture.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","state/map.yaml","state/memory.json"]} +{"timestamp":"2026-05-11T06:42:00+01:00","topic":"grid-mirror-surface","lesson":"Grid linework was replaced with a terminating perfect mirror surface. Grid hits now write the primary scene packet with FIELD_ID_GRID, terrain normal, full coverage, and Studio3 PMREM mip 0 reflection instead of using the transparent event lane.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","state/map.yaml","state/memory.json"]} diff --git a/state/map.yaml b/state/map.yaml index 07bad01..3b73165 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -52,7 +52,7 @@ renderer_state: current: - D3D12 default renderer behind IAquariumRenderer with explicit device/queue/swapchain, command allocators, fences, descriptor arenas, upload ring constants, tracked render targets, command events, resize rebuild, HDR/bloom/present, temporal diagnostics, and DirectWrite overlay bridge. - Deferred scalar Grid height target rendered from additive brush passes. - - Direct-traced Grid linework as a non-terminating stochastic event lane before the nearest solid. + - Direct-traced Grid surface is a terminating perfect mirror over the scalar height field, sampling Studio3 PMREM mip 0. - SDF/analytic solids for Self, planets, and the cursor locator. - Body light buffer feeds Self emission and direct body lighting; future other Selves should join this light lane, not a generic field-instance table. - Studio3 PMREM DDS cubemap is loaded as a D3D12 TextureCube and sampled for roughness-mip PBR specular reflections. @@ -70,5 +70,5 @@ next_actions: - Verify publish output after every packaging-affecting change. - Grow renderer debug controls through the Direct2D/DirectWrite overlay path. - Follow research/rendering/hdr-pbr-presentation.md before changing HDR exposure, bloom, tonemapping, or display transforms. - - Follow docs/tsr-inspired-taa-spec.md when changing current temporal diagnostics or stochastic event handling. + - Follow docs/tsr-inspired-taa-spec.md when changing current temporal diagnostics. - Promote future runtime knobs into typed CultCache documents before they become process folklore. diff --git a/state/memory.json b/state/memory.json index 5c29e5e..b3f258c 100644 --- a/state/memory.json +++ b/state/memory.json @@ -28,14 +28,13 @@ ], "rendering": [ "D3D12 Grid line width normalization uses periodic domains with `fwidth()` and pixel-width constants, not world-space footprint guesses.", - "The Grid is direct-traced as a non-terminating event before the nearest solid. It should not write the opaque surface packet.", - "For a single Grid event, emit expected premultiplied event radiance from analytic coverage; reserve blue-noise stochastic selection for future cases with competing transparent samples.", + "The Grid is direct-traced as a terminating mirror surface over the scalar height field. It writes the primary surface packet with FIELD_ID_GRID, terrain normal, full coverage, and Studio3 PMREM mip 0 reflection.", "Mouse/cursor-owned SDF bodies need object-motion reprojection. Carry current and previous cursor world anchors through frame constants and reproject cursor hits from current center to previous center.", "The cursor locator uses the MathWorld teardrop curve profile with m=6, revolved around vertical: x=cos(t), y=sin(t)*sin^m(t/2), radius `sqrt(1 - x^2) * ((1 - x) / 2)^3`. Ripples belong in the SDF radius function. Material is brass GGX metal with brass-tinted F0, no diffuse metal term, non-emissive, and no ambient floor.", "Heavy/specialized SDF evaluators should not live inside generic packed-id helpers when those helpers are called repeatedly; avoid shader compiler path cloning.", "Lighting is diegetic. Self is the initial emitter; later other Selves should emit through an explicit body light lane, not generic field instances or ambient convenience fill.", "Keep bundled blue-noise texture assets available for future dithering/noise work even when no current pass samples them.", - "Specular IBL uses the Studio3 PMREM cubemap: bake HDR latlong radiance into roughness-indexed cubemap mips, load it as a D3D12 TextureCube, and sample it by reflection direction plus roughness LOD. Keep this as material reflection response, not a replacement for diegetic body light authority.", + "Specular IBL uses the Studio3 PMREM cubemap: bake HDR latlong radiance into roughness-indexed cubemap mips, load it as a D3D12 TextureCube, and sample it by reflection direction plus roughness LOD. Grid mirror reflection samples mip 0 directly; body material reflections use roughness LOD. Keep this as material reflection response, not a replacement for diegetic body light authority.", "HDR/PBR presentation follows research/rendering/hdr-pbr-presentation.md: scene-linear lighting, explicit exposure, pre-tonemap bloom/veil, then display transform.", "Current temporal diagnostics are for inspection. With projection jitter disabled, final presentation should not blindly trust temporal color history until a real temporal contract earns authority." ],