Skip to content

Commit c9654c9

Browse files
committed
Fix default lighting data was negatively affecting Adaptive Probe Volumes in additive scenes:
- Default scenes have a default lighting data asset assigned to it. - This default lighting data causes the render to look different, and this is most noticeable on lilToon 2.3.0. - Fix by checking if the scene currently uses the default lighting data. If it does, set it to null for the duration of the lightbox usage. - This should fix hai-vr/lightbox-viewer-urp#1 in Lightbox Viewer URP.
1 parent e5ce968 commit c9654c9

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Packages/dev.hai-vr.lightbox-viewer/Scripts/Editor/LightboxViewerRenderQueue.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ namespace Hai.LightboxViewer.Scripts.Editor
1313
{
1414
public class LightboxViewerRenderQueue
1515
{
16+
private const string DefaultLightingDataAssetPath = "Resources/unity_builtin_extra";
17+
1618
// TODO: We may need to set this to false on older versions of Unity, as ObjectChangeEvent was added in Unity 2021.
1719
internal const bool WhenInEditMode_ReuseCachedCopy = true;
1820
internal const bool WhenInEditMode_DestroyAllMonoBehaviours = true;
@@ -24,6 +26,8 @@ public class LightboxViewerRenderQueue
2426
private int _queueSize;
2527
private Scene _openScene;
2628
private bool _sceneLoaded;
29+
private bool _wasUsingDefaultLightingData;
30+
private LightingDataAsset _previousLightingData;
2731
private Texture[] _textures = new Texture[1];
2832
private string[] _names = new string[1];
2933
private int _width = 512;
@@ -452,6 +456,12 @@ private void TrueRender(GameObject copy)
452456

453457
public void LoadLightbox(SceneAsset lightbox)
454458
{
459+
_wasUsingDefaultLightingData = IsUsingDefaultLightingData();
460+
if (_wasUsingDefaultLightingData)
461+
{
462+
_previousLightingData = Lightmapping.lightingDataAsset;
463+
Lightmapping.lightingDataAsset = null;
464+
}
455465
_openScene = EditorSceneManager.OpenScene(AssetDatabase.GetAssetPath(lightbox), OpenSceneMode.Additive);
456466
DefinitionNullable = GetDefinitionOrNull();
457467
_foundDefinition = DefinitionNullable != null;
@@ -489,6 +499,10 @@ public void UnloadLightbox()
489499
{
490500
if (_sceneLoaded)
491501
{
502+
if (_wasUsingDefaultLightingData)
503+
{
504+
Lightmapping.lightingDataAsset = _previousLightingData;
505+
}
492506
EditorSceneManager.CloseScene(_openScene, true);
493507
LightProbes.Tetrahedralize();
494508
_sceneLoaded = false;
@@ -565,5 +579,17 @@ private GameObject[] AllApplicableLightboxes()
565579
.Where(lightbox => !lightbox.CompareTag("EditorOnly"))
566580
.ToArray();
567581
}
582+
583+
private static bool IsUsingDefaultLightingData()
584+
{
585+
var lightingDataAsset = Lightmapping.lightingDataAsset;
586+
if (lightingDataAsset != null)
587+
{
588+
var assetPath = AssetDatabase.GetAssetPath(lightingDataAsset);
589+
return assetPath == DefaultLightingDataAssetPath;
590+
}
591+
592+
return false;
593+
}
568594
}
569595
}

0 commit comments

Comments
 (0)