Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Unity Progressive CPU Lightmapper

Discussion in 'Global Illumination' started by Kuba, Feb 2, 2017.

  1. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    5,983
    Thank you for the updates, much appreciated.
     
  2. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,095
    Hi, I suspect you are getting a lot of invalid lightmap texels because the terrain lightmap texels are seeing many backfaces from the trees. There are a few things we can try to isolate the issue:
    - What is the backface tolerance value set for the lightmap parameters for the terrain? What happens if you use a higher tolerance value?
    - Have a look at the texel validity scene visualization mode? is the area with the wrong shadowing marked as invalid during baking?
    - Does using double sided GI for the tree foliage make a difference?
    - Can you please provide a screendump of the generated shadow mask texture?
     
  3. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    5,983
    (you mean lower, right?)
     
  4. Jesper-Mortensen

    Jesper-Mortensen

    Unity Technologies

    Joined:
    Mar 15, 2013
    Posts:
    201
    Looks like a biasing issued when using realtime direct lighting. Have you tried tweaking the bias on the directional light?

    Would be interesting to know if this is in the lightmap or the realtime direct. You should be able to determine that by using the baked lightmap visualization in the scene view.
     
  5. Jesper-Mortensen

    Jesper-Mortensen

    Unity Technologies

    Joined:
    Mar 15, 2013
    Posts:
    201
    We have an issue with a serial stage that depends on the lightmap size, we have optimized this significantly in 18.3 and we are backporting this fix to earlier versions ATM.
     
    Fallc likes this.
  6. Jesper-Mortensen

    Jesper-Mortensen

    Unity Technologies

    Joined:
    Mar 15, 2013
    Posts:
    201
    We know about this and have a fix in 18.3 that we are going to backport to earlier versions asap. Once that happens you should be back to ~100% CPU utilization.
     
    JamesArndt and buttmatrix like this.
  7. Jesper-Mortensen

    Jesper-Mortensen

    Unity Technologies

    Joined:
    Mar 15, 2013
    Posts:
    201
    We have recently been looking into the packing step. We are adding spatially coherent packing and also an ability to force a group of objects into a single atlas. We will look into your request too while we are doing this. It makes sense to be able to do your own packing and maintain that for baking.
     
  8. ZeBraNS

    ZeBraNS

    Joined:
    Feb 21, 2015
    Posts:
    23
    Hi,
    could someone give (or make) some practical example of how to use configurable falloff in the Progressive Lightmapper.

    Thanks
     
  9. kristijonas_unity

    kristijonas_unity

    Unity Technologies

    Joined:
    Feb 8, 2018
    Posts:
    385
    Hey!

    In order for the custom light falloff to work, you would first need to create a script named ExtractFalloff which contains the following code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Experimental.GlobalIllumination;
    5. using UnityEngine.SceneManagement;
    6.  
    7. [ExecuteInEditMode]
    8. public class ExtractFalloff : MonoBehaviour
    9. {
    10.     public void OnEnable()
    11.     {
    12.         Lightmapping.RequestLightsDelegate testDel = (Light[] requests, Unity.Collections.NativeArray<LightDataGI> lightsOutput) =>
    13.         {
    14.             DirectionalLight dLight = new DirectionalLight();
    15.             PointLight point = new PointLight();
    16.             SpotLight spot = new SpotLight();
    17.             RectangleLight rect = new RectangleLight();
    18.             LightDataGI ld = new LightDataGI();
    19.  
    20.             for (int i = 0; i < requests.Length; i++)
    21.             {
    22.                 Light l = requests[i];
    23.                 switch (l.type)
    24.                 {
    25.                     case UnityEngine.LightType.Directional: LightmapperUtils.Extract(l, ref dLight); ld.Init(ref dLight); break;
    26.                     case UnityEngine.LightType.Point: LightmapperUtils.Extract(l, ref point); ld.Init(ref point); break;
    27.                     case UnityEngine.LightType.Spot: LightmapperUtils.Extract(l, ref spot); ld.Init(ref spot); break;
    28.                     case UnityEngine.LightType.Area: LightmapperUtils.Extract(l, ref rect); ld.Init(ref rect); break;
    29.                     default: ld.InitNoBake(l.GetInstanceID()); break;
    30.                 }
    31.  
    32.           ld.falloff = FalloffType.InverseSquared;
    33.                 lightsOutput[i] = ld;
    34.             }
    35.         };
    36.  
    37.         Lightmapping.SetDelegate(testDel);
    38.     }
    39.  
    40.     void OnDisable()
    41.     {
    42.         Lightmapping.ResetDelegate();
    43.     }
    44. }
    The code example above already has Inverse Squared falloff set by default. You can choose between InverseSquared, InverseSquaredNoRangeAttenuation, Legacy, and Linear. If you want to use a different light falloff method, simply change the following line:

    ld.falloff = FalloffType.InverseSquared;


    Once that is done, simply attach the script to the light of your choice. Keep in mind that only baked lights are supported at the moment.

    If you happen to not see any changes in your light falloff after modifying the script, try to disable and enable the light and rebake the scene.

    We have also put a small example project which contains a single light, with the custom falloff script already attached to it. Keep in mind that you would need to open it in Unity 2018.2 in order for it to work. You can download the project via this link.

    If you need more information, please refer to this manual page on custom light falloff in Unity - https://docs.unity3d.com/Manual/ProgressiveLightmapper-CustomFallOff.html
     
    ZeBraNS and konsic like this.
  10. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,379
    since it is lightmap process it should be available in the default renderer
     
  11. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,379
    scroll up :D
     
  12. konsic

    konsic

    Joined:
    Oct 19, 2015
    Posts:
    822
    Where to apply script? On camera or point light ?
     
  13. ZeBraNS

    ZeBraNS

    Joined:
    Feb 21, 2015
    Posts:
    23
    Thanks Kristijonas for your detailed answer :)
     
    kristijonas_unity and JamesArndt like this.
  14. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,379
    Did you read Kristijonas post above?
     
  15. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    5,983
    I don't know if this changed in 2018.2, but I found that to be on the safe side, I usually end up loading another scene and then reloading the scene I want to make sure the change in falloff actually happens.
     
    kristijonas_unity and konsic like this.
  16. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,029
    Many thanks to you and Jesper for answering everyone's questions! (Here's my original post: https://forum.unity.com/threads/progressive-lightmapper.454362/page-13#post-3473156 )

    So it turns out that my project had no " LightmapParameters" object in the project. Should that be generated automatically at some point? So I created one and left the settings at defaults, the tried lightmapping my game scene again. Attached are some views. You can see that the lightmap does not correspond to where the actual (realtime) shadows are cast on the terrain. These are tree-creator trees, and Double Sided GI is dimmed/inactive on those materials.

    thanks
    Dave


    texel validity.png shadowmask.png baked lightmap.png shaded view with realtime shadows.png
     
    Last edited: Jul 11, 2018
  17. Laurens-Paladin-Studios

    Laurens-Paladin-Studios

    Joined:
    Apr 25, 2015
    Posts:
    49
    Hi There Unity,

    I just encountered an issue using Progressive lightmapping with an Alpha clipped material using LWRP:
    BakedGiAlphaClip.JPG

    On the top-right you can see the realtime shadow, on the bottom-left the baked version of the same plane. I'm using LWRP and double sided GI.

    Doing the same thing and not using LWRP works just fine:
    BakedGiAlphaClip_UnityRP.JPG

    I've reported this as a bug (Case 1061688), and am curious if this was already on your radar.

    Thanks
    Laurens

    (edit: Using the latest official unity 2018.2)
     
    Last edited: Jul 18, 2018
    indieDoroid, JamesArndt and konsic like this.
  18. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,095
    Hi Dave! Unity always have a scene wide lightmap parameters assigned in the Lighting window. See this page for details https://docs.unity3d.com/Manual/class-LightmapParameters.html
    Creating a new parameters asset will have default values and assigning it to your object without modifying the values will not change anything. You have to modify the values in the parameters asset you assigned to your object.
    From your screenshots I can tell that you are getting a lot of invalid lightmap texels on the terrain. This is because the lightmap texels on the terrain are seeing a lot of backfacing triangles from the trees.

    - Try setting a higher backface tolerance value on the lightmap parameters for the terrain
     
  19. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,029
    I can only find Backface Tolerance value on the LightmapParameters object that I created in the project -- it's set to 0.9 there, which is almost maximum value. Is there somewhere else to set it for the terrain specifically? If so, sorry, I can't find it and would appreciate a tip....

    thanks
    Dave
     
  20. Captain_Flaush

    Captain_Flaush

    Joined:
    Apr 20, 2017
    Posts:
    29
    Hello,

    Just tested the progressive lightmapper in 2018.2.02f, everything is fine, just that the light mapper started to not save and I can't get it to save the baked light maps again. I can see the textures in the global maps tab, but I can't get it to save them to the scene folder.
    Could you advise on a workaround or a fix on my side?

    Thanks,
    Mihai
     
  21. Captain_Flaush

    Captain_Flaush

    Joined:
    Apr 20, 2017
    Posts:
    29
    The saving works sometimes and sometimes doesn't. Is there any settings that I configure to ensure saving (some buffer size or smth like that?)
    Thanks
    Mihai
     
  22. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,095
    In the manual https://docs.unity3d.com/Manual/class-LightmapParameters.html have a look at the `Assigning Lightmap Parameters Assets` section about assigning to GameObjects.
    InkedUnity_2018-07-26_08-13-09_LI.jpg
     
  23. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,675
    Is mixed mode lighting broken in 2018.1.3f1? I'm using the Progressive lightmapper and when I bake a light out and then return that light to Mixed Mode it doesn't light my real time object anymore.
     
    konsic likes this.
  24. lolclol

    lolclol

    Joined:
    Jan 24, 2013
    Posts:
    177
    2018.2 released but no gpu baking system. :(:(:(
     
  25. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    921
    It should come at some point in the 2018.3 cycle !
     
    KEngelstoft likes this.
  26. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,675
    I must be doing something wrong now. I bake my lighting and the directional light in the scene still affects the track surface, but it should be only lit by a lightmap after baking. I've tried Subtractive, I've tried Shadowmask and all of the different options. My track is set to "Static", it's got Lightmap UVs generated for the mesh. My light is set to "Mixed" so it should bake the track lighting and dynamically light the vehicle. No clue why it isn't working. It does bake lighting to the track when the light is set to "Baked" but when I switch it back to "Mixed" it doesn't light my vehicle anymore.

    Is something broken with Mixed Mode lighting?

    I try to use Light Probes to bake "real time" lighting, but it kills all nice specular shine on my vehicle and it looks awfully flat, so light probes don't' seem to be solving this either.

    EDIT - Okay I did find a nifty workaround that appears to be working. Use two lights. One is a real-time light and the other is a baked light. They are both set to use culling layers, so the real-time light only affects my vehicle and the baked light only affects the environment. Once I'm done baking I disable the baked light, so the only light being used in my scene is the real-time that only illuminates my vehicle. It appears to be working, but feels like a hack or workaround.
     
    Last edited: Aug 3, 2018
    konsic likes this.
  27. Mr-Mechanical

    Mr-Mechanical

    Joined:
    May 31, 2015
    Posts:
    194
  28. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    What is the status of GPU support. Today with 2018.2 I've finally managed to bake an outdoor 600x600m city scene. Took a while so I would like to lut the 1080 to work instead of my older cpu.
     
    Last edited: Aug 9, 2018
    JamesArndt likes this.
  29. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    This is the baked urban map. It is the available Naniwa -Ku map by zenring plus a lot of extra stuff by me, I should not have added small objects to lightmap as It is done trough proves, but I'm still getting familiar with teh system. I had to doubl ethe intensity of directional because initially it was too low lit, may be this could have been tweaked with exposure on the filter stack.
    upload_2018-8-9_12-8-26.png

    upload_2018-8-9_12-9-4.png

    7h is not the end of the world but does not let much marging for increasing quality without leaving me without my working tool.
    At 0.5 resolution it takes about the half despite the docs say its 4 times more texels. I wonder if leaving 0.5 resolution and puting 4 times more indirect rays would be better.
     

    Attached Files:

  30. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    ISSUES:
    I'm having issues with road markings that are a plane with texture with alpha.
    They get black.
    upload_2018-8-9_12-12-5.png

    upload_2018-8-9_12-12-19.png



    RENDERER FOR THE FAILING ROADMARKINGS MESH
    upload_2018-8-9_12-20-14.png

    If I switch to cutout from fade they look fine in the range where lightmap is not active but go black when they enter the lightmap distance.

    This may not be an issue but I set lightmap size 4096 and sometimes it makes 1024 other times 2048 I guess it is that it can take up to 4096 lightmap tiles and if it does not need all of em it just uses smaller size. If not, there may be a bug.


    REQUESTS:
    Of course, GPU!! powered bakes. I need that extra time to increase quality of the bakes without dying in the wait.
    Bake selected button! kmon, I do have to rebake the whole thing just for new additions.
    Is it possible to bake proves only? because if not it should.
    Bake Just AO option.

    For an start baking AO mayy be fine, this shot is just AO from the stack fx.

    EDIT:
    It may hav eoverlapping uv as warning message says. dunno, that meshwas creater in editor with a tool that mergest different meshes. Now I should find a way to create uv2 for theese.... I don´t recall having theese issues in Beast.
     

    Attached Files:

    Last edited: Aug 9, 2018
    JamesArndt likes this.
  31. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    I'm baking this scene, first time it works with PLM, still too slow for the resolution that is outputing. GPU now, please, I honestly can´t get to understand why they whent CPU path.
    upload_2018-8-9_22-47-36.png
    upload_2018-8-9_22-48-14.png
    settings are the ones from above post
    upload_2018-8-9_22-48-31.png
     
  32. konsic

    konsic

    Joined:
    Oct 19, 2015
    Posts:
    822
    Would it be possible to replace enlighten in realtime GI with Progressive Lightmapper ?
     
  33. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,029
    Okay, the problem was indeed the backface tolerance.....but it took awhile to figure out because I thought "use a higher tolerance value" meant to increase the General GI: Backface Tolerance slider value. But that just made things worse, so I finally tried reducing it (to 0.12) and now the tree shadows are baked quite nicely! So I'm not sure why "higher tolerance value" = smaller value on the Backface Tolerance slider, but apparently it does. Problem finally solved, thanks.
     
  34. WermHat

    WermHat

    Joined:
    Jul 13, 2012
    Posts:
    62
    Is cookie baking supported yet?
     
  35. QuantumTheory

    QuantumTheory

    Joined:
    Jan 19, 2012
    Posts:
    1,041
    The problem is right there in the screenshot: your m rays/second. It seems Unity still has not fixed it or backported it as promised. CPU utilization is near nothing. It's like driving a Ferrari in 1st gear only.

    My post: https://forum.unity.com/threads/progressive-lightmapper.454362/page-13#post-3486636

    The reply was: https://forum.unity.com/threads/progressive-lightmapper.454362/page-14#post-3557556

    This is the issue that's holding back the lightmapper. The current CPU progressive preview lightmapper was lightning fast in 5.6. Either Unity accidentally created a bug, or purposefully slowed it down to build hype for the GPU lightmapper and are slow to provide a fix for such a critical feature for the past, well, 2 years. If you can, try 5.6 and see.

    I bet the GPU lightmapper will only be in the paid versions.
     
    JamesArndt and buttmatrix like this.
  36. XRA

    XRA

    Joined:
    Aug 26, 2010
    Posts:
    189
    Would it be possible to have the lightmapper use UV2 from an AdditionalVertexStream assigned to mesh renderers? I tried setting custom UV2 additionalVertexStream mesh in the Lightmapping.started event but the progressive lightmapper likely resets them.
    If set prior (& visible as being set), when lightmapping begins it clears away the additional vertex streams.

    Also related, controlling the raster position via the Meta Pass vertex shader doesn't change anything in progressive (haven't checked enlighten). The vertex positions can be all set to 0 and the scene will bake without issue. (using LWRP to test as it doesn't use the Unity cginc files)

    Basically I'm looking at ways to supply some custom per-chart packing prior to baking, the main requirement is without modifying the original meshes. So either through StructuredBuffers & modifying the raster position in Meta pass, or AdditionalVertexStreams. (The custom per-chart transforms would then be supplied via structured buffer / compute buffer at runtime as part of the render pipeline)

    The alternative right now is baking the lightmaps like usual and then repacking the baked result into the new texture and modifying the scene lightmap data which isn't too bad, but would be nice if eventually we could customize things with the lightmapper a bit more.
     
  37. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,095
    Try a higher pushoff value for the decals https://docs.unity3d.com/Manual/class-LightmapParameters.html. In large scenes 32 bit floating point precision will not be enough so you have to make sure the object is moved a bit from the raytracers point of view.
     
  38. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,095
    We are working on it, stay tuned :)
     
    optimise and lolclol like this.
  39. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,095
    No, not yet.
     
  40. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,095
    The meta pass can only generate albedo and emission, the position is not modifiable in that pass.
    Passing UV2 in an AdditionalVertexStream is not implemented, but it could be done. Please file a bug report with your test scene and we will take a look at your use case.
    The proper way for exposing custom packing would be for Unity to provide an API for atlassing/packing, instead of you having to modify positions. We worked on it during a hackweek but there is more work to be done there. It is in the backlog but no promises on when it will be ready.
     
    XRA likes this.
  41. kristijonas_unity

    kristijonas_unity

    Unity Technologies

    Joined:
    Feb 8, 2018
    Posts:
    385
    It is strange that you experiencing this issue - there is no reason why mixed lights would not work in your particular case (static lightmapped race track + dynamic vehicles). I have just tested a similar scenario in 2018.1.3f1 using shadowmask + a mixed directional light and everything was working as intended: a dynamic object (sphere) was lit by a realtime light casting a realtime shadow, and the environment was receiving a realtime direct light along with indirect contribution baked into the lightmap. Please see the image below:

    Unity_2018-08-30_12-36-14.png

    Could you please try baking your lightmap again using mixed lights? If you'd still happen to run into issues, perhaps you could upload a small repro project so that we could investigate the issue on our end? Thanks.
     
    JamesArndt likes this.
  42. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    921
    Hi,
    just today i did at least 5 attempts to lightmap a scene. It is not that big of a scene and i wait more than an hour every time on lower settings. Every time i am getting these weird issues where there are white spots like in the images below !

    Wonder what could cause this ? If i open the exr lightmap in image editor i am not able to paint on that area, it is like missing information.

    Lightmapping is really slow and tedious process because of these issues ( happening 90 % of the time ) and furthermore, the Progressive Lightmapper makes the whole compute unresponsive even on middle scenes. Any option to lower threads priority should be added because a PC becomes unusable while PLM is running.
    Enlighten does not affect PC performance that much while working though but it's kinda slow baker !

    THIS IS A LONG TIME EXISTING ISSUE NOW:

    What could cause this and how to avoid it !

    Currently using 2017.2.3 p1


    upload_2018-9-6_21-51-57.png

    upload_2018-9-6_21-52-24.png

    upload_2018-9-6_21-58-7.png

    upload_2018-9-6_21-59-6.png
     
  43. HenriSweco

    HenriSweco

    Joined:
    Aug 8, 2016
    Posts:
    28
    I used to have the same issue, but it hasn't appeared in a while.

    Is PLM still in preview for that Unity version? If so, you should upgrade to 2017 LTS if possible.

    I think technically it's not missing information(in photoshop) it's infinity white/black, which photoshop can't handle. A bug nonetheless. There was some way to fix it in photoshop but I can't recall.

    A temporary 'fix' might be setting the lightmap parameter 'Backface Tolerance' to 0 across the scene. It might also have something to do with lights intersecting geometry, or just geometry intersecting geometry.
     
  44. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    921
    Yep it is !

    Upgrade it's not an option when you are creating a package for the store and want to support lowest possible version !

    Most of the time appears on different objects actually and i feel that it happens in a scene where the load on the CPU becomes too big, it doe's not make sense but i think it happens mostly when PC resources are low - however not sure about that !
     
  45. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,675
    I'll check this out again soon and get back to you. It's not entirely my use case though. I don't want the environment affected by any real time lights whatsoever. It's a mobile project so all lighting, shadows and GI needs to be entirely baked to texture maps. The only object affected by the real time light should be the kart itself.
     
  46. kristijonas_unity

    kristijonas_unity

    Unity Technologies

    Joined:
    Feb 8, 2018
    Posts:
    385
    In this case, using culling masks (baked light for the environment + realtime/mixed light for the karts) would be the best solution. Looking back at your previous posts, seems like you've already discovered this solution yourself.

    Another possible solution would be writing a custom shader with fake specular, although not sure how feasible would that be in your case.
     
    JamesArndt likes this.
  47. Kubic75

    Kubic75

    Joined:
    Jan 2, 2017
    Posts:
    83
    UnityTechnologies,
    Please Don´t forget to give us a „Bake selected“ button.
    Its essential.
     
    SamAB likes this.
  48. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,095
  49. adpok

    adpok

    Joined:
    Oct 26, 2017
    Posts:
    28
    Has the bake caching broken in 2018.2.8? I change the filtering settings and it rebakes it all. Also what happened to the shaded wireframe mode in scene view?
     
    JamesArndt likes this.
  50. adpok

    adpok

    Joined:
    Oct 26, 2017
    Posts:
    28
    Cant help thinking it would be good to have more control of bake atlas's, such as being able to specify what geo goes into what map.
     
    JamesArndt likes this.