Skip to content

Commit 722d7b1

Browse files
[7.x.x Backport] Fix issue with ambient probe not being correct with OnEnable/OnDemand probes (#317)
* render until ambient probe is ready * remove comment * changelog
1 parent 6876810 commit 722d7b1

File tree

5 files changed

+58
-16
lines changed

5 files changed

+58
-16
lines changed

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
629629
- Added a fix script to handle the warning 'referenced script in (GameObject 'SceneIDMap') is missing'
630630
- Fix Wizard load when none selected for RenderPipelineAsset
631631
- Fixed issue with unclear naming of debug menu for decals.
632+
- Fixed issue with reflection probes in realtime time mode with OnEnable baking having wrong lighting with sky set to dynamic (case 1238047).
632633

633634
### Changed
634635
- Color buffer pyramid is not allocated anymore if neither refraction nor distortion are enabled

com.unity.render-pipelines.high-definition/Runtime/Lighting/Reflection/HDProbe.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,13 @@ public virtual void PrepareCulling() { }
428428
/// </summary>
429429
public void RequestRenderNextUpdate() => m_WasRenderedSinceLastOnDemandRequest = false;
430430

431+
// Forces the re-rendering for both OnDemand and OnEnable
432+
internal void ForceRenderingNextUpdate()
433+
{
434+
m_WasRenderedSinceLastOnDemandRequest = false;
435+
wasRenderedAfterOnEnable = false;
436+
}
437+
431438
void UpdateProbeName()
432439
{
433440
// TODO: ask if this is ok:

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,14 @@ ref _cullingResults
16201620
continue;
16211621
}
16221622

1623+
// HACK! We render the probe until we know the ambient probe for the associated sky context is ready.
1624+
// For one-off rendering the dynamic ambient probe will be set to black until they are not processed, leading to faulty rendering.
1625+
// So we enqueue another rendering and then we will not set the probe texture until we have rendered with valid ambient probe.
1626+
if (!m_SkyManager.HasSetValidAmbientProbe(hdCamera))
1627+
{
1628+
visibleProbe.ForceRenderingNextUpdate();
1629+
}
1630+
16231631
hdCamera.parentCamera = parentCamera; // Used to inherit the properties of the view
16241632

16251633
HDAdditionalCameraData hdCam;
@@ -1666,26 +1674,30 @@ ref _cullingResults
16661674
// TODO: store DecalCullResult
16671675
};
16681676

1669-
// As we render realtime texture on GPU side, we must tag the texture so our texture array cache detect that something have change
1670-
visibleProbe.realtimeTexture.IncrementUpdateCount();
1671-
1672-
if (cameraSettings.Count > 1)
1677+
if (m_SkyManager.HasSetValidAmbientProbe(hdCamera))
16731678
{
1674-
var face = (CubemapFace)j;
1675-
request.target = new RenderRequest.Target
1679+
// As we render realtime texture on GPU side, we must tag the texture so our texture array cache detect that something have change
1680+
visibleProbe.realtimeTexture.IncrementUpdateCount();
1681+
1682+
if (cameraSettings.Count > 1)
16761683
{
1677-
copyToTarget = visibleProbe.realtimeTexture,
1678-
face = face
1679-
};
1680-
}
1681-
else
1682-
{
1683-
request.target = new RenderRequest.Target
1684+
var face = (CubemapFace)j;
1685+
request.target = new RenderRequest.Target
1686+
{
1687+
copyToTarget = visibleProbe.realtimeTexture,
1688+
face = face
1689+
};
1690+
}
1691+
else
16841692
{
1685-
id = visibleProbe.realtimeTexture,
1686-
face = CubemapFace.Unknown
1687-
};
1693+
request.target = new RenderRequest.Target
1694+
{
1695+
id = visibleProbe.realtimeTexture,
1696+
face = CubemapFace.Unknown
1697+
};
1698+
}
16881699
}
1700+
16891701
renderRequests.Add(request);
16901702

16911703

com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,24 @@ internal SphericalHarmonicsL2 GetAmbientProbe(HDCamera hdCamera)
413413
return GetAmbientProbe(hdCamera.lightingSky);
414414
}
415415

416+
internal bool HasSetValidAmbientProbe(HDCamera hdCamera)
417+
{
418+
SkyAmbientMode ambientMode = hdCamera.volumeStack.GetComponent<VisualEnvironment>().skyAmbientMode.value;
419+
if (ambientMode == SkyAmbientMode.Static)
420+
return true;
421+
422+
if (hdCamera.skyAmbientMode == SkyAmbientMode.Dynamic && hdCamera.lightingSky != null &&
423+
hdCamera.lightingSky.IsValid() && IsCachedContextValid(hdCamera.lightingSky))
424+
{
425+
ref CachedSkyContext cachedContext = ref m_CachedSkyContexts[hdCamera.lightingSky.cachedSkyRenderingContextId];
426+
var renderingContext = cachedContext.renderingContext;
427+
return renderingContext.ambientProbeIsReady;
428+
}
429+
430+
return false;
431+
432+
}
433+
416434
internal void SetupAmbientProbe(HDCamera hdCamera)
417435
{
418436
// Working around GI current system

com.unity.render-pipelines.high-definition/Runtime/Sky/SkyRenderingContext.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ internal class SkyRenderingContext
1414
public CubemapArray skyboxBSDFCubemapArray { get; private set; }
1515
public bool supportsConvolution { get; private set; } = false;
1616

17+
internal bool ambientProbeIsReady = false;
18+
1719
public SkyRenderingContext(int resolution, int bsdfCount, bool supportsConvolution, SphericalHarmonicsL2 ambientProbe, string name)
1820
{
1921
m_AmbientProbe = ambientProbe;
@@ -71,6 +73,8 @@ public void OnComputeAmbientProbeDone(AsyncGPUReadbackRequest request)
7173
m_AmbientProbe[channel, coeff] = result[channel * 9 + coeff];
7274
}
7375
}
76+
77+
ambientProbeIsReady = true;
7478
}
7579
}
7680
}

0 commit comments

Comments
 (0)