Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Lighprobe behavior in additive scenes.

Discussion in 'Global Illumination' started by nomand, May 1, 2020.

  1. nomand

    nomand

    Joined:
    Dec 23, 2008
    Posts:
    44
    Here's a simple setup:

    MainScene is empty, no lighting.
    Room1 is baked with lightprobes.
    Room2 is baked with lightprobes.

    All baking is Full (direct and indirect, no realtime GI. Using latest URP on 2019.3.11 for Android).

    Scene flow:
    MainScene additively loads Room1 > Room1 is set active. > Room1 unloads > Room2 additively loads, sets active.

    Expectation:
    We load into Room1, get Room 1's lighting, when Room2 loads, we get Room2's lighting.
    Reality:
    We load into Room1, get Room1's lighting, when Room2 loads, we still get Room1's lighting.

    Fix attempts:
    1. Removing lightprobes from Room1 causes Room2 to have no probes at all, black lighting on dynamic objects.
    2. After 1's results, running LightProbes.Tetrahedralize(); broke all lightprobe data, throwing probes all over the space and rendering insane harmonics values (super ringed, negative blacks, full whites etc.) (see gif at the bottom)
    3. Setting
    Code (CSharp):
    1. LightmapSettings.lightProbes = null;
    2. LightmapSettings.lightmaps = null;
    After unloading Room1 before loading Room2 causes Room2's probes to load correctly (can see the lightprobegroup gizmos in scene view), but not actually contributing lighting to the scene.
    4. Running LightProbes.Tetrahedralize(); at this stage keeps Room2's probes in correct locations but resets their values to some default skybox gradient value by the looks of it (nothing is exposed so can't say for sure) but does make them contribute the newly-wrong reset lighting to the scene.

    Here's results of step 2 for your amusement:


    I've wasted the whole day trying to debug this. Please don't suggest I put everything into a single scene to bake. What I expect is the flow I describe, as it used to be default behavior. Something changed and that's no longer how Unity works, what is going on?
     
    Last edited: May 1, 2020
  2. DanielMcPeters

    DanielMcPeters

    Joined:
    Jan 15, 2016
    Posts:
    1
    My problem almost exactly. After room 2 loads async I unload room 1 async.
    Then room 2 is set active. I run LightProbes.TetrahedralizeAsync(); which eliminates room 1 light probes and correctly establishes room 2 light probes.
    Only problem is all my probes are black and they make all dynamic objects black.
    This is on 2019.3.7
     
  3. thefranke

    thefranke

    Unity Technologies

    Joined:
    Jun 20, 2015
    Posts:
    153
    Hey nomand!

    That sounds like a bug. Could you perhaps open a ticket and add a reproducible project? I'd expect this to be the correct workflow and so it should not produce black SH or any ringing.

    Cheers
     
  4. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    889
    Impeccable timing. We run into this issue on Thursday and I'm running a task to try and find a solution today. Has this been reported as a bug yet? If not I shall need to do it, it's entirely blocking my task...
     
  5. nomand

    nomand

    Joined:
    Dec 23, 2008
    Posts:
    44
    @DanielMcPeters @AlkisFortuneFish Are you using addressables?
    I've done multiple tests today trying to replicate this flow using offline assets in a new project, and the issues don't surface there. Our suspicion is on addressables right now.
     
  6. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    889
    We are but I am getting it offline too, even on a test project.
     
  7. nomand

    nomand

    Joined:
    Dec 23, 2008
    Posts:
    44
    We are using Bakery, but I tested both Bakery and Unity's native Progressive light mapper and in one context, both setups failed to load probes, and in an offline context, both work fine. I passed it onto our engineering team to figure out if there's a scene loading pathway that causes it. Their initial suspicion is on addressables.

    Here's a quick script I mocked up to load/setActive/unload/load/setActive using the flow described above if it's of any use to you. Didn't even need to run Tetrahedralize() on the probes to have them show up during this test:

    Code (CSharp):
    1.  
    2. using System;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5.  
    6. public class SceneLoaderUnloader : MonoBehaviour
    7. {
    8.     public string Room1;
    9.     public string LighmappedRoom;
    10.  
    11.     private void Start()
    12.     {
    13.         LoadRoom1();
    14.     }
    15.  
    16.     private void LoadRoom1()
    17.     {
    18.         AsyncOperation loadSceneAsync = SceneManager.LoadSceneAsync(Room1, LoadSceneMode.Additive);
    19.         loadSceneAsync.completed += (AsyncOperation) =>
    20.         {
    21.             SceneManager.SetActiveScene(SceneManager.GetSceneByName(Room1));
    22.             UnloadRoom1();
    23.         };
    24.     }
    25.  
    26.     private void UnloadRoom1()
    27.     {
    28.         AsyncOperation loadSceneAsync = SceneManager.UnloadSceneAsync(SceneManager.GetSceneByName(Room1).buildIndex);
    29.         loadSceneAsync.completed += (AsyncOperation) =>
    30.         {
    31.             LoadLightMapped();
    32.         };
    33.     }
    34.  
    35.     private void LoadLightMapped()
    36.     {
    37.         AsyncOperation loadSceneAsync = SceneManager.LoadSceneAsync(LighmappedRoom, LoadSceneMode.Additive);
    38.         loadSceneAsync.completed += (AsyncOperation) =>
    39.         {
    40.             SceneManager.SetActiveScene(SceneManager.GetSceneByName(LighmappedRoom));
    41.         };
    42.     }
    43. }
    44.  
     
  8. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    889
    That is very interesting. I am about to submit a bug with a loader very similar to this, which repros the problem. It uses the following setup:

    Base scene - No Lighting Data
    Scene 1 - Lighting Data
    Scene 2 - Lighting Data

    Base scene is always loaded.
    Load Scene 1
    Set Scene 1 Active
    Tetrahydralize
    Unload Scene 1
    Load Scene 2
    Set Scene 2 Active
    Tetrahydralize

    Without calling Tetrahydralize I cannot even get Unity to load the Light Probes at all.
     
  9. nomand

    nomand

    Joined:
    Dec 23, 2008
    Posts:
    44
    Interesting, I have exactly the same setup:

    Base scene - No lighting data, always loaded.
    Scene 1 - Lightmaps + Reflection Probes, no light probes
    Scene 2 - Lightmaps + Reflection Probes + Light probes.

    Same loading flow as yours but without the Tetrahedralize call.
    All scenes set to Non-directional, Subtractive (URP no shadowmask).
     
  10. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    889
    Oh, there is one difference, both Scene 1 and Scene 2 have lightprobes for me.

    Also, one other thing that explains why I need to call Tetrahydralize there, Base Scene had ended up with lighting data, probably from one of the previous tests I was doing trying to get this to work.

    Still, the first Light Probe data loaded is stuck and doesn't change no matter what. Just tried to make it so that the first scene is unloaded after the first scene becomes active to see if that changes anything and it doesn't.
     
  11. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    889
    Also, main game uses URP Subtractive No Shadowmask but the test project just uses built-in and I've tested all lighting modes. No difference in behaviour, which there shouldn't be anyway as this stuff is quite low level.
     
  12. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    889
    @thefranke I have reported this as case 1244629.
     
  13. thefranke

    thefranke

    Unity Technologies

    Joined:
    Jun 20, 2015
    Posts:
    153
    Thank you!
     
  14. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    889
  15. nocanwin

    nocanwin

    Joined:
    May 7, 2009
    Posts:
    176
    Getting this as well in Unity 2019.3.15f1, Addressables 1.9.2. The problem seems to be with Addressables. Using Addressables, if RootScene(no light probes) loads EnvironmentScene(light probes) and then sets EnvironmentScene to active light probes are black. If I load the EnvironmentScene without using addressables then lighting works as expected.

    Edit: Maybe my issue is different. Calling LightProbes.TetrahedralizeAsync(); fixed it for me. Leaving this up here in case anyone else is having the same problem.
     
    Last edited: Jun 5, 2020
    chrismarch likes this.
  16. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    889
    Our issue is not but we have been given a workaround. Our probe positions are the same, since they represent different environments, so the system rejects them and the old ones stick.

    Jittering the probe positions a bit fixes it, until the actual fix lands.
     
  17. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    449
    Thanks. Possibly to clarify for others running into this with addressables, it wasn't enough for us to Tetrahedralize after setting the active scene to the newly loaded scene. I had to also do a TetrahedralizeAsync right after awaiting the Task in the AsyncOperationHandle returned by Addressables.UnloadSceneAsync. We unload the previous scene before loading the next (additively)
     
    jeremedia likes this.