Search Unity

What is the expected multi-scene lighting pipeline? Because it appears to be broken...

Discussion in 'Global Illumination' started by hypnoslave, Sep 5, 2018.

  1. hypnoslave

    hypnoslave

    Joined:
    Sep 8, 2009
    Posts:
    439
    I'm a long time Unity fan, so if this post sounds salty, no disrespect was intended...

    It seems to me that the multi-scene lighting pipeline is currently broken and making an additive-loading game in Unity is either profoundly limited or impossible because of the ongoing bug where light probes are used from the most recently loaded scene, which makes separate baking impossible.

    What is the expected multi-scene lighting process here? Loading my entire game together for lightmapping theoretically solves the light probe issue, but introduces other problems. Even if I can load my entire game at once to generate mapping, I would need to create a single set of lightmapping options that work across my whole game. that means:
    1. No ambient light can be used anywhere if I want even a single dark area, which means I need a complex material solution for ambient lighting, including a solution for objects traveling between areas.
    2. Areas with Unrealistic lighting (such as a portal to another dimension where there are two suns) is simply impossible without a loading screen.
    3. Cheating by having sections overlap slightly is impossible - all scenes must be perfectly laid out in rational physical space so they do not block lighting from one another.

    I hope someone can tell me that I'm completely flying off the handle here and I'm just a dummy?

    I have no doubt that Graphics programming is insanely difficult and well over my head... but unless I'm missing something, making this sort of game simply isn't feesible in Unity, and as a consumer, if I had known how broken this was I'd have considered Unreal.

    Is there an ETA on the light probes issue, by any chance? I'd rather not re-build everything I have an another engine, if I can avoid that.
     
  2. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    Try to ask bakery's creator
     
  3. hypnoslave

    hypnoslave

    Joined:
    Sep 8, 2009
    Posts:
    439
    Bakery?

    I'm out of the loop, apparently.
     
  4. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    https://forum.unity.com/threads/bakery-gpu-lightmapper-v1-2-released.536008/
    I mean you might have faster answer and turn around with bakery than anything with unity team, because he is on a much smaller target than them. He was willing to listen about interval mapping which an obscure lightmap technique, so it will certainly inform you of the feasability of your issues. Also it's a damn fast and efficient lightmapper, like 10x faster at worst.
     
  5. hypnoslave

    hypnoslave

    Joined:
    Sep 8, 2009
    Posts:
    439
    Huh. No kidding. that's very interesting. Thanks very much neoshaman, I'll take a good look into this and see if it doesn't alleviate my woes.
     
  6. jStinson

    jStinson

    Joined:
    May 9, 2017
    Posts:
    21
  7. hypnoslave

    hypnoslave

    Joined:
    Sep 8, 2009
    Posts:
    439
    Thanks very much! Unfortunately that script solution does not work. it's possible that it's broken as a result of later unity patches, but who knows. I took some time, analysed it, understood it, and ran it, and it does what it purports to do (almost) but the probes that it ultimately creates are not correct - the data fails to copy to them properly. most of them are black, for example.

    I'm going to investigate this new light mapper, and in the absence of that, I'll simply see if I can use Unity's solution - to just bake all of my scenes together. I think I can prooooobaabbbllyyy get away with all scenes having a similar lighting set up. I'll just have to be super sneaky and put in some effort.
     
  8. danielrugu

    danielrugu

    Joined:
    Jul 24, 2016
    Posts:
    14
    Did you solve it yet?
     
  9. hypnoslave

    hypnoslave

    Joined:
    Sep 8, 2009
    Posts:
    439
    Nope.

    I've been onto other things. Hopefully unity can fix this (they are aware of the problem) but it's possible that I'll just have to load all the scenes together and bake. I've altered my design slightly and my entire environment should all be able to be baked together, as it makes euclidean sense.

    God help anyone who's making a non-euclidean game who needs to bake lightmaps.
     
  10. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    Well I guess there still isn't a solution. I'm using Unity 2017.4.24f and still seeing this as an issue.

    All of my scenes must be baked separately as they are much to large to fit in memory at the same time. I'll have to make in-between scenes (with very small and very little meshes), that have no light probes...so there are only main large scene light probes to go off of.

    Not ideal, but that's the only "solution" I could come up with.
     
  11. hypnoslave

    hypnoslave

    Joined:
    Sep 8, 2009
    Posts:
    439
    Hey, that's a very creative solution. good idea!
    Still sucks though, really, as it will only work with some pretty specific design restrictions.

    Honestly, I'm not sure why this isn't higher priority (or perhaps it is and it's just a really difficult problem). It's not like seamless open world games aren't insanely popular. It's not like Unity didn't revamp their entire scene management system to allow for seamless multi-scene loading/uloading. This bug basically F***s that all completely up.

    Very strange.
     
  12. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    I totally agree. I wish there were at least guidance or best practices to get around these kind of issues. It seems as though more advanced issues gets unresolved.
     
  13. hypnoslave

    hypnoslave

    Joined:
    Sep 8, 2009
    Posts:
    439
    Yeah, I know the feeling. Well it could very well be that they're absolutely gargantuan ice-berg problems, for all we know, so.... meh.

    Honestly, this isn't the first massive issue that I've navigated around and it won't be the last. it would have been nice to get a response on this particular issue but... I guess that's game development when you're using someone else's engine.
     
  14. thefranke

    thefranke

    Unity Technologies

    Joined:
    Jun 20, 2015
    Posts:
    153
    Hello everyone,

    I can confirm that there is a solution to the Light Probe problem with additive scenes. In the latest 2019.3 beta, probesets from additively loaded scenes will be merged together automatically. You will however need to call an API function to finalize the merge. This call - Lightmapping.Tetrahedralize() - will update the tetrahedralization structure you see when you click on a probeset (the lines connecting the probes) to include the newly added probes. Because re-tetrahedralizing probes is quite heavy work, you want to reduce calls to this function to a minimum.

    E.g. let's assume you build a Spacehulk like game where characters move along corridors, and each corridor segment is a scene. You load each neighboring/connecting segment to the current corridor because you don't know which way the characters will move next, i.e. each time characters move into a corridor segment, multiple new scenes are additvely loaded rather than just one. In cases like these, first load all scenes, then when everything is done call Lightmapping.Tetrahedralize().

    Cheers
     
    FiveFingerStudios likes this.
  15. hypnoslave

    hypnoslave

    Joined:
    Sep 8, 2009
    Posts:
    439
    Fantastic!!! Thanks very much for the tip, thefranke!

    You guys have saved me quite a lot of forehead rubbing and eye squinting, etc. This is great news for my forehead and others.

    I'll give this a try quite soon.
     
    thefranke likes this.
  16. pcg

    pcg

    Joined:
    Nov 7, 2010
    Posts:
    292
    Am I correct in assuming that the baked probe data from an additive scene cannot be moved to a new location and then retetrahedralized ?

    What I want to do is bake a series of rooms in their own scene all at the same location. Then load the additive scenes and move the rooms in to their correct position, retaining the baked light probe data. Is this possible?
     
  17. hypnoslave

    hypnoslave

    Joined:
    Sep 8, 2009
    Posts:
    439
    Quick update for anyone who finds this thread. "Lightmapping.Tetrahedralize" is a UnityEditor function, so it can't be used at runtime. I think what thefranke probably meant was LightProbes.Tetrahedralize & TetrahedralizeAsync. I hope. I'm about to find out :S

    pcg - responding because nobody else has -- Did you try this? it's possible that once you load a scene, and then move it (and thereby move the lightprobe objects in that scene), Tetrahedralize might update with the new positions. Sounds like we can call Tetrahedralize whenever we damn-well please.
     
  18. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    I came up with a solution for baking light probes across scenes loaded async….I tested it in Unity 2017.4.24f.

    Here is a video of it working.
     
    DotTeam likes this.
  19. pcg

    pcg

    Joined:
    Nov 7, 2010
    Posts:
    292
    Hey @hypnoslave thanks for the reply.

    Just tested on 2019.3.0f3 and I can confirm that you CANNOT move the light probe group and call Tetrahedralize.
    I'm assuming the baked probe data is actually stored in the LightingData.asset for the scene and that the Light Probe Group is only used for baking.

    Sadly this means Tetrahedralize doesnt address the problem for me in that I don't know the location the baked objects will finally end up as its a procedural level using prefabs.

    EDIT: I havent tried modifying the Light Probe position yet, I moved the light probe group instead, so perhaps that might work. I'll try that tomorrow and update.

    EDIT: Doh, position data is read only :(
     
    Last edited: Dec 14, 2019
  20. hypnoslave

    hypnoslave

    Joined:
    Sep 8, 2009
    Posts:
    439
    Five Finger Studios - that's fantastic! Congrats on getting it working. I'm super curious as to what your solution was. In terms of your question about what to do with it -- by all means if you can, capitalize, and an asset might be good for you guys. However it sounds like this issue may be addressed more-or-less in the newer versions of unity, so it might not be worth your time. I won't ask you to fork over your trade secrets but if you do, let me know, because I'm really quite curious indeed.

    PCG - I suppose that makes sense - the position data is baked and saved to a file, and then can be read from and tetrahedrawhatsitalized at runtime. Too bad a transformation can't be applied to the loaded data though. Don't think I've got an idea for you I'm afraid. I can imagine a few reasons why someone would want to do what you're doing - like... procedurally generated dungeons, for example. Can you change your design to allow for pre-placed configurations?
     
    FiveFingerStudios likes this.
  21. pcg

    pcg

    Joined:
    Nov 7, 2010
    Posts:
    292
    I have a solution which is to place all the prefabs in a single scene, bake it and then remove all the prefabs and just load the scene for the LightingData asset. There is a probe anchor field on the renderer component that can be used to get light probe data from another transform and I use this.
    It just means I have to create a separate game object for every item that needs to use light probes, position it in the correct place for the light probe data and if the object needs to move I have reflect this in the probe reference object. It all seems like overkill and I was hoping to ditch it if I could move the scene probe data but I guess it stays.
     
  22. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    Thanks!

    I'll talk it over with my partner to see what we should do. At the very least I should be able to write something up and provide some code to anyone that wants it.
     
  23. ldlework

    ldlework

    Joined:
    Jan 22, 2014
    Posts:
    46
    @thefranke What's the word on lightprobes for procgen scenes where you need to move the pieces around? How about lightprobe data in prefabs instead of scenes? Give us some hope buddy.
     
    pcg likes this.
  24. ldlework

    ldlework

    Joined:
    Jan 22, 2014
    Posts:
    46
    @pcg Did you ever make any practical progress with your anchor proxy solution. Can't believe I'm seriously inquiring into this....
     
  25. pcg

    pcg

    Joined:
    Nov 7, 2010
    Posts:
    292
    yes, it’s all up and running and seems to work well. I have a trigger collider around each prefab and I move the anchor to a relative position within the rooms anchor probe set.
    I’ll post some screens and more details if you are interested next time I’m behind the computer.
     
  26. ldlework

    ldlework

    Joined:
    Jan 22, 2014
    Posts:
    46
    Yes please.
     
  27. CF-Games

    CF-Games

    Joined:
    Jun 2, 2013
    Posts:
    134
    @pcg Would you mind sharing more details on how you did this, specifically the part about placing all rooms in a single scene, baking the scene, and then loading the scene just for the lighting data?

    I'm currently working on a game where my levels are also procedurally generated (made up of a bunch of rooms). I tried making a separate scene for each room and then loading them additively but each scene can only be loaded once. If there are multiple of the same room in my level, the scene with that room can only be loaded once. So I don't know a solution to this other than to make a lot of copies of the same scene and rename them to have unique names, which doesn't sound like the right way to do it.

    For your approach with baking all the rooms in a single scene, how did you instantiate multiple copies of those rooms and keep the lighting data? When I tried saving a lightmapped room as a new prefab and then drag that room to the scene, it's dark and doesn't have a lightmap.
     
  28. pcg

    pcg

    Joined:
    Nov 7, 2010
    Posts:
    292
    Sure. My game is also room based and I started this prior to 2019.3 (which is relevant for this solution) and is using 2019.2.
    I have a scene for each room for the purpose of baking prefab lightmaps only (not probes) which uses the process described in this forum thread
    https://forum.unity.com/threads/problems-with-instantiating-baked-prefabs.324514/

    Here's an example of one of my rooms.
    SingleRoom.PNG
    The black areas around the room are just quads I use to fade in/out to hide or show surrounding rooms.

    I also have a separate scene I call AllProbes which contains each room prefab and light probes on a separate game object for each room that are setup in a grid fashion with probes extending outside of the rooms although I dont think you need to setup your probes like this.
    SingleProbe.PNG

    The rooms evenly spaced so light from one room does not contaminate another room when baking and this ends up looking like so...
    MultiRooms.PNG

    As I mentioned each of my rooms is a prefab and the prefab does not contain the light probes, instead they are on separate game objects so my hierarchy ends up looking like this...
    Hierarchy.PNG
    Lets call the parent objects (Hall_1_1, Hall_1_1_H etc) the Probe Room Parents (mentioned later).

    Once I have all that setup I save that scene, and duplicate it to create another scene I call JustProbes. This is the scene I use to bake the probes only. First I run an editor script which goes through all the renderers in the scene and makes sure they switch from their RecieveGI from Lightmaps to Lightprobes. This stops the scene from baking lightmaps and helps speed up the bake.

    Code (CSharp):
    1.     [MenuItem("Tools/Lightprobes/Set Just LightProbes")]
    2.     public static void JustLightProbes()
    3.     {
    4.         MeshRenderer[] renderers = FindObjectsOfType<MeshRenderer>();
    5.         foreach (MeshRenderer r in renderers)
    6.         {
    7.             if (r.receiveGI == ReceiveGI.Lightmaps)
    8.                 r.receiveGI = ReceiveGI.LightProbes;
    9.         }
    10.     }
    11.  
    Then I bake the scene and finally remove the prefabs from the scene so all that remains is the lightprobes (and parent object). I do this final step because I have a reference to my prefabs elsewhere in the game so there is no need to have them load as part of the "JustProbes" scene.

    Then in game the last scene I additively load is the JustProbes scene.
    When you load the JustProbes scene the lightprobes will load in the positions setup in the original JustProbes scene, so to use them you must add a probe anchor to the renderer of your dynamic object. The position of the probe anchor must be relative to the position of the light probe room.
    EG
    I placed room 1 in my AllProbes scene at 0,0,0 and room 2 at 100,0,0
    Then in the game room 1 gets spawned at 1000,0,0.
    My players positions is 20,0,5 local to room 1 (ie his world position is 1020,0,5) then I must place my probe anchor at 120,0,5.
    So, to place the probe anchor you need to know what room the object is in, your local position of the object in that room, and the position of the Probe Room Parent the object is in.

    Hope that makes sense :)

    I'm currently in the process of automating all this because switching platforms and repeatedly doing this is a ball ache.
    I think in 2019.3 this could be simplified by loading the prefabs from individual scenes and running retetrahedralize on the light probe data.
     
    Last edited: Mar 6, 2020
    Aurigan and mowax74 like this.
  29. CF-Games

    CF-Games

    Joined:
    Jun 2, 2013
    Posts:
    134
    @pcg Thanks for the details. It all seems overly complicated. Baking lightmaps/light probes to prefabs sounds like something that should have already been built-in to Unity.

    I'm using 2019.3.3, and tried making a scene for each room and loading them additively, but the problem is that each scene can only be loaded once. If that room is used multiple times throughout the level, I can't load that room's scene more than once at a time. I also couldn't figure out how to get a reference to the room in the additively loaded scene after it's been loaded.

    I'm using DunGen to generate my levels with the rooms. After the level has been generated, I'm trying to make a script that goes through all the rooms and replace them with the rooms from additively loaded scenes, but I don't know how to get a reference to the rooms in those scenes to move them into place. But that won't matter unless I can solve the first issue with the loading scenes more than once.