Skip to content

Commit 027fdbe

Browse files
DGI propagation fixes (#112)
* Fixed fallback radiance baking when dirty flags are enabled. * Fixed noticeable intensity loss for lower propagation quality due to axis weights renormalization error. * Separate radiance comparison for LogLUV encoding that avoids many false positives in dirty flags. * Fixed propagation data not being cleared when Frame Settings are changed via the settings window causing the pipeline to be destroyed.
1 parent fbc3755 commit 027fdbe

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
lines changed

com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/DynamicGI/ProbePropagationAxes.compute

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,7 @@ void PropagateLight(uint3 id : SV_DispatchThreadID)
427427
_RadianceCacheAxis[index] = EncodeRadiance(radiance);
428428

429429
#ifndef DIRTY_FLAGS_DISABLED
430-
float3 previousRadiance = DecodeRadiance(GetPreviousAxisRadiance(index));
431-
if (any(abs(radiance - previousRadiance) > 1.0 / 255.0))
430+
if (!IsSimilarEqual(GetPreviousAxisRadiance(index), radiance))
432431
{
433432
for (int l = 0; l < PROPAGATION_AXIS_AMOUNT; ++l)
434433
{

com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/DynamicGI/ProbePropagationHits.compute

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,7 @@ void AccumulateLightingDirectional(uint3 id : SV_DispatchThreadID)
236236
lighting += UnpackEmission(neighborData.mixedLighting) * _MixedLightingMultiplier;
237237

238238
#ifndef DIRTY_FLAGS_DISABLED
239-
float3 oldLighting = DecodeRadiance(_HitRadianceCacheAxis[hitAxisIndex]);
240-
241-
if (any(abs(lighting - oldLighting) > 1.0 / 255.0))
239+
if (!IsSimilarEqual(_HitRadianceCacheAxis[hitAxisIndex], lighting))
242240
SetProbeDirty(_ProbeVolumeDirtyFlags, probeIndex);
243241
#endif
244242

com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/DynamicGI/ProbeVolumeDynamicGI.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,7 @@ internal void DispatchPropagationOutputDynamicSH(
12791279

12801280
CoreUtils.SetKeyword(cmd, "PROBE_VOLUMES_ENCODING_SPHERICAL_HARMONICS_L1", false);
12811281
CoreUtils.SetKeyword(cmd, "PROBE_VOLUMES_ENCODING_SPHERICAL_HARMONICS_L2", true);
1282+
CoreUtils.SetKeyword(shader, "DIRTY_FLAGS_DISABLED", true);
12821283

12831284
cmd.SetComputeVectorParam(shader, HDShaderIDs._ProbeVolumeResolution, (Vector3)size);
12841285
cmd.SetComputeVectorParam(shader, HDShaderIDs._ProbeVolumeResolutionInverse, new Vector3(
@@ -1568,7 +1569,7 @@ unsafe void PrecomputeAxisCacheLookup(int axisAmount, BasisFunction basisFunctio
15681569
var hitWeightsGoal = 0f;
15691570
var propagationWeights = 0f;
15701571
var propagationWeightsGoal = 0f;
1571-
for (int sortedAxisIndex = 0; sortedAxisIndex < axisAmount; sortedAxisIndex++)
1572+
for (int sortedAxisIndex = 0; sortedAxisIndex < s_NeighborAxis.Length; sortedAxisIndex++)
15721573
{
15731574
if (sortedAxisIndex < axisAmount)
15741575
{
@@ -1578,14 +1579,13 @@ unsafe void PrecomputeAxisCacheLookup(int axisAmount, BasisFunction basisFunctio
15781579

15791580
hitWeightsGoal += _sortedNeighborAxisLookups[sortedAxisStart + sortedAxisIndex].hitWeight;
15801581
propagationWeightsGoal += _sortedNeighborAxisLookups[sortedAxisStart + sortedAxisIndex].propagationWeight;
1581-
15821582
}
15831583
float hitWeightsNormalization = hitWeightsGoal / hitWeights;
15841584
float propagationWeightsNormalization = propagationWeightsGoal / propagationWeights;
15851585
for (int sortedAxisIndex = 0; sortedAxisIndex < axisAmount; sortedAxisIndex++)
15861586
{
15871587
_sortedNeighborAxisLookups[sortedAxisStart + sortedAxisIndex].hitWeight *= hitWeightsNormalization;
1588-
_sortedNeighborAxisLookups[sortedAxisStart + sortedAxisIndex].propagationWeight /= propagationWeightsNormalization;
1588+
_sortedNeighborAxisLookups[sortedAxisStart + sortedAxisIndex].propagationWeight *= propagationWeightsNormalization;
15891589
}
15901590
}
15911591
}

com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/DynamicGI/ProbeVolumeDynamicGI.hlsl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,5 +341,28 @@ float3 DecodeRadiance(RADIANCE packedValue)
341341
#endif
342342
}
343343

344+
bool IsSimilarEqual(RADIANCE packedA, float3 b)
345+
{
346+
#if defined(RADIANCE_ENCODING_LOGLUV)
347+
const int3 componentsA = int3(packedA & 255, packedA >> 8 & 255, packedA >> 16);
348+
349+
const float3 logLuvB = LogluvFromRgb(b);
350+
const int3 componentsB = int3(
351+
min(255, (uint)round(logLuvB.x * 255)),
352+
min(255, (uint)round(logLuvB.y * 255)),
353+
min(65535, (uint)round(logLuvB.z * 65535)));
354+
355+
return all(abs(componentsA - componentsB) < int3(2, 2, 32));
356+
357+
#else
358+
// TODO: Add a better comparison for HalfLuv and R11G11B10 if they are needed. They'll be giving a lot of false negatives now.
359+
360+
const float3 a = DecodeRadiance(packedA);
361+
362+
// Comparison with NaN always gives false. But if max is 0 then min is also 0.
363+
// So we accept NaN from the division as true by flipping the condition twice.
364+
return !any(min(a, b) / max(a, b) < 0.99);
365+
#endif
366+
}
344367

345368
#endif // endof PROBE_VOLUME_DYNAMIC_GI

com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolumeLighting.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,13 @@ void CleanupProbeVolumes()
401401
{
402402
DestroyProbeVolumeBuffers();
403403

404+
if (SupportDynamicGI)
405+
{
406+
var volumes = ProbeVolumeManager.manager.GetVolumesToRender();
407+
foreach (var volume in volumes)
408+
ProbeVolumeDynamicGI.instance.ClearProbePropagation(volume);
409+
}
410+
404411
#if UNITY_EDITOR
405412
UnityEditor.Lightmapping.lightingDataCleared -= OnLightingDataCleared;
406413
#endif
@@ -1449,7 +1456,7 @@ void RenderProbeVolumeDebugOverlay(in DebugParameters debugParameters, CommandBu
14491456
{
14501457
DisplayProbeVolumeAtlas(cmd, debugParameters.probeVolumeOverlayParameters, debugParameters.debugOverlay);
14511458
}
1452-
else if (m_SupportDynamicGI && lightingDebug.probeVolumeDebugMode == ProbeVolumeDebugMode.VisualizeDynamicGIDirtyFlags)
1459+
else if (SupportDynamicGI && lightingDebug.probeVolumeDebugMode == ProbeVolumeDebugMode.VisualizeDynamicGIDirtyFlags)
14531460
{
14541461
DebugDrawProbeVolumeDirtyFlags(cmd);
14551462
}

0 commit comments

Comments
 (0)