Search Unity

Night to day transition with baked lightmaps?

Discussion in 'Global Illumination' started by frogwise, Feb 3, 2018.

  1. frogwise

    frogwise

    Joined:
    Nov 27, 2009
    Posts:
    103
    Hey guys,

    I have a game about a little guy in a boat. The game session lasts 5 minutes, and over the course of that time, it goes from night time and ends at dawn. However, it's not real world environment that needs a physical sun or moving shadows - it just needs to feel like its going from night to dawn.

    This game is for WebGL 2.0 and up, so I would like to bake as much lighting as possible. The only thing that really needs a dynamic shadow is the little guy and his boat. Everything else can be baked.

    However, how can I got about baking nice bounced lighting and all that, while still allowing the scene to look like it's getting closer to morning? I find that if I bake my terrain and object lightmaps, they do not get affected by the main directional light getting brighter. This is true for trees (and their billboard lods as well)

    TL;DR

    I have a scene that transitions from night to day, but it doesn't need a moving sun source.
    I only need my directional light (sun) to cast dynamic light and shadow on/from my main character.
    The rest of the world can be baked.

    How do I set this up so that I can bake most of my lighting, but still transition it from night to day?
     
    jamesdeantv likes this.
  2. kemalakay

    kemalakay

    Unity Technologies

    Joined:
    Jul 12, 2016
    Posts:
    224
    Hey @frogwise

    First, there's this tool that you can check: https://github.com/laurenth-unity/lightmap-switching-tool
    This will allow you to change baked lightmaps at runtime.

    But as far as I understand, you want indirect light to be baked for all static geometry and use realtime shadows and lighting for your main character. Then I suggest using `Baked Indirect` light mode with a single mixed directional light. Unlike Shadowmask mode, you won't have shadows beyond shadow distance but that also depends on your scene setup. You can find the details about this mode here: https://docs.unity3d.com/Manual/LightMode-Mixed-BakedIndirect.html

    Thanks
     
  3. frogwise

    frogwise

    Joined:
    Nov 27, 2009
    Posts:
    103
    Hey @kemalakay

    Thanks for the very clear reply. I've read a little but about baked indirect, but I was worried that it has to large of a performance hit for webgl compared to the others. Is this true?

    To get a better understanding of my scene, here are two screenshots - one from the start of the game (night) and one from the end (daytime). The only thing that needs dynamic lighting and shadows is the character - everything else can be baked. As you can see, the sun shadows don't move - the only thing that changes are:

    Sun Intensity and Color
    Ambient Intensity and Color
    Fog Color

    As you can imagine, baking lightmaps means that they are baked at a particular time of day, and changing those values above has no effect on static baked objects. Also, the tree billboards in the back are stuck in one lighting scenario too :(

    upload_2018-2-4_11-54-4.png

    upload_2018-2-4_11-54-29.png
     
  4. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    For games with large outdoors areas realtime lightmaps in a lower resolution make lot more sense.
    It only updates if you change a light that is contributing the to GI.
     
  5. frogwise

    frogwise

    Joined:
    Nov 27, 2009
    Posts:
    103
    Interesting, thanks for this. Could you elaborate a bit more about the performance implications of going with realtime lightmaps vs. baked? Especially for WebGL, if possible.

    Also, which settings would you suggest to have? Right now, I am using "Mixed" for my main light source, and both Realtime GI and Baked GI checked in the lighting settings.
     
  6. kristijonas_unity

    kristijonas_unity

    Unity Technologies

    Joined:
    Feb 8, 2018
    Posts:
    1,080
    When using WebGL, I would strongly suggest against using any type of realtime lighting solutions, as they are very performance intensive, especially in WebGL. If you absolutely need to have a dynamic day and night cycle in your game, I'd suggest the following:
    • Make sure that you have only one realtime directional light in the scene, which simulates the sun/moon, which casts no shadows.
    • Make sure to use Forward Rendering path.
    • Bake your entire environment using Baked Indirect lighting mode, using a neutral light color, which could fit both day and night scenarios.
    • Set as many objects as you can to Static to benefit from baked GI and static batching.
    • Do not use realtime shadows for your character/NPCs; instead, rely on the blob shadows, which can be achieved using the projector component in Unity - https://docs.unity3d.com/Manual/class-Projector.html
    These are just some guidelines to follow, in order to make sure that you get the best possible performance, while maintaining visual fidelity on WebGL.
     
    Teocuitlatl likes this.
  7. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,913
    Just use realtime lighting/shadows. Performance in WebGL is good. Just enable WebAssembly and Graphics Jobs in Player Settings. You can even use any image effects you want.
     
  8. frogwise

    frogwise

    Joined:
    Nov 27, 2009
    Posts:
    103
    Thanks @kristijonas_unity and @Stardog , but those seem to be conflicting opinions :)

    To Stardog's point, the Unity manual itself says that the performance of WebGL applications should be close to native GPU applications.

    upload_2018-2-25_21-36-41.png

    Also to your point, Stardog - I found the Graphics Jobs checkbox and enabled it. What does it do exactly?

    I cannot find anything for WebAssembly, though

    upload_2018-2-25_21-40-50.png
     
  9. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,913
    I think WebAssembly is in Publishing at the bottom.

    Here's some WebGL examples I made that I get 60 fps with (2500k cpu, GTX 1060). Use a fresh browser session with few tabs loaded. You need to right-click to enable mouse sometimes.

    Realtime shadows. This one should give memory error when increasing the Grass Distance to full, and putting the Grass Amount near the top:
    https://cdn.rawgit.com/st4rdog/WebGLExports/f4b0f2b2/2017.10.24/index.html

    Realtime shadow, baked at distance:
    https://cdn.rawgit.com/st4rdog/WebGLExports/f4b0f2b2/2017.04.12/index.html

    Realtime shadow, baked indirect:
    https://cdn.rawgit.com/st4rdog/WebGLExports/f9eb54b9/2017.9.1/index.html

    Realtime shadows. Left-click drag to move. Right-click look around:
    https://cdn.rawgit.com/st4rdog/WebGLExports/f1a4bf2b/2017.11.08/index.html

    The main problem with WebGL is memory and polycount. I have only had performance problems with some skinned meshes using the navmesh. Too much grass on a terrain will also cause the game to hit the memory limit. Increasing it beyond 256 doesn't do anything for me.

    Also, another thing, you will have to edit your game with WebGL 2.0 graphics emulation (Edit > Graphics Emulation > 2.0). The fun part is that Unity won't remember this so you'll have to do it everytime you load the game.
     
    Tashkeel and custardhilt like this.
  10. frogwise

    frogwise

    Joined:
    Nov 27, 2009
    Posts:
    103
    Fantastic information and experiments, @Stardog Thanks so much.

    Your Fortnite example is probably most relevant to my project - terrain, grass, third person camera, etc.

    And ya - that damn bug that resets your WebGL 2.0 emulation eeeeverytime!
     
  11. frogwise

    frogwise

    Joined:
    Nov 27, 2009
    Posts:
    103
    Curious - what are your light settings for the Fortnite example? Here are mine.

    upload_2018-2-26_21-48-53.png
     
  12. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,913
    It's the same except Default Skybox, no Realtime Global Illumination, and Linear fog 30, 170.

    Also, at default settings the tris are about 90k, 56 set pass calls, 50 shadow casters. There is 3000 trees, but camera draw distance is only 220.
     
  13. frogwise

    frogwise

    Joined:
    Nov 27, 2009
    Posts:
    103
    Interesting - so if you have both Realtime Global Illumination and Mixed Lighting OFF, then you must not have any of your scene objects as "Static"? Otherwise, how are you getting any environment lighting?
     
  14. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,913
    Only the terrain is static, but not Lightmap Static. Everything has to be dynamic because blocks can be placed and trees cut down.
     
  15. Absinthe23

    Absinthe23

    Joined:
    Feb 1, 2015
    Posts:
    16
    @frogwise Necroing an ancient post but just wanted to say your game looks really pretty. Did it get released?