Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Unity [2020.1] New Feature - Lighting Settings Asset

Discussion in 'Global Illumination' started by kristijonas_unity, Feb 21, 2020.

  1. kristijonas_unity

    kristijonas_unity

    Unity Technologies

    Joined:
    Feb 8, 2018
    Posts:
    497
    LSA-FeatureImage.jpg
    A simple diagram showing how to access the feature via the UI.

    Overview
    This feature was developed by Jennifer Nordwall (@JenniferNordwall).

    Improvements introduced by the Lighting Settings Asset (LSA) feature
    • Ability to change settings on multiple scenes and having more control in multi-bake scenarios.
    • Lighting settings are no longer a part of the Unity scene file; instead they are now located in an independent file that stores all the settings related to pre-computed GI.
    Benefits to the users
    • Lighting settings can now be easily shared between different scenes.
    • Ability to toggle between different lighting settings quickly.
    • Lighting settings asset file can easily be assigned to a scene, removed or modified (either through the Inspector UI or API). This allows for much faster iterations when authoring lighting settings.
    • A single lighting settings asset file can be used by multiple scenes without need to manually tweak the settings for every scene.
    Setup instructions
    Via the UI
    1. Open Lighting window by navigating to Window > Rendering > Lighting.
    2. Click on New Lighting Settings button located at the top of the window.
    3. Your newly created Lighting Settings Asset is going to be assigned and located next to the opened scene's file.
    4. Either select the asset directly from the Project folder, or edit the asset in the Lighting window after assigning it to the Lighting Settings slot.
    Note: Currently, the Lighting Settings asset will be automatically created in the folder located next to the Unity scene file when opening the scene after upgrading to the recent 2020.1.0/trunk branch, but only if the lighting settings of this upgraded scene were changed from the default values. We are going change that behavior for the upcoming 2020.1.0 beta version, so that the asset would only be created after making changes to the lighting settings of the upgraded scene (i.e. changing the lightmapper backend) and then manually saving the scene.

    Via C# code
    Creating the asset:
    Code (CSharp):
    1. Lightmapping.lightingSettings = new LightingSettings();
    2. ProjectWindowUtil.CreateAsset(Lightmapping.lightingSettings, "My new lighting settings asset.lighting");
    Setting directionality mode:
    Code (CSharp):
    1. Lightmapping.lightingSettings.directionalityMode = value;
    Feature access & feedback
    You can get access to the feature by downloading the latest 2020.1 alpha build via the Unity Hub, or via this link - https://unity3d.com/alpha/2020.1a#downloads. We are looking forward to hearing your feedback!
     
    Last edited: Mar 9, 2020
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    7,051
    Is this not optional? Do I have to clutter my project with a gazillion lighting settings asset files so I can safely edit the settings of a certain scene without affecting other scenes?
     
    florianBrn and astracat111 like this.
  3. JenniferNordwall

    JenniferNordwall

    Unity Technologies

    Joined:
    Sep 19, 2016
    Posts:
    159
    Just put the settings file next to you Lighting Data Asset, or create it from code :)
     
  4. unit_dev123

    unit_dev123

    Joined:
    Feb 10, 2020
    Posts:
    996
    thank u Jennifer, good work!
     
  5. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    7,051
    Is being unable to edit lighting settings from the Lighting tab an intended design decision, or is it a bug?

    (I can only change settings by clicking the settings asset and editing in inspector, the lighting window itself does not allow me to type new values).
     
  6. unit_dev123

    unit_dev123

    Joined:
    Feb 10, 2020
    Posts:
    996
    Not yet ready maybe remember this is wip
     
  7. kristijonas_unity

    kristijonas_unity

    Unity Technologies

    Joined:
    Feb 8, 2018
    Posts:
    497
    Make sure that you have a LSA assigned in the Lighting Settings window. If there's no asset assigned, you will not be able to edit any values in the Lighting Settings window.
     
  8. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    7,051
    Nah, it's some sort of bug. The asset is assigned correctly. It happens after I do a bake and it's only for inputting values with keyboard. If I click and drag to increase/decrease values, then it works properly (and uses the correct values). If I type values, nothing happens.

    Probably some sort of UI bug that is unrelated to the LSA feature.
     
  9. DavidLlewelyn

    DavidLlewelyn

    Unity Technologies

    Joined:
    Aug 14, 2012
    Posts:
    26
    @AcidArrow is the Lighting Settings Asset actually assigned in the Lighting window? If it is not assigned, you will be viewing the default values which are not editable by design.
     
  10. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    7,051
    Yes. And also I wasn’t viewing the default values.

    I will post a short video if I find the time later today.
     
  11. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    7,051
    Here's a video @DavidLlewelyn and @kristijonas_unity

    Some notes:

    1. You need to start a bake and let if finish normally by itself for it to repro. Before I do that it seems to work fine. I'm using the GPU baker, not sure if it matters.
    2. When I'm selecting the various fields in the video I am typing things. Please don't ask me to record myself trying to type things.
    3. I can edit values with a mouse, just not with a keyboard.
    4. At around 11seconds, I am selecting the asset directly and editing it in inspector (just clarifying because I cut off the top by mistake). I can edit the asset in the inspector fine with both mouse and keyboard. And as you can see they update the settings in the lighting settings window, meaning the asset is set correctly.
    5. I hope you can see that this mean that the asset is properly set in the lighting settings.
    6. I will not submit a bug report, if this is not enough for you to fix it, then it might as well stay unfixed.

    EDIT: 7. I did not try it in the video, but maybe you can take my word for it, copy pasting (with keyboard) also works.

     
    Last edited: Feb 24, 2020
    Jesper-Mortensen likes this.
  12. V_Kalinichenko

    V_Kalinichenko

    Unity Technologies

    Joined:
    Apr 15, 2015
    Posts:
    14
    Hey, thanks a lot for finding this bug! FYI, I've submitted it here: https://issuetracker.unity3d.com/is...-keyboard-after-switching-between-editor-tabs
    It looks like it's unrelated to the LSA feature, as this is a regression introduced in 2020.1.0a23.
    In any case, our developers will take a look at it and fix it as soon as possible.
    Cheers!
     
    kristijonas_unity and AcidArrow like this.
  13. CD_MT

    CD_MT

    Joined:
    Jul 18, 2019
    Posts:
    7
    Nice Work - this will be a massive improvement, thanks!... very keen to try this as soon as I get a chance.

    Could you tell me @JenniferNordwall @DavidLlewelyn - how these settings relate to baking a scene comprised from several sub scenes?

    Light settings currently exist for each subscene. Though we endeavor to maintain a 'lighting scene' which holds our required bake settings, the settings will will invariably differ across the other subscenes. As a result we regularly get into a tangle due to the 'wrong' subscene being active :

    The overall 'look' may immediately differ (skybox, fog etc)
    Baking may produce several directories of redundant baked data (named depending on active subScene)
    + AutoGenerate accidentally left on in any subscene exacerbates the above issue.

    Clearly the first of these issues is fixed with your new settings - but what of the actual baking? Can the new settings also provide the 'path' to which the baked data is written, for example?
     
  14. CD_MT

    CD_MT

    Joined:
    Jul 18, 2019
    Posts:
    7
  15. JenniferNordwall

    JenniferNordwall

    Unity Technologies

    Joined:
    Sep 19, 2016
    Posts:
    159
    Hi

    Currently, skybox and fog are part of the scene and render settings, which we haven't moved to its separate file yet (and might never do since most of those things will be redone in the SRP workflow). So these settings will be attached to the active scene (which is also being used to fetch the current lighting settings). The active scene workflow is so rooted into how everything works in Unity, but hopefully the lighting settings workflow helped a bit with this.

    As for the bake location, what problem will this solve? I just want to fully understand your situation and why this would be a good solution for you.

    Thanks :)
     
  16. unknowndevice

    unknowndevice

    Joined:
    Sep 13, 2016
    Posts:
    64
    It would be extremely useful to have the lighting environment settings as a .asset. We modify the ambient color, and skybox as part of in game "transformation events" in our scenes. Having the environment settings as asset would make previewing and setting this up in the editor much more straight forward.

    Right not we just use a scriptable with a custom script, we can obviously keep doing this, but it would be easier if it was supported directly.
     
  17. zapposh

    zapposh

    Joined:
    Nov 12, 2016
    Posts:
    107
    Why is this being generated every time I save a scene in 2020.1?
    I have a 2D renderer, no lights in any scene, and all lighting settings are disabled everywhere in the project and URP.
    All sprites use the UNLIT material.
    Is this a bug?

    I keep deleting the files every time they are generated to stop them clogging up my hierarchy for nothing.
     
  18. Earthshine

    Earthshine

    Joined:
    Jul 24, 2020
    Posts:
    1
    It seems to be no way to choose default lighting settings (Settings.lighting). I've switched a project to 2020.1 and all the scenes got default settings, except one that got (None) and would only receive a separate settings.lighting asset. It's a mild inconvenience but still looks like a bug.
     
  19. Bentoon

    Bentoon

    Joined:
    Apr 26, 2013
    Posts:
    76
    Thank you all!
    I am getting really weird maps though now ...
    So I disabled all lights and probes in scene. Everything is set to Bake in Lighting tab. I even took off all environmental setting and I still get a bake but only generated @ runtime..?

    Weird right?
     

    Attached Files:

  20. darthbator

    darthbator

    Joined:
    Jan 21, 2012
    Posts:
    165
    Is there a way to use the global asset by default and not generate an individual file for every scene now? The project clutter is highly undesirable for the majority of smaller unity projects that don't require per scene global illumination settings.
     
    astracat111 likes this.
  21. unknowndevice

    unknowndevice

    Joined:
    Sep 13, 2016
    Posts:
    64
    If you just make an asset, and assign it to every scene it'll stop generating them.
     
  22. JenniferNordwall

    JenniferNordwall

    Unity Technologies

    Joined:
    Sep 19, 2016
    Posts:
    159
    It only does this when it upgrades so that you don't loose your settings. Just assign the LSA to null, and remove the files :) It's not the perfect solution, but I didn't wanna risk destroying peoples settings.
     
  23. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    624
    I'm still looking for how to turn the creation of a brand new file off when saving a scene. For now I'm just deleting the lighting settings file, because I simply use real time shadows with no baked lighting (saves MB on disk and is faster to develop for).

    I have an OnRenderObject() and looking to assign the same default lighting settings object to every scene.

    I've got:

    Code (CSharp):
    1.  
    2. //On start:
    3. LightingSettings lightingSettings = new LightingSettings();
    4.  
    5. if (lightingSettings. ??? == null)
    6.    lightingSettings. ??? = Resources.Load("LightingSettings/") etc etc...
    Not sure how to go about this...
     
  24. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    624
    Since I didn't want to use baked lighting and couldn't figure out how to load a lighting settings file from Load.Resources, I just put this in the beginning of the script that I have on every scene.

    Again, the complication is that I'm not wanting to use any baked lighting whatsoever:


    Code (CSharp):
    1.     public LightingSettings SetLightingSettings(LightingSettings lightingSettings)
    2.     {
    3.         lightingSettings = new LightingSettings();
    4.         lightingSettings.albedoBoost = 0;
    5.         lightingSettings.ao = false;
    6.         lightingSettings.aoExponentDirect = 0;
    7.         lightingSettings.aoExponentIndirect = 0;
    8.         lightingSettings.aoMaxDistance = 0;
    9.         lightingSettings.autoGenerate = false;
    10.         lightingSettings.bakedGI = false;
    11.         lightingSettings.bounces = 0;
    12.         lightingSettings.compressLightmaps = false;
    13.         lightingSettings.denoiserTypeAO = LightingSettings.DenoiserType.None;
    14.         lightingSettings.denoiserTypeDirect = LightingSettings.DenoiserType.None;
    15.         lightingSettings.denoiserTypeIndirect = LightingSettings.DenoiserType.None;
    16.         lightingSettings.directionalityMode = LightmapsMode.NonDirectional;
    17.         lightingSettings.directSampleCount = 32;
    18.         lightingSettings.environmentSampleCount = 256;
    19.         lightingSettings.exportTrainingData = false;
    20.         lightingSettings.extractAO = false;
    21.         lightingSettings.filteringAtrousPositionSigmaAO = 1;
    22.         lightingSettings.filteringAtrousPositionSigmaDirect = 0.5f;
    23.         lightingSettings.filteringAtrousPositionSigmaIndirect = 2;
    24.         lightingSettings.filteringGaussRadiusAO = 2;
    25.         lightingSettings.filteringGaussRadiusDirect = 1;
    26.         lightingSettings.filteringMode = LightingSettings.FilterMode.None;
    27.         lightingSettings.filterTypeAO = LightingSettings.FilterType.None;
    28.         lightingSettings.filterTypeDirect = LightingSettings.FilterType.None;
    29.         lightingSettings.filterTypeIndirect = LightingSettings.FilterType.None;
    30.         lightingSettings.indirectResolution = 0;
    31.         lightingSettings.indirectSampleCount = 512;
    32.         lightingSettings.indirectScale = 1;
    33.         lightingSettings.lightmapMaxSize = 1;
    34.         lightingSettings.lightmapPadding = 1;
    35.         lightingSettings.lightmapper = LightingSettings.Lightmapper.ProgressiveGPU;
    36.         lightingSettings.lightmapResolution = 1;
    37.         lightingSettings.lightProbeSampleCountMultiplier = 4;
    38.         lightingSettings.mixedBakeMode = MixedLightingMode.Shadowmask;
    39.         lightingSettings.name = "BASIC";
    40.         lightingSettings.prioritizeView = true;
    41.         lightingSettings.realtimeEnvironmentLighting = false;
    42.         lightingSettings.realtimeGI = false;
    43.         lightingSettings.russianRouletteStartBounce = 0;
    44.         lightingSettings.sampling = 0;
    45.         lightingSettings.trainingDataDestination = "";
    46.  
    47.         return lightingSettings;
    48.     }
    49.  
     
  25. arielsan

    arielsan

    Joined:
    Dec 3, 2013
    Posts:
    40
    Is there a way to turn it off or at least select the default settings in some place and then every scene uses that one? we have tons of scenes and each time someone modify one of them, we get a new auto generated lighting settings we don't use nor want.

    Yes, I know I could open each scene with a script and maybe configure the default setting, I was hoping to set something that would work in the long term (new scenes), I suppose I could create a post import action to set the default settings too.
     
    astracat111 likes this.
  26. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    624
    @arielsan If you wanna give a crack at it, I'm working on an editor script that's supposed to set the lighting settings data object to a default asset in the editor if it's equal to null or not equal to the default one you choose.

    It seems to be Lightmapping.lightingDataAsset, but I can't get it to change. It also says that the scene needs to be re-opened before the changes are made (odd), but even with this code it doesn't seem to want to change:

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3. using UnityEditor.SceneManagement;
    4. using UnityEngine.SceneManagement;
    5.  
    6. [InitializeOnLoad]
    7. class EditorUpdate
    8. {
    9.  
    10.     public static string GlobalLightingSettingsName = "Default";
    11.  
    12.     static EditorUpdate()
    13.     {
    14.         EditorApplication.update += Update;
    15.     }
    16.  
    17.     static void Update()
    18.     {
    19.         Debug.Log(Lightmapping.lightingDataAsset);
    20.  
    21.         if (Lightmapping.lightingDataAsset != null)
    22.             Debug.Log(Lightmapping.lightingDataAsset.name);
    23.  
    24.         if (Lightmapping.lightingDataAsset == null)
    25.             SwitchLightingSettingsToDefault();
    26.  
    27.         if (Lightmapping.lightingDataAsset != null)
    28.         {
    29.             if (Lightmapping.lightingDataAsset.name != GlobalLightingSettingsName)
    30.                 SwitchLightingSettingsToDefault();
    31.         }
    32.  
    33.     }
    34.  
    35.     private static void SwitchLightingSettingsToDefault()
    36.     {
    37.         Debug.Log("switch here");
    38.  
    39.         string path = "LightingSettings/" + GlobalLightingSettingsName;
    40.  
    41.         Debug.Log("path = " + path);
    42.  
    43.         Lightmapping.lightingDataAsset = Resources.Load(path) as LightingDataAsset;
    44.         EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
    45.     }
    46.  
    47. }
     
  27. arielsan

    arielsan

    Joined:
    Dec 3, 2013
    Posts:
    40
    Thanks @astracat111 !! yeah, ended up with a script that opens all scenes and reset to our own lighting settings, with everything turned off.

    Code (CSharp):
    1.  
    2. [MenuItem("Assets/Refactors/Remove Lighting Settings from Scenes", false, 21)]
    3. public static void RemoveLightingSettingsFromAllScenes()
    4. {
    5.     var allScenesGuids = new List<string>();
    6.  
    7.     // Here we filter by all assets of type scene but under Assets folder to avoid all other scenes from
    8.     // external packages.
    9.     allScenesGuids.AddRange(AssetDatabase.FindAssets("t:scene", new string[]
    10.     {
    11.         "Assets"
    12.     }));
    13.  
    14.     Debug.Log("count: " + allScenesGuids.Count);
    15.  
    16.     EditorUtility.DisplayProgressBar("Removing lighting settings", "Starting...", 0);
    17.     EditorSceneManager.sceneOpened += RemoveLightingSettings;
    18.    
    19.     var allScenesCount = allScenesGuids.Count;
    20.     for (var i = 0; i < allScenesCount; i++)
    21.     {
    22.         var sceneGuid = allScenesGuids[i];
    23.         var scenePath = AssetDatabase.GUIDToAssetPath(sceneGuid);
    24.        
    25.         try
    26.         {
    27.             EditorUtility.DisplayProgressBar("Removing lighting settings", scenePath,
    28.                 i / (float) allScenesCount);
    29.             EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Single);
    30.         }
    31.         catch (Exception ex)
    32.         {
    33.             Debug.Log("ERROR: " + ex.Message);
    34.         }
    35.     }
    36.  
    37.     EditorSceneManager.sceneOpened -= RemoveLightingSettings;
    38.     EditorUtility.ClearProgressBar();
    39. }
    40.  
    41. private static void RemoveLightingSettings(Scene scene, OpenSceneMode mode)
    42. {
    43.     var lightingSettings = AssetDatabase.LoadAssetAtPath<LightingSettings>("Assets/Bundles/LightingSettings.lighting");
    44.     Lightmapping.lightingSettings = lightingSettings;
    45.     // Lightmapping.lightingDataAsset = null;
    46.     EditorSceneManager.MarkSceneDirty(scene);
    47.     EditorSceneManager.SaveScene(scene);
    48. }
    49.  
    I am thinking about creating an editor on open scene callback static method which does this, so new scenes are also configured.
     
    astracat111 likes this.
  28. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    624
    I've also tried:

    Code (CSharp):
    1. Lightmapping.lightingDataAsset = AssetDatabase.LoadAssetAtPath(Application.dataPath + "/LightingSettings/Default.lighting", typeof(LightingDataAsset)) as LightingDataAsset;
    But still can't get this:



    To change through code in the editor...
     
  29. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    624
    Oooh okay, you simply do:

    Code (CSharp):
    1.   var lightingSettings = AssetDatabase.LoadAssetAtPath<LightingSettings>("Assets/Bundles/LightingSettings.lighting");
    2.     Lightmapping.lightingSettings = lightingSettings;
    3.     // Lightmapping.lightingDataAsset = null;
    4.     EditorSceneManager.MarkSceneDirty(scene);
    5.     EditorSceneManager.SaveScene(scene);
    I'll test that out and see what works...

    EDIT: Nope, I've still got nothing when I do:

    Code (CSharp):
    1. Lightmapping.lightingSettings = AssetDatabase.LoadAssetAtPath(Application.dataPath + "/LightingSettings/" + GlobalLightingSettingsName + ".lighting", typeof(LightingSettings)) as LightingSettings;
     
  30. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    624
    Success! Fixed it, now if you want a single lighting settings this editor script (put in an Editor folder) will automatically keep every scene always at the lighting settings you specify with 'LightingSettingsName' and 'LightingSettingsAssetPath'.

    No need to create a whole saving every scene script, just open your scenes, it'll mark it as dirty and it'll save them. If you try to change the lighting settings it'll automatically switch it back to the default one so that you can't. This'll stop it from creating a file for every scene for bigger projects in where that'd create a ton of extra files.

    One big problem is that I didn't know how to check the Lightmapping.lightingSettings object because it keeps stating it's null when you try to check it for being null so I just put a try catch statement in there. Maybe some advanced programmer has some magic way to do it.

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3. using UnityEditor.SceneManagement;
    4.  
    5. [InitializeOnLoad]
    6. class EditorUpdate
    7. {
    8.  
    9.     public static string LightingSettingsAssetPath = "Assets/LightingSettings/Default.lighting";
    10.     public static string LightingSettingsName = "Default";
    11.  
    12.     static EditorUpdate()
    13.     {
    14.         EditorApplication.update += CheckLightingSettings;
    15.     }
    16.  
    17.     static void CheckLightingSettings()
    18.     {
    19.         if (Application.isPlaying == false) {
    20.         try
    21.         {
    22.             SwitchLightingSettingsIfNotDefault();
    23.         }
    24.         catch
    25.         {
    26.             SwitchLightingSettingsToDefault();
    27.         }
    28.         }
    29.     }
    30.  
    31.     private static void SwitchLightingSettingsIfNotDefault()
    32.     {
    33.         if (Lightmapping.lightingSettings != null)
    34.         {
    35.             if (Lightmapping.lightingSettings.name != LightingSettingsName)
    36.             {
    37.                 SwitchLightingSettingsToDefault();
    38.             }
    39.         }
    40.     }
    41.  
    42.     private static void SwitchLightingSettingsToDefault()
    43.     {
    44.         Lightmapping.lightingSettings = AssetDatabase.LoadAssetAtPath(LightingSettingsAssetPath, typeof(LightingSettings)) as LightingSettings;
    45.         EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
    46.     }
    47.  
    48. }
     
    Last edited: Aug 7, 2020
  31. caletbak-sp

    caletbak-sp

    Joined:
    Dec 11, 2018
    Posts:
    1
    Is this only available in Unity 2020 or it could work in 2019.4.7 with some package installation?
     
  32. JenniferNordwall

    JenniferNordwall

    Unity Technologies

    Joined:
    Sep 19, 2016
    Posts:
    159
    Hi
    All this are default features in the engine and doesn't live in a package. So unfortunately no :/ Sorry
     
unityunity