From abdbd1ee64d67721dad2644d175f876f31d252a4 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 4 Jun 2024 10:47:37 +0200 Subject: [PATCH] Add improved Global SDF tracing when going over different cascades --- Source/Shaders/GlobalSignDistanceField.hlsl | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Source/Shaders/GlobalSignDistanceField.hlsl b/Source/Shaders/GlobalSignDistanceField.hlsl index 93bdee22b..eee202784 100644 --- a/Source/Shaders/GlobalSignDistanceField.hlsl +++ b/Source/Shaders/GlobalSignDistanceField.hlsl @@ -223,26 +223,25 @@ GlobalSDFHit RayTraceGlobalSDF(const GlobalSDFData data, Texture3D tex, T float4 cascadePosDistance = data.CascadePosDistance[cascade]; float voxelSize = data.CascadeVoxelSize[cascade]; float voxelExtent = voxelSize * 0.5f; - float3 worldPosition = trace.WorldPosition + trace.WorldDirection * (voxelSize * cascadeTraceStartBias); + float3 worldPosition = trace.WorldPosition + trace.WorldDirection * max(voxelSize * cascadeTraceStartBias, trace.MinDistance); // Hit the cascade bounds to find the intersection points float2 intersections = LineHitBox(worldPosition, traceEndPosition, cascadePosDistance.xyz - cascadePosDistance.www, cascadePosDistance.xyz + cascadePosDistance.www); intersections.xy *= traceMaxDistance; intersections.x = max(intersections.x, nextIntersectionStart); - float stepTime = intersections.x; if (intersections.x >= intersections.y) { // Skip the current cascade if the ray starts outside it - stepTime = intersections.y; + continue; } - else - { - // Skip the current cascade tracing on the next cascade + + // Skip the current cascade tracing on the next cascade (if we're tracing from inside SDF volume) + if (intersections.x <= 0.0f) nextIntersectionStart = intersections.y; - } // Walk over the cascade SDF uint step = 0; + float stepTime = intersections.x; LOOP for (; step < 250 && stepTime < intersections.y; step++) {