From 0d48ac8fc27e58ddf8b0771d07ed4a1778ea7fbc Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 18 Jun 2024 15:05:21 +0200 Subject: [PATCH] Add smoother DDGi probe relocation when old position is visible from new position --- Source/Shaders/GI/DDGI.shader | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Source/Shaders/GI/DDGI.shader b/Source/Shaders/GI/DDGI.shader index 203a84d3a..92df2c043 100644 --- a/Source/Shaders/GI/DDGI.shader +++ b/Source/Shaders/GI/DDGI.shader @@ -228,6 +228,20 @@ void CS_Classify(uint3 DispatchThreadId : SV_DispatchThreadID) // If probe was in a different location or was activated now then mark it as activated bool wasActivated = probeStateOld == DDGI_PROBE_STATE_INACTIVE; bool wasRelocated = distance(probeOffset, probeOffsetOld) > 2.0f; +#if DDGI_PROBE_RELOCATE_FIND_BEST || DDGI_PROBE_RELOCATE_ITERATIVE + if (wasRelocated && !wasActivated) + { + // If probe was relocated but the previous location is visible from the new one, then don't re-activate it for smoother blend + float3 diff = probeOffsetOld - probeOffset; + float diffLen = length(diff); + float3 diffDir = diff / diffLen; + GlobalSDFTrace trace; + trace.Init(probeBasePosition + probeOffset, diffDir, 0.0f, diffLen); + GlobalSDFHit hit = RayTraceGlobalSDF(GlobalSDF, GlobalSDFTex, GlobalSDFMip, trace); + if (!hit.IsHit()) + wasRelocated = false; + } +#endif if ((wasActivated || wasScrolled || wasRelocated) && probeState == DDGI_PROBE_STATE_ACTIVE) probeState = DDGI_PROBE_STATE_ACTIVATED; }