Search Unity

Graphics Magic Lightmap Switcher - Storing, Switching and Blending Lightmaps in Real-Time

Discussion in 'Tools In Progress' started by Eugene-B, Sep 8, 2020.

  1. smmtest

    smmtest

    Joined:
    Jan 26, 2018
    Posts:
    4
    Will URP version be released in April?
     
  2. Eugene-B

    Eugene-B

    Joined:
    Sep 7, 2014
    Posts:
    321
    I will try very hard, but I will not promise, as SRP has so many versions and continues to change. And although I already have support for it, there is still a lot of work to do. Also, I think I should be polling the audience available to me about which version is currently being used. I have support since version 7, but it seems to be out of date. In general, I will try to finish with it in April, but most likely it will take May too.
     
    ftejada, AntonioModer and syphon1977 like this.
  3. Sholms

    Sholms

    Joined:
    Nov 15, 2014
    Posts:
    85
    hello, you would have support for bakery? if so, the full lighting mode work with baked shadows?
     
  4. Eugene-B

    Eugene-B

    Joined:
    Sep 7, 2014
    Posts:
    321
    Hi! Yes, the Bakery is supported and what you say will work without problems.
     
  5. Eugene-B

    Eugene-B

    Joined:
    Sep 7, 2014
    Posts:
    321
    Magic Lightmap Switcher has just become available in the Asset Store!

    While the asset was being checked, a lot of work was done to find hidden bugs and optimize some things. Thanks to the beta testers for participating, I really appreciate it!

    So the new version is ready and sent to the store, it will be available soon, however I can send the updated package directly, just let me know in PM.

    Good luck to everyone and good luck to the asset!

    Version 1.1

    Bug Fixes:

    • Fixed a bug due to which the Shadowmask was not taken into account by the system.
    • Fixed a bug due to which the Bakery could not bake light probes
    • Unexpected system behavior for objects with a 0 lightmap scale
    • Fixed an issue where lightmaps were not displayed after baking manually using the standard Unity Lighting window.
    • Fixed a bug in the DayNightController (Day/Night Cycle example) script that caused the MLS Light component to be infinitely added to the sun object.
    Changes:
    • Changed the mechanism of the shader patch. Now the patch is launched from the command line with administrator rights (for Windows). This should fix the access violation issue for most restricted users. For the rest, instructions are written in the documentation on how to get around the limitation.
    Improvements:
    • Added a new blend option for CustomBlendable, now interpolation can occur between stored variable values.
     
    AntonioModer likes this.
  6. Eugene-B

    Eugene-B

    Joined:
    Sep 7, 2014
    Posts:
    321
  7. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    I NEED THIS NOOOOOOW !!!!!!!!!
     
    Eugene-B likes this.
  8. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Ok so, I love this and I love you and I really needed it so THANK YOU!
    That being said, I'm using my own custom shaders and the manual doesn't specify how to implement this on custom surface or vertex/pixel shaders.
    I already sample the lightmaps myself in my custom shaders, so implementing this shouldn't be hard. I see you include a custom Standard shader in there, so I would need to incorporate those changes in my custom shaders. Some advice would be really appreciated to speed things up. :)
     
  9. Eugene-B

    Eugene-B

    Joined:
    Sep 7, 2014
    Posts:
    321
    Yes, the documentation will change for a while. Definitely. :D As for the shaders. Do you use your own lighting functions, or is your shader just a surface shader that uses the Unity standard library to render lightmaps, reflections, light probes and more?
     
  10. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    It's actually a custom lighting function for surface shaders that does all of this manually: lightmaps, light probes and probe volumes calculations explicitly inside (not automatically generated by unity).
    Then I use this lighting function on all the custom surface shaders I do.
    So I would need to implement your custom lightmap sampling and light probe functions in my custom lighting function and it should work with all my custom shaders.

    I use
    unity_SHA , unity_SHB , unity_SHC 
    to calculate the actual lightprobe myself and
    SHEvalLinearL0L1_SampleProbeVolume
    for Probe Volumes
    Then
    unity_Lightmap.Sample
    and
    DecodeDirectionalLightmap
    for lightmaps, so yeah, all manual stuff.

    If you could put all your magic code in an include and use it as a #define or an inline function, that would be the best :)
     
  11. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    I just bought it BTW. :)
     
    Eugene-B likes this.
  12. Eugene-B

    Eugene-B

    Joined:
    Sep 7, 2014
    Posts:
    321
    I have a separate include file that contains the blending functions and all the variables, then built-in Unity functions, just call those functions from this cginc. It seems that we need to work more closely, then I can write a detailed manual for everyone who uses custom shaders and maybe expand the functionality if necessary.

    Can you send me your shader by mail or private messages? I will see in detail how you can modify it and how difficult it is.

    Thank you, I hope this time I don't get 1 star from you! :D
     
    atomicjoe likes this.
  13. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Then it's all right! I was afraid you just modified the Standard Unity shader and put the code in there. I hate diving inside the Standard Unity shader. It's all over the place, divided in 1000 functions and 10 files :D
    I'm afraid sampling lightmaps inside a regular surface shader is really NOT user friendly: it wasn't designed to allow you to do that in the first place. What I ended doing was making a minimal surface shader, asking Unity to show me the generated code for this and copy-pasting the lightmaping functions back into my own surface shader. It's cumbersome and pretty hacky, but has served me well.
    It's ok. I'll manage it myself, but I'll ask for help if I need it, thanks :)
    HEY! I did bump that review up to 4 stars because you gave great support and were nice overall! (even though I ended up making my own lightprobe placer in the end. But that's just because I'm like that :p )
     
    Eugene-B likes this.
  14. Eugene-B

    Eugene-B

    Joined:
    Sep 7, 2014
    Posts:
    321
    Ok, then can you tell me later how it went and should I add or change something?
    BTW, MLS function calls in version 1.1 were changed for optimization, so don't swear too much if you see UNITY_BRANCH somewhere :)

    It was one of my first direct works with a customer, thanks so far!
     
  15. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    I always make such a great impression! :D
     
    Eugene-B likes this.
  16. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    I'll do it, I promise. But I don't know when, since I have quite a lot of work to do. I just purchased your plugin now because I wanted to let you know your work is appreciated ;)
     
    Deznom and Eugene-B like this.
  17. TimGM

    TimGM

    Joined:
    Mar 28, 2017
    Posts:
    6
    @Eugene-B i would buy this asset in a second if it supported URP. Just wanted to add my voice to the request queue! Looks amazing. Any rough ETA. It’s in my basket for when URP comes out.
     
    Eugene-B likes this.
  18. Eugene-B

    Eugene-B

    Joined:
    Sep 7, 2014
    Posts:
    321
    Hey! I hope to be done with this within a month if all goes well. :)
     
    ftejada, TimGM and AntonioModer like this.
  19. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    Same time for HDRP?
     
  20. Eugene-B

    Eugene-B

    Joined:
    Sep 7, 2014
    Posts:
    321
    Yes, a separate SRP (URP + HDRP) package will be released.
     
    keeponshading and ftejada like this.
  21. rbcode

    rbcode

    Joined:
    Aug 18, 2020
    Posts:
    4
    Hi Eugene, any news on HDRP support?
     
  22. Eugene-B

    Eugene-B

    Joined:
    Sep 7, 2014
    Posts:
    321
    Hey, the package has been sent to the store, awaiting publication. As soon as it becomes available, I will report it on all channels.
     
    keeponshading likes this.
  23. ecarter

    ecarter

    Joined:
    Jan 3, 2013
    Posts:
    21
    hello, i have these error on my scene and i dont get any info to see whatsa objet is the problem,

    ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index
    System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <695d1cc93cca45069c528c15c9fdd749>:0)
    System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <695d1cc93cca45069c528c15c9fdd749>:0)
    MagicLightmapSwitcher.MLSManager.RemoveStoredLightingScenario (System.Int32 removeIndex) (at Assets/Magic Lightmap Switcher/Editor/MLSManager.cs:363)
    MagicLightmapSwitcher.MLSLightmapDataStoring+<BakeAndStoreLightmapQueue>d__29.MoveNext () (at Assets/Magic Lightmap Switcher/Editor/MLSLightmapDataStoring.cs:354)
    MagicLightmapSwitcher.MLSLightmapDataStoring.BakeAndStoreQueueIteratorUpdate () (at Assets/Magic Lightmap Switcher/Editor/MLSLightmapDataStoring.cs:44)
    UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at <208f92fc783546f9abbe643bfc23920c>:0)
     
  24. Eugene-B

    Eugene-B

    Joined:
    Sep 7, 2014
    Posts:
    321
    Hello!
    This is a known problem to me and it is already on the roadmap.
    The easiest way to fix this (although it still leaves the possibility of encountering this in the future) is to make sure that the size of the Events arrays matches the number of lighting scenarios in Switching/Blending tab. To do this, select the Magic Lightmap Switcher object in the scene hierarchy and switch the inspector to Debug mode, then check the lines shown in the screenshot.
    upload_2022-5-23_1-31-15.png
    The second option is to simply comment out the lines of code that refer to events, if you don't use them at all.
     
    ecarter likes this.
  25. ecarter

    ecarter

    Joined:
    Jan 3, 2013
    Posts:
    21
    also i have these message when run the game, and the game runs really slow when using lightswitch in the scene, maybe is because of these message


    'ETC_RGB4' is not supported on this platform. Decompressing texture. Use 'SystemInfo.SupportsTextureFormat' C# API to check format support.
    UnityEngine.Cubemap:.ctor (int,UnityEngine.TextureFormat,bool)
    MagicLightmapSwitcher.MagicLightmapSwitcher:CreateDefaultCubemap () (at Assets/Magic Lightmap Switcher/MagicLightmapSwitcher.cs:2383)
    MagicLightmapSwitcher.MagicLightmapSwitcher:OnEnable () (at Assets/Magic Lightmap Switcher/MagicLightmapSwitcher.cs:2281)
     
    Last edited: May 23, 2022
  26. Eugene-B

    Eugene-B

    Joined:
    Sep 7, 2014
    Posts:
    321
    What platform is the build for?
     
  27. ecarter

    ecarter

    Joined:
    Jan 3, 2013
    Posts:
    21
    is for quest 2,
    i tried the same scene using ML in one and the other without ML, the one with ML have a huge drops of fps.
     
  28. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    That's because it's decompressing the texture on the CPU and then storing it as RGBA32, which is an uncompressed format and taxes the GPU a lot.

    Exotic modes like RGB4 are not widely supported in general. It's better to just stick to regular 8 bit modes for compatibility.
    Also, using a specific texture format is not a good idea unless you know very well the target device you are building for.
    Otherwise it's better to let Unity decide by setting the texture to automatic and compressed in the importer for each platform.
     
    Eugene-B likes this.
  29. umair21

    umair21

    Joined:
    Mar 4, 2016
    Posts:
    147
    Hi! I want to buy this asset but before I go ahead and buy it, I want to make some questions clear for myself.

    1a. Instant switching of Lightmaps in START method
    How does this tool work? I mean like in my case, I have a game inside a house, RC Car. How many lightmaps will it create if I want night and day light? My night time lightmapping is creating like 2 lightmap textures and day time create 1 4k lightmap texture. Will this tool use these 3 maps to work? Or will it create it's own lightmaps to work properly.

    1b. Blending of 2 Lightmaps (Not a day night cycle but just 2 lightmaps within a room)
    I have control room with red light baked for emergency and green for everything is under control. My question is, can I blend these 2 lightmaps or I must have to go for instant switching of lightmaps.

    1c. Blending for Day Night cycle
    If I ever want to extend my game and make it day night cycle support, do I must have to create all 4 times of the day and night light cycles or is this tool can just simply blend between day and night lightmaps skipping noon or evening?

    2. Low-end support
    Will it work on low-end devices like 2gb RAM or 3gb RAM devices? (Ofcourse it works on Android as you mentioned in your descrition so that cleared one of my question).

    3. Bakery GPU Lightmapper
    I am working with Bakery GPU Lightmapper so is it working fully and properly with Bakery GPU Lightmapper or is it still in development stage, this Bakery support I mean.

    4. Shader dependent
    Do we have to use your custom shaders (If any) for this tool to work or we can go with our own ones like Mobile diffuse (Since I am developing for mobile so I prefer this shader alot).

    5. Any need of rebaking?
    Can we use this tool for our currently baked scenes with Bakery? No need of rebaking lightmaps?

    6. Creating it's own maps?
    Last question, does this tool creates it's own lightmaps? Or it'll simply use my own baked ones???


    If there's anything that you think I should know about this tool and mobile support before I buy it, please guide me with that. :)
     
  30. Eugene-B

    Eugene-B

    Joined:
    Sep 7, 2014
    Posts:
    321
    Hi!

    1a. MLS saves baked lighting maps, so you can create two presets for night lighting and one for daytime, then start baking and saving, and then switch between them instantly or perform a smooth blending.

    1b. Yes, you can get smooth blending.

    1c. You can get an average option between day and night, however I don't think it will be accurate enough.

    2. I suppose it depends on the complexity of the scene, it will require testing, I can't say for sure.

    3. It works mostly without problems, but sometimes there are errors with shaders. I fix them quickly. At the moment, a new version is almost ready for release, which also supports blending and switching Bakery Volumes.

    4. MLS can work in "Switching Only" mode, however, a shader patch is required to support blending. On the other hand, MLS edits only basic shaders, which are then used, including custom shaders, so everything should work without problems, unless you write your own lighting functions.

    5. It will require a complete re-baking and customization.

    6. MLS copies the lightmaps created by the built-in lightmapper or Bakery.

    Blending lightmaps requires their full loading into memory, so this can cause problems on weak devices, in addition, several sets of lightmaps may take up more space than you expect, you need to be careful with this. AssetBundles are supported.
     
  31. umair21

    umair21

    Joined:
    Mar 4, 2016
    Posts:
    147
    Thank you so much for this detailed reply. Definitely going to buy it real soon since it covers everything that I need. <3
     
    Eugene-B likes this.
  32. Demhaa

    Demhaa

    Joined:
    Jun 23, 2018
    Posts:
    35
    Can we use custom lightmaps made in an external 3d editor like Vray or Arnold?
     
  33. Eugene-B

    Eugene-B

    Joined:
    Sep 7, 2014
    Posts:
    321
    Hello! Can you describe the process of integrating external lightmaps into a Unity scene? I need to understand if the lightmaps will be in the standard Unity array in the end. I also ask you to prepare a simple test scene with external lightmaps already integrated be and send to me as package so that I can run some tests on my own. Note that there must be at least two sets of lightmaps.
     
  34. transcosmos

    transcosmos

    Joined:
    Feb 5, 2016
    Posts:
    3
    1. I imported this asset after purchase.
    When I tested Quick Start, the shader for the floor object was missing.
    I am attaching the image.
    What may be the cause.

    2.I want to stream lightmaps Can I store lightmap-related files baked in another project on the server and read the files by streaming?

    environment
    Unity2021.3.9f1
    Build-in
     

    Attached Files:

  35. Eugene-B

    Eugene-B

    Joined:
    Sep 7, 2014
    Posts:
    321
    1. Just replace the shader depending on which RP you use.

    2. I haven't tested this and I can't say for sure, however, in order for MLS to be able to blend lightmaps, it only needs to load the required data.
    The system provides an option to work with AssetBundles, when it is activated, you will have to load all the previously saved data yourself. When you enable this option, MLS will write a message in the console that it is waiting for data to load, you just need to go to the line in the code where this message is generated and write the streaming code you need there.
     
  36. ehillrti

    ehillrti

    Joined:
    May 3, 2019
    Posts:
    2
    I recently purchased MLP and MLS and am VERY impressed! MLP saved me a TON of time and did a great job. I'm now working on integrating MLS into my application but I've run into a small problem. I got MLS imported, setup my main scene with a Lighting Scenario and two Presets, did the Bake And Store Lightmaps Queue, then built my application. MLS did a great job and allowed my main scene to use the two sets of lightmaps to easily switch between a fully lit environment (all lights on) and a dark environment (all lights off). Thanks so much!

    PROBLEM: The problem I've run into is that I have a couple of very simple preliminary scenes that the user passes through to make game selections and these scenes do not use lightmapping, just a very simple set of lighting settings that use the default skybox and a single directional light. They look fine when you first come into the application but as soon as you go into the main game scene (the only scene with lightmapping & MLS) and then come back out to make another scenario selection, those simple preliminary scenes have lost their lighting. FYI, I am not using any additive scenes. Each loaded scene replaces the previous scene. Is there something I need to be doing to restore the lighting settings in my non-LMS scenes? Thanks!
     
  37. yueyuxingchen

    yueyuxingchen

    Joined:
    Feb 28, 2022
    Posts:
    1
    “ The name 'FileUtil' does not exist in the current context”。This problem occurred when I was packing. How can I fix it
     

    Attached Files:

  38. Eugene-B

    Eugene-B

    Joined:
    Sep 7, 2014
    Posts:
    321
    In which version of MLS does this happen? I'll fix it and post an update. Or you can connect to the Discord server, then I can send you the fix personally.
     
  39. Eugene-B

    Eugene-B

    Joined:
    Sep 7, 2014
    Posts:
    321
    Please connect to the Discord server, maybe we will figure out the problem using a remote connection.
     
  40. Mulbin

    Mulbin

    Joined:
    Feb 8, 2016
    Posts:
    63
    Hi, I'm getting an odd issue. I have a scene with both baked and dynamic lights, and I've got the baked lightmap switching just fine... but for some reason it is also killing the camera's ability to see dynamic lights shining on static objects when I switch! The light is still clearly working in the scene view, and is still shining on non-static objects in game view, but the static objects are completely black in the game view.

    Inspector (dynamic green light)
    upload_2024-1-10_13-32-57.png

    Game View of the same dynamic light.
    upload_2024-1-10_13-33-30.png

    If I toggle back to the other baked lightmap the dynamic light also starts working again in game view.