Search Unity

  1. How can our website serve you better? Give us your feedback. Take our survey and let us know.
    Dismiss Notice

Help Wanted Proper workflow when using cubemap for lightmapping as well as camera background?

Discussion in 'Global Illumination' started by AzurySimon, Feb 17, 2021.

  1. AzurySimon

    AzurySimon

    Joined:
    Jul 16, 2018
    Posts:
    34
    I am using Unity 2020.1 and URP 9. I have an outdoor scene which is currently using a panoramic HDR cubemap as a skybox. I want to lightmap this scene as well, ideally with my cubemap to ensure a certain degree of consistency in my lighting.

    Right now when I set a "Skybox Material" in my Lighting/Environment settings, it is both used for lightmapping as well as a backdrop for my camera. I can override the cameras behaviour by using a Skybox component.
    My cubemap contains a sun, which of course influences lightmapping quite a bit, but this obviously does not create realtime shadows, so I would like to replace it with a directional light.

    What would be the best way to achieve a good lighting in my case? Should I create a second HDR cubemap (possibly lowres and/or blurred) from my original cubemap with the sun removed, so I can use this for lightmapping while overriding this cubemap with the "real" one on camera? This would also make it possible to use a properly tonemapped LDR cubemap for my camera?

    Will the skybox material (and texture) in my lighting settings be included in my build, even when it is never really used beyond lightmapping (seems inefficient)?

    Or is there another workflow I am not aware of? It seems to be kind of a hassle to explicitly override the cameras background using a skybox component as well as using a second manually created asset for this.
     
  2. kristijonas_unity

    kristijonas_unity

    Unity Technologies

    Joined:
    Feb 8, 2018
    Posts:
    655
    Hey! I suppose you could do one of the following:
    • Map a HDRI of your choice to a skydome mesh. Scale it so that in encompasses the entire level. Make sure that the mesh does not cast any shadows, has no collisions, and is not lightmapped. Also, disable mipmaps for the HDRI in the texture import settings. This would allow you to use one HDRI for lightmapping (in the environment settings), and another for your visual environment (skydome).
    • You could try and write a script, which spawns an emissive sphere aligned to the directional light normal. In this way you would need to assign a "sunless" HDRI in the environment settings. Emissive sphere (or any other mesh of your choice), would act as a fake sun.
    I hope this helps.
     
  3. AzurySimon

    AzurySimon

    Joined:
    Jul 16, 2018
    Posts:
    34
    Thank you for your reply, you mention some interesting alternatives.
    However I am more interested in what the general expectation here is. Is using different cubemaps for lightmapping vs visual environment a common scenario?

    If so, why does Unity not provide better built-in methods to achieve this? Right now I can select the source of "Environment Lighting", but they are only "Skybox", "Gradient" and "Color". If it is common to use different cubemaps for lightmapping and visual environment why not provide another option "Custom Skybox" there, or provide two skybox slots?
     
  4. kristijonas_unity

    kristijonas_unity

    Unity Technologies

    Joined:
    Feb 8, 2018
    Posts:
    655
    The most common approach to this is the skybox method I've suggested earlier. It is not limited to Unity either.

    HDRP offers a volume based approach. This allows you to assign different skybox shaders on a per-volume basis (be it local or global). Advantage of this that visual and baking environments are decoupled from each other. And it allows you to have multiple visual environments per scene, and blend between them, if needed.

    There are no plans to implement this functionality in the built-in RP.
     
unityunity