From 0fdbcbbe8398f2feab065f99ebe53634160c105c Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 8 May 2026 11:52:46 +0100 Subject: [PATCH] Escape displaced body shells while marching --- docs/hlsl-renderer.md | 4 +++- src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/hlsl-renderer.md b/docs/hlsl-renderer.md index b41e4a4..923e967 100644 --- a/docs/hlsl-renderer.md +++ b/docs/hlsl-renderer.md @@ -53,7 +53,9 @@ Current frame order: Empty froxels skip body SDF work entirely. 5. Displaced body SDFs report a noisy hit distance separately from a conservative envelope step distance, so high-frequency surface detail can shape the - silhouette without letting rays skip over it. + silhouette without letting rays skip over it. When a ray is inside the + conservative envelope but outside the noisy surface, it takes a shell escape + step instead of starving on the minimum stride. 6. Terrain marching uses heightfield crossing and slope-aware steps instead of pretending `z - height(xy)` is a true Euclidean SDF. Body objects still use SDF distance steps. diff --git a/src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl b/src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl index d947d8b..8dc36e5 100644 --- a/src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl @@ -530,7 +530,14 @@ bool raymarch(float3 rayOrigin, float3 rayDirection, out float3 hitPosition, out : 0.026; terrainStep = min(terrainStep * 0.62, max(gridRadius * 0.08, 0.026)); - float bodyStep = bodyStepDistance < 99999.0 ? max(bodyStepDistance * 0.68, 0.004) : 100000.0; + float bodyStep = 100000.0; + if (bodyStepDistance < 99999.0) + { + bodyStep = bodyStepDistance > hitEpsilon + ? bodyStepDistance * 0.68 + : max(bodyDistance * 0.42, 0.045); + } + float distanceToScene = min(bodyStep, terrainStep); previousTravel = travel; previousTerrainGap = terrainGap;