diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 71ba1db8fe2..95805be1978 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -623,6 +623,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added a fix script to handle the warning 'referenced script in (GameObject 'SceneIDMap') is missing' - Fix Wizard load when none selected for RenderPipelineAsset - Fixed issue with unclear naming of debug menu for decals. +- Fixed issue with reflection probes in realtime time mode with OnEnable baking having wrong lighting with sky set to dynamic (case 1238047). ### Changed - Color buffer pyramid is not allocated anymore if neither refraction nor distortion are enabled diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Reflection/HDProbe.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Reflection/HDProbe.cs index d7acda444b7..145981a32b3 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Reflection/HDProbe.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Reflection/HDProbe.cs @@ -428,6 +428,13 @@ public virtual void PrepareCulling() { } /// public void RequestRenderNextUpdate() => m_WasRenderedSinceLastOnDemandRequest = false; + // Forces the re-rendering for both OnDemand and OnEnable + internal void ForceRenderingNextUpdate() + { + m_WasRenderedSinceLastOnDemandRequest = false; + wasRenderedAfterOnEnable = false; + } + void UpdateProbeName() { // TODO: ask if this is ok: diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 0ac757e2b14..7d3d93693fa 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -1620,6 +1620,14 @@ ref _cullingResults continue; } + // HACK! We render the probe until we know the ambient probe for the associated sky context is ready. + // For one-off rendering the dynamic ambient probe will be set to black until they are not processed, leading to faulty rendering. + // So we enqueue another rendering and then we will not set the probe texture until we have rendered with valid ambient probe. + if (!m_SkyManager.HasSetValidAmbientProbe(hdCamera)) + { + visibleProbe.ForceRenderingNextUpdate(); + } + hdCamera.parentCamera = parentCamera; // Used to inherit the properties of the view HDAdditionalCameraData hdCam; @@ -1666,26 +1674,30 @@ ref _cullingResults // TODO: store DecalCullResult }; - // As we render realtime texture on GPU side, we must tag the texture so our texture array cache detect that something have change - visibleProbe.realtimeTexture.IncrementUpdateCount(); - - if (cameraSettings.Count > 1) + if (m_SkyManager.HasSetValidAmbientProbe(hdCamera)) { - var face = (CubemapFace)j; - request.target = new RenderRequest.Target + // As we render realtime texture on GPU side, we must tag the texture so our texture array cache detect that something have change + visibleProbe.realtimeTexture.IncrementUpdateCount(); + + if (cameraSettings.Count > 1) { - copyToTarget = visibleProbe.realtimeTexture, - face = face - }; - } - else - { - request.target = new RenderRequest.Target + var face = (CubemapFace)j; + request.target = new RenderRequest.Target + { + copyToTarget = visibleProbe.realtimeTexture, + face = face + }; + } + else { - id = visibleProbe.realtimeTexture, - face = CubemapFace.Unknown - }; + request.target = new RenderRequest.Target + { + id = visibleProbe.realtimeTexture, + face = CubemapFace.Unknown + }; + } } + renderRequests.Add(request); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs index 52bb03f685c..810ebdafbd6 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs @@ -413,6 +413,24 @@ internal SphericalHarmonicsL2 GetAmbientProbe(HDCamera hdCamera) return GetAmbientProbe(hdCamera.lightingSky); } + internal bool HasSetValidAmbientProbe(HDCamera hdCamera) + { + SkyAmbientMode ambientMode = hdCamera.volumeStack.GetComponent().skyAmbientMode.value; + if (ambientMode == SkyAmbientMode.Static) + return true; + + if (hdCamera.skyAmbientMode == SkyAmbientMode.Dynamic && hdCamera.lightingSky != null && + hdCamera.lightingSky.IsValid() && IsCachedContextValid(hdCamera.lightingSky)) + { + ref CachedSkyContext cachedContext = ref m_CachedSkyContexts[hdCamera.lightingSky.cachedSkyRenderingContextId]; + var renderingContext = cachedContext.renderingContext; + return renderingContext.ambientProbeIsReady; + } + + return false; + + } + internal void SetupAmbientProbe(HDCamera hdCamera) { // Working around GI current system diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyRenderingContext.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyRenderingContext.cs index d03791d1d2b..9016477b396 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyRenderingContext.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyRenderingContext.cs @@ -14,6 +14,8 @@ internal class SkyRenderingContext public CubemapArray skyboxBSDFCubemapArray { get; private set; } public bool supportsConvolution { get; private set; } = false; + internal bool ambientProbeIsReady = false; + public SkyRenderingContext(int resolution, int bsdfCount, bool supportsConvolution, SphericalHarmonicsL2 ambientProbe, string name) { m_AmbientProbe = ambientProbe; @@ -71,6 +73,8 @@ public void OnComputeAmbientProbeDone(AsyncGPUReadbackRequest request) m_AmbientProbe[channel, coeff] = result[channel * 9 + coeff]; } } + + ambientProbeIsReady = true; } } }