Skip to content

Commit 5ad49f8

Browse files
Fixed two issues with sky static lighting. #1775
1 parent d0f2506 commit 5ad49f8

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
5353
- Fixed an issue where opening the look dev window with the light theme would make the window blink and eventually crash unity.
5454
- Fixed a serialization issue, preventing quality level parameters to undo/redo and update scene view on change.
5555
- Fixed an issue where look dev lighting would go black when a new scene is loaded.
56+
- Fixed a static lighting flickering issue caused by having an active planar probe in the scene while rendering inspector preview.
57+
- Fixed an issue where even when set to OnDemand, the sky lighting would still be updated when changing sky parameters.
5658

5759
### Changed
5860
- Changed extensions of shader CAS include files.

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,7 @@ internal void ForceRenderingNextUpdate()
437437

438438
void UpdateProbeName()
439439
{
440-
// TODO: ask if this is ok:
441-
if (settings.type == ProbeSettings.ProbeType.PlanarProbe)
440+
if (settings.type == ProbeSettings.ProbeType.ReflectionProbe)
442441
{
443442
for (int i = 0; i < 6; i++)
444443
probeName[i] = $"Reflection Probe RenderCamera ({name}: {(CubemapFace)i})";

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,13 @@ internal static void Sanitize(ref FrameSettings sanitizedFrameSettings, Camera c
699699
// When MSAA is enabled we disable Fptl as it become expensive compare to cluster
700700
// In HD, MSAA is only supported for forward only rendering, no MSAA in deferred mode (for code complexity reasons)
701701
sanitizedFrameSettings.bitDatas[(int)FrameSettingsField.FPTLForForwardOpaque] &= !msaa;
702+
703+
// We disable reflection probes and planar reflections in regular preview rendering for two reasons.
704+
// - Performance: Realtime reflection are 99% not necessary in previews
705+
// - Static lighting consistency: When rendering a planar probe from a preview camera it may induce a recomputing of the static lighting
706+
// but with the preview lights which are different from the ones in the scene and will change the result inducing flickering.
707+
sanitizedFrameSettings.bitDatas[(int)FrameSettingsField.ReflectionProbe] &= !preview;
708+
sanitizedFrameSettings.bitDatas[(int)FrameSettingsField.PlanarProbe] &= !preview;
702709
}
703710

704711
/// <summary>Aggregation is default with override of the renderer then sanitized depending on supported features of hdrpasset.</summary>

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,18 @@ public void UpdateEnvironment( HDCamera hdCamera,
727727
m_BuiltinParameters.frameIndex = frameIndex;
728728
m_BuiltinParameters.skySettings = skyContext.skySettings;
729729

730+
// When update is not requested and the context is already valid (ie: already computed at least once),
731+
// we need to early out in two cases:
732+
// - updateMode is "OnDemand" in which case we never update unless explicitly requested
733+
// - updateMode is "Realtime" in which case we only update if the time threshold for realtime update is passed.
734+
if (IsCachedContextValid(skyContext) && !updateRequired)
735+
{
736+
if (skyContext.skySettings.updateMode.value == EnvironmentUpdateMode.OnDemand)
737+
return;
738+
else if (skyContext.skySettings.updateMode.value == EnvironmentUpdateMode.Realtime && skyContext.currentUpdateTime < skyContext.skySettings.updatePeriod.value)
739+
return;
740+
}
741+
730742
int skyHash = ComputeSkyHash(hdCamera, skyContext, sunLight, ambientMode, staticSky);
731743
bool forceUpdate = updateRequired;
732744

@@ -745,6 +757,7 @@ public void UpdateEnvironment( HDCamera hdCamera,
745757
{
746758
using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.UpdateSkyEnvironment)))
747759
{
760+
// Debug.Log("Update Sky Lighting");
748761
RenderSkyToCubemap(skyContext);
749762

750763
if (updateAmbientProbe)
@@ -823,7 +836,7 @@ public void UpdateEnvironment(HDCamera hdCamera, ScriptableRenderContext renderC
823836
if ((ambientMode == SkyAmbientMode.Static || forceStaticUpdate) && hdCamera.camera.cameraType != CameraType.Preview)
824837
{
825838
m_StaticLightingSky.skySettings = staticLightingSky != null ? staticLightingSky.skySettings : null;
826-
UpdateEnvironment(hdCamera, renderContext, m_StaticLightingSky, sunLight, m_StaticSkyUpdateRequired, true, true, SkyAmbientMode.Static, frameIndex, cmd);
839+
UpdateEnvironment(hdCamera, renderContext, m_StaticLightingSky, sunLight, m_StaticSkyUpdateRequired || m_UpdateRequired, true, true, SkyAmbientMode.Static, frameIndex, cmd);
827840
m_StaticSkyUpdateRequired = false;
828841
}
829842

0 commit comments

Comments
 (0)