Skip to content

Commit eecd5e6

Browse files
adrien-de-tocquevilleEvergreen
authored andcommitted
[HDRP] Fix static lighting sky used when baking
The static lighting sky used when baking was kinda random Now it always use the one from the active scene
1 parent 935e979 commit eecd5e6

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

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

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Linq;
33
using System.Collections.Generic;
4+
using UnityEngine.SceneManagement;
45
using UnityEngine.Experimental.Rendering;
56
using UnityEngine.Rendering.RenderGraphModule;
67

@@ -179,8 +180,9 @@ class SkyManager
179180
public static Dictionary<int, Type> cloudTypesDict { get { if (m_CloudTypesDict == null) UpdateCloudTypes(); return m_CloudTypesDict; } }
180181

181182
// This list will hold the static lighting sky that should be used for baking ambient probe.
182-
// In practice we will always use the last one registered but we use a list to be able to roll back to the previous one once the user deletes the superfluous instances.
183-
private static List<StaticLightingSky> m_StaticLightingSkies = new List<StaticLightingSky>();
183+
// We can have multiple but we only want to use the one from the active scene
184+
private static Dictionary<int, StaticLightingSky> m_StaticLightingSkies = new ();
185+
private static StaticLightingSky m_ActiveStaticSky;
184186

185187
// Only show the procedural sky upgrade message once
186188
static bool logOnce = true;
@@ -1236,7 +1238,7 @@ public void UpdateEnvironment(RenderGraph renderGraph, HDCamera hdCamera, Light
12361238
// because we only maintain one static sky. Since we don't care that the static lighting may be a bit different in the preview we never recompute
12371239
// and we use the one from the main camera.
12381240
bool forceStaticUpdate = false;
1239-
StaticLightingSky staticLightingSky = GetStaticLightingSky();
1241+
m_ActiveStaticSky = m_StaticLightingSkies.GetValueOrDefault(SceneManager.GetActiveScene().GetHashCode(), null);
12401242
#if UNITY_EDITOR
12411243
// In the editor, we might need the static sky ready for baking lightmaps/lightprobes regardless of the current ambient mode so we force it to update in this case if it's not been computed yet..
12421244
// We always force an update of the static sky when we're in scene view mode. Previous behaviour was to prevent forced updates if the hash of the static sky was non-null, but this was preventing
@@ -1246,9 +1248,12 @@ public void UpdateEnvironment(RenderGraph renderGraph, HDCamera hdCamera, Light
12461248
#endif
12471249
if ((ambientMode == SkyAmbientMode.Static || forceStaticUpdate) && hdCamera.camera.cameraType != CameraType.Preview)
12481250
{
1249-
m_StaticLightingSky.skySettings = staticLightingSky != null ? staticLightingSky.skySettings : null;
1250-
m_StaticLightingSky.cloudSettings = staticLightingSky != null ? staticLightingSky.cloudSettings : null;
1251-
m_StaticLightingSky.volumetricClouds = staticLightingSky != null ? staticLightingSky.volumetricClouds : null;
1251+
if (m_ActiveStaticSky != null)
1252+
{
1253+
m_StaticLightingSky.skySettings = m_ActiveStaticSky.skySettings;
1254+
m_StaticLightingSky.cloudSettings = m_ActiveStaticSky.cloudSettings;
1255+
m_StaticLightingSky.volumetricClouds = m_ActiveStaticSky.volumetricClouds;
1256+
}
12521257
UpdateEnvironment(renderGraph, hdCamera, m_StaticLightingSky, sunLight, m_StaticSkyUpdateRequired || m_UpdateRequired, true, true, SkyAmbientMode.Static);
12531258
m_StaticSkyUpdateRequired = false;
12541259
}
@@ -1595,34 +1600,25 @@ public TextureHandle RenderOpaqueAtmosphericScattering(RenderGraph renderGraph,
15951600

15961601
static public StaticLightingSky GetStaticLightingSky()
15971602
{
1598-
if (m_StaticLightingSkies.Count == 0)
1599-
return null;
1600-
else
1601-
return m_StaticLightingSkies[m_StaticLightingSkies.Count - 1];
1603+
return m_ActiveStaticSky;
16021604
}
16031605

16041606
static public void RegisterStaticLightingSky(StaticLightingSky staticLightingSky)
16051607
{
1606-
if (!m_StaticLightingSkies.Contains(staticLightingSky))
1608+
#if UNITY_EDITOR
1609+
if (staticLightingSky.staticLightingSkyUniqueID == (int)SkyType.Procedural && !skyTypesDict.TryGetValue((int)SkyType.Procedural, out var dummy))
16071610
{
1608-
if (m_StaticLightingSkies.Count != 0)
1609-
{
1610-
Debug.LogWarning("One Static Lighting Sky component was already set for baking, only the latest one will be used.");
1611-
}
1612-
1613-
if (staticLightingSky.staticLightingSkyUniqueID == (int)SkyType.Procedural && !skyTypesDict.TryGetValue((int)SkyType.Procedural, out var dummy))
1614-
{
1615-
Debug.LogError("You are using the deprecated Procedural Sky for static lighting in your Scene. You can still use it but, to do so, you must install it separately. To do this, open the Package Manager window and import the 'Procedural Sky' sample from the HDRP package page, then close and re-open your project without saving.");
1616-
return;
1617-
}
1618-
1619-
m_StaticLightingSkies.Add(staticLightingSky);
1611+
Debug.LogError("You are using the deprecated Procedural Sky for static lighting in your Scene. You can still use it but, to do so, you must install it separately. To do this, open the Package Manager window and import the 'Procedural Sky' sample from the HDRP package page, then close and re-open your project without saving.");
1612+
return;
16201613
}
1614+
#endif
1615+
1616+
m_StaticLightingSkies[staticLightingSky.gameObject.scene.GetHashCode()] = staticLightingSky;
16211617
}
16221618

16231619
static public void UnRegisterStaticLightingSky(StaticLightingSky staticLightingSky)
16241620
{
1625-
m_StaticLightingSkies.Remove(staticLightingSky);
1621+
m_StaticLightingSkies.Remove(staticLightingSky.gameObject.scene.GetHashCode());
16261622
}
16271623

16281624
public Texture2D ExportSkyToTexture(Camera camera)

Packages/com.unity.shaderanalysis/CHANGELOG.md.meta

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)