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

Question Baking lightmaps from script (Batch mode)

Discussion in 'High Definition Render Pipeline' started by Chris_Webb, Sep 28, 2022.

  1. Chris_Webb

    Chris_Webb

    Joined:
    Mar 18, 2014
    Posts:
    128
    Hello,

    I am trying to bake lightmaps from batch mode (as an automated process on our build machine), but noticed the lightmaps generated in this context are incorrect, lacking sky ambience.

    I noticed this error in the log, which makes me worry this might not be possible.

    Code (CSharp):
    1. Static Lighting Sky is not ready for baking. Please make sure that at least one frame has been rendered with HDRP before baking. For example you can achieve this by having Scene View visible with Draw Mode set to Shaded
    Is there any way to automate lightmap baking in HDRP in batch mode? Is there a method I can call to force HDRP to update the static lighting?

    Thanks for the help
     
  2. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    429
    Couldn't you just wait at least one frame before baking?
     
  3. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    695
    You should also be able to call Camera.Render to force a frame to render, before trying to bake ?
     
  4. Chris_Webb

    Chris_Webb

    Joined:
    Mar 18, 2014
    Posts:
    128
    I have tried to manually call render on the scene view camera, but this doesnt work in batch mode, but does work in editor (there is no scene view camera in batch mode obviously). I will try to create a temporary camera in the scene and force render that.
     
  5. Chris_Webb

    Chris_Webb

    Joined:
    Mar 18, 2014
    Posts:
    128
    I have tried creating a camera and rendering that before baking, but still get the static sky lighting error.


    Code (CSharp):
    1.                
    2. GameObject bakeCameraGO = new GameObject("BakeCameraGO");
    3. bakeCameraGO.hideFlags = HideFlags.DontSave;
    4. HDAdditionalCameraData hdData = bakeCameraGO.AddComponent<HDAdditionalCameraData>();
    5. Camera bakeCamera = bakeCameraGO.GetComponent<Camera>();
    6. bakeCamera.Render();
    7.  
    8. Lightmapping.Bake();
     
  6. Chris_Webb

    Chris_Webb

    Joined:
    Mar 18, 2014
    Posts:
    128
    There is no scene view in batch mode, waiting a frame does not render anything.
     
  7. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    429
    You don't need a scene view for rendering to happen afaik. The rendering should happen as usual (I think) whether you are in batchmode or not (this won't probably apply if you throw a nographics flag, but I don't think that this is the case). You should be able to do it with editor coroutines probably as baking the lightmaps won't be probably possible during the playmode.
     
  8. Chris_Webb

    Chris_Webb

    Joined:
    Mar 18, 2014
    Posts:
    128
    I just tried using editor coroutines, rendering with a fresh camera manually, then waiting several seconds, then baking lightmaps, and I still get the initial error and incorrect probes.
     
  9. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    429
    have you tried running your automation process without the batchmode to verify that everything is working as expected to verify that it is indeed batchmode only issue?
     
  10. Chris_Webb

    Chris_Webb

    Joined:
    Mar 18, 2014
    Posts:
    128

    I just tried running it out of batch mode, and it works fine :) Definitely seems to be a batch mode issue.
     
  11. TheAlterian

    TheAlterian

    Joined:
    Aug 9, 2013
    Posts:
    2
    I am wondering what you are using to automate your light bakes? Is it a custom tool you wrote or did you find one? I am trying to find a way to bake out a bunch of scenes without having to manually open each one and click the bake button for a project I am working on.
     
  12. Chris_Webb

    Chris_Webb

    Joined:
    Mar 18, 2014
    Posts:
    128
    We are using jenkins to call an editor script we wrote. This is still an issue for us :(
     
  13. Chris_Webb

    Chris_Webb

    Joined:
    Mar 18, 2014
    Posts:
    128
    Hello

    I hate to bump, but has anyone managed to bake lightprobes correctly from batch mode, as part of an automated build pipeline?

    We get somewhat correct probes, but they are missing sky ambience.

    Currently we are launching in batch mode, then starting an editor coroutine, which opens the scene, waits 5 seconds, renders, waits 5 seconds, then calls Lightmapping.Bake. This is an attempt to get unity to generate the ambient lighting, which seems to be an asynchronous process.

    When we run this method from the editor, it works fine, but running via command line in batch mode gives incorrect results.

    I'm running out of ideas for hacks to make this work :)

    Thanks