Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Dynamic Lighting Vs Baked: Which one is better?

Discussion in 'General Discussion' started by lahicksfamilia, Jun 19, 2013.

  1. lahicksfamilia

    lahicksfamilia

    Joined:
    May 13, 2013
    Posts:
    77
    Im new to Unity and im trying to wrap my head around dynamic vs baked lighting. What i understand so far is that with dynamic lighting everything is lit in realtime and looks better but performance can take a bit of a hit. Baked lighting turns your lighting into textures thus not delivering realtime shadows. Im i correct so far?

    My question is...is it possible to do an entire game with just the dynamic lighting? If so then why used Baked lighting? Can they both be used together? If so then what would be the benefit of that?

    What say you guys?
     
  2. Neo_

    Neo_

    Joined:
    Nov 3, 2012
    Posts:
    36
    What say you guys... ?

    Just read the reference manual first :)
     
  3. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    Yes, it is possible to do dynamic lighting, put performance will go down the drain VERY fast if you use all pixel lights.

    Baked lighting can be used with dynamic- better perfomance for static objects, and dynamic ones get lit in realtime (generally by faster vertex lights)

    Baked lighting has shadows in Unity Free, but doesn't pick up normal maps; can't comment on Pro as I don't have it (yet) :).
     
  4. lahicksfamilia

    lahicksfamilia

    Joined:
    May 13, 2013
    Posts:
    77
    Thanks for the response. Ive been researching it but just wanted to hear from people who are using it. Thanks
     
  5. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,613
    It's not that dynamic necessarily 'looks' better, it's that it's... well... dynamic. Lights can move and change. Objects can move and change and have their lighting update. As we're in the business of making games rather than static art demos, dynamism is pretty important.

    Baked lighting actually has the potential to look better, as the baking process can simulate the behaviour of light in a way that's too expensive for realtime/dynamic methods (e.g. simulating the way light bounces off surfaces).

    (Oh and that's using Directional Lightmaps / RNMs of course).
     
  6. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Not just the potential, IMO it is very difficult to make it look as bad as real time.
     
  7. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,613
    Well if you set bounces to 0, use low-resolution maps, and only use them in Single mode, then it'll look worse.
     
  8. Windexglow2

    Windexglow2

    Joined:
    Sep 23, 2012
    Posts:
    90
    Dynamic lighting recalculates the lights quite often, so it needs to cut corners to look nice.
    Baked lighting has all the time in the world, so it can make much more complex lighting.

    It depends on the game, but I think you can just use both without major issue.
     
  9. Aiursrage2k

    Aiursrage2k

    Joined:
    Nov 1, 2009
    Posts:
    4,835
    Well I think dynamic lighting actually looks better unless you are running on mobile or have an artist to tweak it and constantly rebake the scenes to get it to look good.
     
  10. lahicksfamilia

    lahicksfamilia

    Joined:
    May 13, 2013
    Posts:
    77
    what if im building something like an outdoor ruin and all i need it sunlight? Would dynamic work better than baked?
     
  11. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,888
    Again, it depends how you set it up. For static lighting, there's not reason really not to bake lighting.
     
  12. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    Probably not. No ambient occlusion, worse performance on the shadows, no light bounces, etc. Generally, you want to use baked whenever possible.
     
  13. lahicksfamilia

    lahicksfamilia

    Joined:
    May 13, 2013
    Posts:
    77
    Ok. sorry if im asking the same question again, got it. Now what about the controlled character? How would i light the player? And could you give me a good example of when to definitely use dynamic lighting?
     
  14. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    1. Bake the light.
    2. Leave the light's realtime functionality on.
    3. ??????
     
  15. lahicksfamilia

    lahicksfamilia

    Joined:
    May 13, 2013
    Posts:
    77
    oh..so even if i bake, the baked lighting will still affect objects moving in the scene? Shadows etc?
    and my third question was basically asking if i should use baked or dynamic for something like candles and torches and things that will be interacted with
     
  16. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
  17. lahicksfamilia

    lahicksfamilia

    Joined:
    May 13, 2013
    Posts:
    77
    Thanks. You guys are all a big help. Thanks for the responses
     
  18. the_motionblur

    the_motionblur

    Joined:
    Mar 4, 2008
    Posts:
    1,774
    Rule of thumb: if your lighting has to change (day/nighttime or shooting out individual lights - things like that) you need dynamic lighting. If your lighting situation does not change or you want more performance for a pretty realistic lighting situation with Ambient Occlusion, Light Textures and indirect lighting/bounces then you should rather go for baked lighting. You can mix the two together but only in Unity Pro does it make sense, really because then you can blend between indirect lighting in the lightmaps and shadows from the realtime lights in the near clip range of the camera while the far clip range shows static baked shadows.

    The documentation explains this very understandable and in detail. Just play around with the settings and modes a little and you'll see how things work. Also do not forget to check 'create lightmapping UVs' for your imported assets. ;)
     
    Wolfdog likes this.
  19. lahicksfamilia

    lahicksfamilia

    Joined:
    May 13, 2013
    Posts:
    77
    thanks for the feedback. I believe i have a much clearer understanding of Unity's lighting system
     
  20. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    946
    I have just made some tests in WebGL.
    I have just a simple walkthrough template, which is meant as a starting scene with a number of scenenes loaded from assetbundles.
    I am usually using baked lighting for these scenes, but this time I tried to make a precomputed realtime and baked lighting versions of one of the scenes in order to compare them.
    The template outputs a screnhot gallery and webgl player.

    This is the baked lighting output:
    http://virtualplayground.d2.pl/WebGL/st15/galleries/gallery_D36_nk/

    This is the precomputed realtime lighting output:
    http://virtualplayground.d2.pl/WebGL/st15/galleries/gallery_D36_nkRealtime/

    As one could expect, the quality of baked lighting version is much better than realtime. On my PC I am getting around 50 fps for lighting version and only 3 fps for realtime.
    On the other side the realtime assetbundle size equals to a third of the baked bundle size and is a bit above 2 megs.

    I think baked lighting option is the best choice for static walkthrough scenes like that.
    Most of Unity tech demos use prebaked realtime, but I guess that is because they are dynamic.
     
    Last edited: Dec 7, 2016
  21. Fabian-Haquin

    Fabian-Haquin

    Joined:
    Dec 3, 2012
    Posts:
    231
    It's quite possible to have a nice rendering with dynamic lighting combined with precomputed realtime GI with decent perf on desktop.

    I dit it for a VR project in a city with a lot of stuff going on with a day/night cycle and shadows.

    The key is to optimize your assets as much as possible:
    - Enable Precomputed realtime GI
    - GPU Instancing for dynamic MeshRenderers
    - Static batching for statics MeshRenderers
    - For skinmeshes I didn't used anything, but there is some tools in the asset store to use GPU instancing on SkinMeshes
    - Use Atlas for everything to reduce drawcalls & materials amount
    - Use MaterialPropertyBlock & custom shader properties to add variant to avoid using multiple materials
    - Avoid the usage of point light, always prefer spot lights
    - Create a pool system to always have x nearest lights enabled with a nice fade-in, fade-out
    - Reflection probe is a drawcall killer so avoid overlap/using it, or it need to be very selective.
    - Use Occlusion culling if it apply to your project and carefuly choose what is Occluder and what is Occludee
    - If you can use a compute shader for something instead of using your CPU, do it
     
    Last edited: Dec 7, 2016
  22. RockoDyne

    RockoDyne

    Joined:
    Apr 10, 2014
    Posts:
    2,234
    We've got a necromancer on the loose. This thread was finished before Unity 5.0 even came out.
     
    the_motionblur and Kiwasi like this.
  23. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    946
    So this would be the other way than it is said here:
    "Spot lights are more expensive than point lights which are more expensive than directional lights."
    in this article here: http://wiki.unity3d.com/index.php?title=General_Performance_Tips
     
  24. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,312
    A global directional light has much more complicated shadowcasting routine (shadows are screenspace) compared to spot and point. Spot light shadow pretty much requires one texture to be rendered, point light requires six (cubemap faces), and directional somewhere around 3 or 4.

    So, not a very sound advice there.
     
  25. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    946
  26. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    This. So much of this thread is irrealavant now.