Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bakery - GPU Lightmapper (v1.96) + RTPreview [RELEASED]

Discussion in 'Assets and Asset Store' started by guycalledfrank, Jun 14, 2018.

  1. lolclol

    lolclol

    Joined:
    Jan 24, 2013
    Posts:
    212
    did a quick render but its not lighting interior of the building, i added skylight only. any help?
     

    Attached Files:

  2. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,667
    It's possible the probes are wrongly positioned, being stuck inside of other objects, therefore reporting complete shadow. I wonder if that's the case. You can make Unity visualize baked probes in the Lighting window (scroll to bottom -> Debug Settings -> Light Probe Visualization)
     
  3. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,667
    Yep, you should probably disable shadow casting on window glass :)
     
  4. lolclol

    lolclol

    Joined:
    Jan 24, 2013
    Posts:
    212
    yep that did the job, thnx
     

    Attached Files:

    RockSPb and guycalledfrank like this.
  5. PaavoHapponen

    PaavoHapponen

    Joined:
    Sep 10, 2014
    Posts:
    6
    I also get this issue.
    It corresponds to these lines in ftModelPostProcessor / AdjustUV()
    Code (CSharp):
    1.  var nm = m.name;
    2. #if UNITY_2017_1_OR_NEWER
    3.             if (deserializedSuccess && deserialized.meshName != null && deserialized.padding != null)
    4.             {
    5.                 // Get padding from extraUserProperties (new)
    6.                 int mindex = deserialized.meshName.IndexOf(nm);
    7.                 var padding = deserialized.padding[mindex];  //////// bug: mindex == -1
    8.                 uparams.packMargin = padding/1024.0f;
    9.                 Unwrapping.GenerateSecondaryUVSet(m, uparams);
    10.             }
    It turns out IndexOf(nm) returns a -1 for mindex, as in mesh name does not exist in the meshName list, which obviously fails.
    This tends to happen with scenes with a lot of objects.
    I have tried baking the scene enabling and disabling objects to find which triggers it but it only happens when everything is enabled.
    I have not found a clear cause as of yet.
    On Unity 2017.4.16.
    Meshes have been set to 16bit index.
    Drivers are up to date, latest bakery release.
     
    guycalledfrank likes this.
  6. XRA

    XRA

    Joined:
    Aug 26, 2010
    Posts:
    265
    32 samples & scene geo is pretty complex, it bakes fine without skylight (with 10-20 other bakery lights + a directional). I also baked a much larger scene with a skylight without issue too.

    With that in mind I've been disabling some of the meshes and got it to bake, once I figure out which mesh is causing the issue I'll see if anything seems wrong with how it was authored & let you know!

    btw Bakery is an excellent asset, great work :)
     
    guycalledfrank likes this.
  7. mehrankan

    mehrankan

    Joined:
    Apr 12, 2015
    Posts:
    61
    So I should get a bigger card I guess?
    upload_2019-1-9_12-11-16.png
     
  8. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Or set a smaller tile and "max resolution", lower the samples and lower the texels per unit.
    Start from the lowest settings and slowly go up a single parameter every time so you better understand what has a bigger impact on quality.
     
    guycalledfrank likes this.
  9. mehrankan

    mehrankan

    Joined:
    Apr 12, 2015
    Posts:
    61
    thanks man, I will try that. I did bring down the bounces and the texel resolutions, but never tried the max-resolution setting.
     
  10. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,667
    Just sent you a patch.

    I noticed that happening sometimes. Doesn't seem to break the baking process, but may exclude some objects from the UV padding adjustment. Will investigate further.

    You should also try 16-24 samples instead, it's quite enough if the scene is not too occluded. 16 is decent for most city-like scenes, 32 is good for closed spaces.

    Default Tile Size (512) has a rather modest VRAM footprint. Should probably leave it unchanged.
    Samples (GI, Skylight, light shadows), Texels and Max Resolution is indeed what you should try to reduce.

    Bounces don't affect memory usage at all
    . They only take more time to bake.

    How big is the scene, what card do you have and what was your Texels value?
     
    greengremline likes this.
  11. innolabs

    innolabs

    Joined:
    Dec 26, 2016
    Posts:
    3
  12. greengremline

    greengremline

    Joined:
    Sep 16, 2015
    Posts:
    183
    Hey we are noticing differences between our rooms in a build versus the editor - any idea what might be causing that?

    Editor (correct):


    Build (weird):
     
  13. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,667
    Did you add Bakery light components at all?
    Lighting data asset should not be generated unless you bake light probes. Lightmap data is stored differently.

    Hard to tell exactly from these screenshots. Depends on your render mode/directional mode/build shader stripping settings.

    Actually I have some idea: last time we spoke you were using RNM. Artifacts on the 2nd screenshot look like distorted specular. RNM specular requires tangents to be present in the mesh. Unity may remove tangents from builds/bundles if it thinks it's not used by the shader. You can disable it somewhere in Player settings.
     
  14. greengremline

    greengremline

    Joined:
    Sep 16, 2015
    Posts:
    183
    Okay - sorry I had incorrect information, the previous images were 1) Editor in editor mode, 2) Editor in play mode / builds

    Here's another example: Editor scene view in editor mode:


    Editor scene view in play mode:



    I tried unchecking the checkbox as you mentioned "Optimize mesh data" and disabled vertex compression but this is still happening



    Perhaps due to rotation of the prefab? This occurs when this prefab is a hard referenced asset in the editor so it shouldn't have anything to do with asset bundle weirdness, but who knows lol
     
  15. hrgchris

    hrgchris

    Joined:
    Oct 26, 2016
    Posts:
    17
    We'd like to automated the process of baking using our own scripts. The basic process would be that we generate some objects in a scene, create a prefab of them, then want to run bakery on them with a programmatically chosen set of options. How would we go about doing this from script. I'm guessing the option is there in some form, even if not clearly exposed?

    Also, when we instantiate the prefabs, we won't necessarily instantiate them with the same transform as the one from which they were baked. I'm guessing this isn't a problem? i.e. the light map will look the same as it's been baked in.

    Thanks

    Chris
     
  16. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,667
    Oohh yeah. You can't rotate things with RNM/SH lightmaps, it will bend the lighting in a wrong way.

    Seems like a popular question.
    So yeah, you can do that, but you'll need to change ftRenderLightmap.cs a bit (or wait for the next update).
    - If you call ftRenderLightmap.FindRenderSettingsStorage(), you will get a ftLightmapsStorage object containing render settings. You can them modify them as you wish (variable names start with "renderSettings", e.g. renderSettingsTexelsPerUnit).
    - You will need to initialize Bakery window with these settings. I've added a single method to do that, but for now you'll need to make OnEnable function public and do something like that:

    var instance = (ftRenderLightmap)EditorWindow.GetWindow(typeof(ftRenderLightmap));
    instance.OnEnable(); // in case window was already present
    instance.Show(); // in case it wasn't


    - Then you can declare a method like that and call it:

        public void RenderButton()
    {
    if (!TestSystemSpecs()) return;
    selectedOnly = false;
    progressFunc = RenderLightmapFunc();
    EditorApplication.update += RenderLightmapUpdate;
    }


    Only a problem for RNM/SH modes. Classic color/shadowmask/directional should be fine.
     
  17. angelo9888

    angelo9888

    Joined:
    Feb 16, 2013
    Posts:
    9
    It doesn't seem to be a light probe problem. :/
     

    Attached Files:

  18. angelo9888

    angelo9888

    Joined:
    Feb 16, 2013
    Posts:
    9
    Ok I found out what's happening. The lights are mixed so the walls (static) don't cast shadows on real time objects so the light passes through. Do you know any work around maybe?
     
    guycalledfrank likes this.
  19. praesidenter

    praesidenter

    Joined:
    Mar 5, 2016
    Posts:
    36
    Does Bakery support HDRP rectangular and line lights? As I understand these are the HDRP replacements for area lights, but I couldn't get them to work.
     
  20. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,667
    Perhaps you can try copying the walls, making them non-static and setting Mesh Renderer -> Cast Shadows = Shadows Only?

    Bakery has its own component called Light Mesh that can make any geometry (be it a quad, a tube, a bunny) emissive. Currently they're supposed to be baked only. I'm not sure if HDRP realtime area lights support shadowmasking.
    You should be able to use Bakery to render indirect-only lighting (bounces) caused by area lights and combine it with realtime HDRP lighting.
     
  21. angelo9888

    angelo9888

    Joined:
    Feb 16, 2013
    Posts:
    9
    Still gives me bad lighting on real time materials. One workaround is to reduce the range of the point lights to fit the room, but then your lights are really low. Also I still have a bunch of black real time objects throughout the scene and I think the problem is that in mixed mode the real time objects are getting real time lighting from the light probes, which shouldn't be the case.
     
  22. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,667
    Are you sure it's related to Bakery? Mixed lighting and probes (with "occlusion probes" enabled) works the same way as with built-in lightmappers (at least it's supposed to).
     
  23. angelo9888

    angelo9888

    Joined:
    Feb 16, 2013
    Posts:
    9
    Ok what fixed my problems was add another light with bake indirect enabled. Perhaps the shadowmask doesn't bake lights into the probes? I don't know.
     
  24. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,667
    Shadowmask will bake shadow occlusion + indirect part of the light. Final lighting will be calculated as [realtime_light * baked_occlusion + baked_indirect].

    If you enable "bake to indirect" on the light, it will be baked completely. Shadowmask won't be used, and final lighting will be 100% baked. Realtime light component is meant to be disabled in this mode.
     
  25. angelo9888

    angelo9888

    Joined:
    Feb 16, 2013
    Posts:
    9
    Ok everything fixed! It seems that the problem was that I had the static checkbox, checked on the light for some reason. My bad!
     
    guycalledfrank likes this.
  26. aeldred28

    aeldred28

    Joined:
    Dec 16, 2017
    Posts:
    30
    Does bakery support light probes in the latest update? As in, if I render them will they work when instantiated?
     
  27. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,667
    It currently only supports standard Unity light probes, and these can't be instantiated (engine limitation). But a better system (both baking and runtime) is on the roadmap.
     
    Mark_01 and lolclol like this.
  28. Wriggler

    Wriggler

    Joined:
    Jun 7, 2013
    Posts:
    133
    Hi Frank,

    Thanks for your excellent work on Bakery. We're struggling to get the baked textures working with asset bundles, so I was hoping you might explain your process in more detail so we might see where we're going wrong? Here's what we're doing:
    • Baking a scene using Bakery
    • Bundling the scene into one asset bundle, and the baked hdr/tga files into another
    • At runtime, first loading the hdr/tga bundle and then loading the scene from it's bundle.
    • Result: no lightmaps visible, the lighting window reports as having 0 lightmaps loaded.
    So how did you guys get it working? Did you do something in a different order? Or did you re-apply all the textures in LightmapSettings.lightmaps[] manually?

    Thanks for your help!

    Ben
     
    guycalledfrank likes this.
  29. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,667
    Thanks! TBH, I never tested bundles myself, but I know people are using them. You should probably ask zornor90 - they use bundles a lot. But as far as I understand, they build a complete section of the world into a bundle (geometry + lightmaps). Separating maps and objects to different bundles may not work - is there any particular reason you decided to split them like that?

    Right after you load a scene/load a bundle/instantiate a prefab, a script is called that assigns lightmaps to corresponding objects. If lightmaps are not present in memory at this point, the script won't do its job correctly. Loading just the textures won't trigger any event that would apply them.
     
  30. Wriggler

    Wriggler

    Joined:
    Jun 7, 2013
    Posts:
    133
    Thanks for getting back to me so quickly!

    Actually I was under the impression that scenes and assets needed to be separated in bundles; Unity gets angry if you try to bundle scene and non-scene files together in the same bundle. I'm not sure whether lightmaps are an exception to this, but that's how we've been handling things so far...

    Ah, that's interesting. So we *are* loading the lightmaps into memory before loading the scene, so I don't think that's the problem. The script you mention: is that a Bakery script, or a Unity script? Our current setup is to only include Bakery in our game during the baking process. It is then removed from the actual game during the main game build step, so Bakery isn't present in the final game binary. The assumption was that the constructed lightmaps would work on their own without the rest of the Bakery stuff being required at runtime. Is that not the case?

    @zornor90 - any additional insight you have on this would be very welcome indeed. Thank you very much!

    Ben
     
  31. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,667
    You can probably make a prefab instead of a scene. It will still contain same objects with same components and stuff.

    Hmmm interesting. In this case perhaps the link between the script and the maps is broken. I'm not sure how cross-bundle asset references are supposed to work.

    Aha, so perhaps that's the actual problem. There are two Bakery folders: Assets/Editor/x64/Bakery and Assets/Bakery.
    First is editor only and doesn't go to builds. Second is actually needed, because there are scripts that apply the lightmaps (in fact there are just about 5 required scripts - they are listed in FAQ). Currently it's the only way custom lightmaps can work in Unity.
    Bakery creates an invisible object (called !ftraceLightmaps) in your scene and stores an array of lightmaps there. When the scene is loaded, the maps are applied.
     
  32. greengremline

    greengremline

    Joined:
    Sep 16, 2015
    Posts:
    183
    @Wriggler We only use prefabs so we don't use lightmaps in the scene, but based on my reading, I believe the issue is probably just the bakery scripts not being included in your build

    It sounds like you understand the asset bundle order of operations, so long as the lightmap texture is loaded into memory before the scene with the bakery object referencing it, unity will be able to connect the dots (of course if the bakery monobehaviour is missing then all bets are off)
     
    guycalledfrank likes this.
  33. Lakuza_

    Lakuza_

    Joined:
    Jan 12, 2019
    Posts:
    2
    First off, I love bakery. The project I've been working on would not light bake with normal means, but with bakery I can bake everything with ease :D

    I wanted to ask how to go about crunch compressing the lightmaps. I have baked them to 4k lightmaps and the total size is 192mb (16mb per lightmap image).

    I tried to do crunch compression like I've done normally which is selecting the lightmap image and clicking the crunch checkbox in the inspector and after it supposedly performs the crunch, the file size is still 16mb for each lightmap.

    I'm using Unity 2017.4.15f1

    (Also my technical knowledge with unity is really low, the project I'm walking on is a hobby project to learn unity)
     
    guycalledfrank likes this.
  34. greengremline

    greengremline

    Joined:
    Sep 16, 2015
    Posts:
    183
    Hm are you referring to the light itself or the prefab containing the lightmaps? We've been able to rotate the prefab itself no problem previously

    I think the issue might be in fact due to mip maps / texture streaming

    In both these images, unity's texture streaming system is running

    Image 1 (Lightmap textures have no mipmaps and streaming is disabled on them)



    Image 2 (Lightmap textures have mipmaps and streaming is enabled on them)



    Are you familiar with what might be causing this at all? I wonder if it has to do with how mipmap generation affects textures, but I'm not sure...if it is related to streaming there will probably be a lot of people asking this question as it becomes more and more popular to use since 2018.2 released it
     
  35. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    Hello Frank,

    i have a massive scene with around 800 objects.
    It s baking fine in 1/12 of the Enlighten time on 2x 1080 GTX.

    Every geometry has 5 LOD with same UV Layouts.
    I use

    LightmappedLOD.cs
    https://github.com/laurenth-unity/LODLightmapScripts/blob/master/README.md


    on LOD 1 to LOD 4 who simply copys the Lightmap from LOD0 on awake.

    Is there a easy way to configure Bakery to not render the LOD 1 to 4 to save some more time.
     
    Last edited: Jan 12, 2019
    lolclol and guycalledfrank like this.
  36. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,667
    Crunch compression should reduce build size/loading time, BUT it does nothing for video memory. After textures are un-crunched back, they use regular GPU-supported compressed format (e.g. DXT on PC).
    There isn't much to do about it. If you're shipping on PC/modern console, 192mb might be not that bad. If it's a more limited platform, then you should probably reduce resolution. Also check if there are any holes in the lightmaps - Unity isn't good at efficient unwrapping, so maybe some objects need a better UV layout (which most modeling packages can generate). If the scene is very large, maybe you can split it into chunks and load/unload them at runtime.

    The prefab. Hmm. Right, my bad. There is actually no problem rotating RNM-baked objects - but there is with SH.

    Mipmapping is usually disabled on lightmaps. Bakery does disable it on texture assets - otherwise you would get weird artefacts. Tight texture atlases can't be simply downsized, because different UV charts start to leak over each other.

    Did you enable it manually? If so, you shouldn't.

    Nice one!

    Perhaps you can just remove "Lightmapped static" from the LODs? Script seems to be assigning the lightmap on its own anyway.
     
  37. Ignacii

    Ignacii

    Joined:
    May 23, 2013
    Posts:
    106
    Hi! Great asset but I have a question.

    I would like to bake mountain's shadow without Distance Shadowmask but shadows of trees has to have it. What should I do? Is this possible? Can't think of solution myself.



    Thank you
     
  38. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,667
    Hi, thanks!
    Distance shadowmask is governed by the engine and it's global. Basically it renders fully realtime shadows from mixed lights close to camera and uses baked shadows beyond the shadow range limit.
    If I understand correctly, you want mountain shadow to be baked, but tree shadows remain realtime?
    If so, perhaps you can make trees non-static, disable Distance Shadowmask and bake Occlusion Prbes? Then what you'll get is:
    - Mountain shadow will be baked
    - Trees will cast dynamic shadows (mixing with baked)
    - Occlusion probes will darken the trees placed inside mountain's shadow.
     
    Ignacii likes this.
  39. Ignacii

    Ignacii

    Joined:
    May 23, 2013
    Posts:
    106
    Thanks for the quick response! That's exactly what I am looking for. Never baked occlusion probes before. Will try and let you know if I stumble somewhere.

    Thank you
     
    guycalledfrank likes this.
  40. greengremline

    greengremline

    Joined:
    Sep 16, 2015
    Posts:
    183
    Gotcha, I was trying to make our streaming system as fast as possible, but it's good to know that mips should be disabled on lightmaps - thanks for the clarification
     
    guycalledfrank likes this.
  41. Lakuza_

    Lakuza_

    Joined:
    Jan 12, 2019
    Posts:
    2
    Its purely for build size/loading time that I want to crunch compress them if it is possible. My project is a world for Vrchat so download time for other users is my main concern as my project is already larger than most worlds in that game.
     
  42. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,667
    Then crunch compression must work - unless Unity disables it for lightmaps specifically. There is nothing special about Bakery lightmap assets, they are treated as any other texture by the engine.
     
  43. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    Damn. Thanks. Thats was easy. Works nearly perfect.
    Only Animated Crossfade LOD shows some glitches.
    Could be managed by disable Animation Crossfade.
    Crossfading works.

    This method saves a lot of baketime for heavy lod scenes.
    Directly invested back in bake quality.)
     
    guycalledfrank likes this.
  44. DEEnvironment

    DEEnvironment

    Joined:
    Dec 30, 2018
    Posts:
    437
    guycalledfrank likes this.
  45. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,667
    Perhaps you're switching the wrong gizmo? Direct/Sky/Point have different components and different checkboxes.

    upload_2019-1-13_0-35-7.png
     
  46. lilmatsix

    lilmatsix

    Joined:
    Oct 29, 2017
    Posts:
    3
    I've been trying to get this working with asset bundles. The lightmaps don't seem to load.
     
  47. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,667
    Any details?
     
  48. lilmatsix

    lilmatsix

    Joined:
    Oct 29, 2017
    Posts:
    3
    I built a scene into a bundle. I tried manually selecting lightmap modes in graphic settings too. But as soon as the scene gets loaded into whatever I'm trying to load it in the lightmap shadows don't work.
     
  49. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,667
    Others seem to get it working well. Did you remove Bakery scripts from the build? Are there any errors in the built game's log?
     
    Last edited: Jan 13, 2019
  50. Wriggler

    Wriggler

    Joined:
    Jun 7, 2013
    Posts:
    133
    Ah yes, sounds like that'll be it. I figured that I was missing an extra step somewhere. I'll give this a shot when I'm back in the studio. Thanks for the help!

    Ben