From c147e3bff447c67f7b4728fc7e7683b570ef4c86 Mon Sep 17 00:00:00 2001 From: Wojciech Figat Date: Mon, 6 Jun 2022 13:13:36 +0200 Subject: [PATCH] Minor DDGI optimization --- Content/Shaders/GI/DDGI.flax | 4 +-- .../GI/DynamicDiffuseGlobalIllumination.cpp | 2 +- Source/Shaders/GI/DDGI.shader | 33 +++++++++---------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Content/Shaders/GI/DDGI.flax b/Content/Shaders/GI/DDGI.flax index 29c746d3b..d68e89a7b 100644 --- a/Content/Shaders/GI/DDGI.flax +++ b/Content/Shaders/GI/DDGI.flax @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:cd93974da1fcb3fad04406e385cb2988f171ef2378017adb9971ac36e5d7b5de -size 18757 +oid sha256:589d77f14b69b0af963b848ee5a4342c0986304f64296a29d21f45d7e0e6ea88 +size 18536 diff --git a/Source/Engine/Renderer/GI/DynamicDiffuseGlobalIllumination.cpp b/Source/Engine/Renderer/GI/DynamicDiffuseGlobalIllumination.cpp index 9d86a9585..8521cd1c0 100644 --- a/Source/Engine/Renderer/GI/DynamicDiffuseGlobalIllumination.cpp +++ b/Source/Engine/Renderer/GI/DynamicDiffuseGlobalIllumination.cpp @@ -287,12 +287,12 @@ bool DynamicDiffuseGlobalIlluminationPass::Render(RenderContext& renderContext, bool debugProbes = false; // TODO: add debug option to draw probes locations -> in Graphics window - Editor-only // TODO: configurable via postFx settings (maybe use Global SDF distance?) const float indirectLightingIntensity = 1.0f; + const float probeHistoryWeight = 0.8f; const Vector3 giDistance(2000, 2000, 2000); // GI distance around the view (in each direction) const float giResolution = 100.0f; // GI probes placement spacing const Int3 probesCounts(Vector3::Ceil(giDistance / giResolution)); const Vector3 probesDistance = Vector3(probesCounts) * giResolution; const int32 probeRaysCount = Math::Min(Math::AlignUp(256, DDGI_TRACE_RAYS_GROUP_SIZE_X), DDGI_TRACE_RAYS_LIMIT); // TODO: make it based on the GI Quality - const float probeHistoryWeight = 0.8f; // Init buffers const int32 probesCount = probesCounts.X * probesCounts.Y * probesCounts.Z; diff --git a/Source/Shaders/GI/DDGI.shader b/Source/Shaders/GI/DDGI.shader index 6cfb7fa0d..c6a680291 100644 --- a/Source/Shaders/GI/DDGI.shader +++ b/Source/Shaders/GI/DDGI.shader @@ -236,9 +236,7 @@ void CS_UpdateProbes(uint3 DispatchThreadId : SV_DispatchThreadID, uint GroupInd uint coord = (probeCount + (scrollDirection ? (scrollOffset - 1) : (scrollOffset % probeCount))) % probeCount; if (probeCoords[planeIndex] == coord) { - // Clear probe and return - //RWOutput[outputCoords] = float4(0, 0, 0, 0); - //if (!skip) RWOutput[outputCoords] = float4(0, 0, 0, 0); + // Skip scrolled probes skip = true; } } @@ -249,23 +247,20 @@ void CS_UpdateProbes(uint3 DispatchThreadId : SV_DispatchThreadID, uint GroupInd if (probeState == DDGI_PROBE_STATE_INACTIVE) skip = true; - // Calculate octahedral projection for probe (unwraps spherical projection into a square) - float2 octahedralCoords = GetOctahedralCoords(DispatchThreadId.xy, DDGI_PROBE_RESOLUTION); - float3 octahedralDirection = GetOctahedralDirection(octahedralCoords); - - // Load trace rays results into shared memory to reuse across whole thread group - uint count = (uint)(ceil((float)(DDGI_TRACE_RAYS_LIMIT) / (float)(DDGI_PROBE_RESOLUTION * DDGI_PROBE_RESOLUTION))); - for (uint i = 0; i < count; i++) + if (!skip) { - uint rayIndex = (GroupIndex * count) + i; - if (rayIndex >= DDGI.RaysCount) - break; - CachedProbesTraceRadiance[rayIndex] = ProbesTrace[uint2(rayIndex, probeIndex)]; - CachedProbesTraceDirection[rayIndex] = GetProbeRayDirection(DDGI, rayIndex); + // Load trace rays results into shared memory to reuse across whole thread group + uint count = (uint)(ceil((float)(DDGI_TRACE_RAYS_LIMIT) / (float)(DDGI_PROBE_RESOLUTION * DDGI_PROBE_RESOLUTION))); + for (uint i = 0; i < count; i++) + { + uint rayIndex = (GroupIndex * count) + i; + if (rayIndex >= DDGI.RaysCount) + break; + CachedProbesTraceRadiance[rayIndex] = ProbesTrace[uint2(rayIndex, probeIndex)]; + CachedProbesTraceDirection[rayIndex] = GetProbeRayDirection(DDGI, rayIndex); + } } GroupMemoryBarrierWithGroupSync(); - - // TODO: optimize probes updating to build indirect dispatch args and probes indices list before tracing rays and blending irradiance/distance if (skip) { // Clear probe @@ -273,6 +268,10 @@ void CS_UpdateProbes(uint3 DispatchThreadId : SV_DispatchThreadID, uint GroupInd return; } + // Calculate octahedral projection for probe (unwraps spherical projection into a square) + float2 octahedralCoords = GetOctahedralCoords(DispatchThreadId.xy, DDGI_PROBE_RESOLUTION); + float3 octahedralDirection = GetOctahedralDirection(octahedralCoords); + // Loop over rays float4 result = float4(0, 0, 0, 0); #if DDGI_PROBE_UPDATE_MODE == 0