diff --git a/src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl b/src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl index 6f4cf45..01ac844 100644 --- a/src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl @@ -1444,6 +1444,48 @@ float gridTemporalSupport(float3 position) return saturate(gridAmount * 0.58 + contour * 0.22 + fieldLine * 0.16) * mask; } +void integrateTransparentGridOverlay(float3 rayOrigin, float3 rayDirection, float maxTravel, out float3 overlayColor, out float overlayAlpha) +{ + overlayColor = 0.0; + overlayAlpha = 0.0; + + float marchEnd = min(maxTravel, farDistance); + float stepLength = max(marchEnd / 72.0, 0.05); + float travel = stepLength * 0.5; + float transmittance = 1.0; + + [loop] + for (int stepIndex = 0; stepIndex < 96; stepIndex++) + { + if (travel >= marchEnd || transmittance < 0.04) + { + break; + } + + float3 p = rayOrigin + rayDirection * travel; + float surfaceZ = terrainHeight(p.xy); + float3 surfacePosition = float3(p.xy, surfaceZ); + float mask = terrainMask(p.xy); + float2 gradient = terrainGradient(p.xy); + float normalRate = max(abs(rayDirection.z - dot(gradient, rayDirection.xy)), 0.18); + float bandWidth = max(0.028, travel * 0.00045); + float band = (1.0 - smoothstep(bandWidth, bandWidth * 2.8, abs(p.z - surfaceZ))) * mask; + + if (band > 0.0001) + { + float4 overlay = shadeGridOverlay(surfacePosition); + float alpha = saturate(overlay.a * band * stepLength / normalRate * 0.42); + overlayColor += transmittance * overlay.rgb * alpha; + overlayAlpha += transmittance * alpha; + transmittance *= 1.0 - alpha; + } + + travel += stepLength; + } + + overlayAlpha = saturate(overlayAlpha); +} + float3 aces(float3 color) { const float a = 2.51; @@ -1596,24 +1638,6 @@ SceneOut AquariumScenePS(VertexOut input) outputCoverage = 1.0; } - float3 gridHitPosition; - float gridTravel; - if (traceGridSurface(cameraPosition, rayDirection, gridHitPosition, gridTravel) && gridTravel < nearestSolidTravel) - { - float4 gridOverlay = shadeGridOverlay(gridHitPosition); - float gridCoverage = saturate(gridOverlay.a); - float gridSupport = gridTemporalSupport(gridHitPosition); - outputTravel = gridTravel; - outputMaterialId = FIELD_ID_GRID; - outputNormal = terrainNormal(gridHitPosition); - outputCoverage = gridSupport; - outputReactive = 0.0; - if (stochasticTransparency(screenUv, gridOverlay.a) > 0.0) - { - color = gridOverlay.rgb; - } - } - float mediumDensityMean; float mediumTransmittance; float3 mediumInScattering; @@ -1751,14 +1775,6 @@ ResolveOut AquariumResolvePS(VertexOut input) float currentMediumDensity = saturate(currentControl.w); bool currentIsGrid = abs(currentFieldId - FIELD_ID_GRID) < 0.25; - if (currentIsGrid && currentTravel <= farDistance) - { - float3 currentRay = rayDirectionForPixel(pixel, jitterPixels, cameraPosition, gridCenter); - float3 worldPosition = cameraPosition + currentRay * currentTravel; - float4 gridOverlay = shadeGridOverlay(worldPosition); - currentColor = gridOverlay.rgb * saturate(gridOverlay.a) + float3(0.001, 0.003, 0.004); - } - float historyWeight = 0.0; float historyAge = 0.0; float3 historyColor = currentColor; @@ -1829,6 +1845,14 @@ ResolveOut AquariumResolvePS(VertexOut input) float blendedMediumTransmittance = lerp(1.0, froxelMediumTransmittance, mediumBlend); float3 resolved = currentColor * blendedMediumTransmittance + froxelMediumInScattering * mediumBlend; + float gridOverlayTravel = currentTravel <= farDistance && currentFieldId > 0.5 && !currentIsGrid + ? currentTravel + : farDistance; + float3 gridOverlayColor; + float gridOverlayAlpha; + float3 gridOverlayRay = rayDirectionForPixel(pixel, jitterPixels, cameraPosition, gridCenter); + integrateTransparentGridOverlay(cameraPosition, gridOverlayRay, gridOverlayTravel, gridOverlayColor, gridOverlayAlpha); + resolved = resolved * (1.0 - gridOverlayAlpha) + gridOverlayColor; float3 exposedColor = exposeSceneColor(resolved); float3 bloomColor = diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 19dd91c..198e0cc 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -59,3 +59,4 @@ {"area":"renderer/volumetrics","lesson":"Do not compose the final frame from the diagnostic 4x4 medium atlas. If atlas density shows frustum-slice blobs while direct ray density is continuous, final composition should use direct registered-medium ray integration until a real froxel volume replaces the diagnostic atlas. Keep atlas density as an artifact-revealing debug view only.","files":["src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl","state/scratch.md"],"verification":["dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4 -HeadlessTimeoutSeconds 60"],"ts":"2026-05-09"} {"area":"renderer/volumetrics","lesson":"The medium atlas trial has been replaced by a first real packed froxel volume: independent froxel dimensions, 32 depth slices, 8x4 D3D11 atlas packing, per-froxel density/transmittance/in-scattering, and resolve-side front-to-back composition. Direct ray density/transmittance debug remains the correctness reference; froxel density is the volume inspection view.","files":["src/Aquarium.Engine/Render/D3D11Renderer.cs","src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl","docs/hlsl-renderer.md","docs/sdf-field-renderer-plan.md","state/scratch.md"],"verification":["dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4 -HeadlessTimeoutSeconds 60"],"ts":"2026-05-09"} {"area":"renderer/volumetrics","lesson":"The Grid is a transparent schematic overlay, not a participating-medium occluder. Keep Grid travel/field id for temporal stability, but do not clamp fog integration to Grid travel; only solid fields such as Self and planets terminate the froxel composite ray.","files":["src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl","state/scratch.md"],"verification":["Aquarium.Engine project build succeeded","Full solution/headless verification blocked by dirty external CultLib changes on E:\\Projects\\CultLib codex/cultcache-attribute-first: CultCache.cs currently fails GameCult.Caching build with System.Text.Json/IsExternalInit errors"],"ts":"2026-05-09"} +{"area":"renderer/grid","lesson":"The Grid must not be owned by the scene first-hit surface path if it is meant to read as transparent schematic UI. Scene pass should keep solid depth/color as truth; resolve can integrate a thin Grid heightfield band along the camera ray and composite it over solids/fog up to the nearest solid travel. Avoid crossing-list multi-hit hacks; they fragment the heightfield.","files":["src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl","state/scratch.md"],"verification":["dotnet build src\\Aquarium.Engine\\Aquarium.Engine.csproj","manual headless shader check using reusable dev-reload slot 20260509-112908-42cf5f71"],"ts":"2026-05-09"} diff --git a/state/scratch.md b/state/scratch.md index 0c0b8a8..d2e2891 100644 --- a/state/scratch.md +++ b/state/scratch.md @@ -206,3 +206,8 @@ prototype integrated along the camera ray before surface composition. stops at Self/planet solids only; Grid pixels integrate medium to the visible far distance so the schematic overlay cannot cut holes through fog or occlude itself. +- Transparent Grid overlay correction: the Grid no longer writes scene color or + wins scene travel. Resolve integrates a thin heightfield band along the view + ray up to the nearest solid/far travel and composites it over the resolved + scene. This is the proper surface/transparency split: solids own depth, fog + owns volume, Grid owns a translucent schematic overlay.