Minor DDGI optimization

This commit is contained in:
Wojciech Figat
2022-06-06 13:13:36 +02:00
parent 1f1ed2bf60
commit c147e3bff4
3 changed files with 19 additions and 20 deletions

BIN
Content/Shaders/GI/DDGI.flax (Stored with Git LFS)

Binary file not shown.

View File

@@ -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;

View File

@@ -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,10 +247,8 @@ 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);
if (!skip)
{
// 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++)
@@ -263,9 +259,8 @@ void CS_UpdateProbes(uint3 DispatchThreadId : SV_DispatchThreadID, uint GroupInd
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