Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Why does a baked spotlight looks less rough around the edges than a directional light?

Discussion in 'Global Illumination' started by AndersMalmgren, May 10, 2019.

  1. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,406
    At the default resolution of 40 a spotlight looks alot better around the edges than a directional light.

    Spot
    upload_2019-5-10_23-42-49.png

    Directional light
    upload_2019-5-10_23-43-18.png

    Why is that?

    Thanks
     
  2. fguinier

    fguinier

    Unity Technologies

    Joined:
    Sep 14, 2015
    Posts:
    114
  3. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,406
    Yep both are baked lightmaps with mixed mode (Shadowmask in quality setting, not Shadowmask distance which uses real-time up close). I can take some upclose pictures when I get to the office to show you the difference, directional looks less than half of the resulution of a spot light projected on the same mesh with same settings
     
  4. fguinier

    fguinier

    Unity Technologies

    Joined:
    Sep 14, 2015
    Posts:
    114
  5. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,406
  6. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,406
    @fguinier All right, so here is spot zoomed in. Still very low res (40 isnt very high). But its acceptable in my case
    upload_2019-5-13_14-16-42.png

    Here is dir.light. Now we got alot of edgy squares building up the edge of the shadow
    upload_2019-5-13_14-17-54.png

    The effect is very visible in game.
    Untitled.jpg

    Untitled.jpg

    upload_2019-5-13_14-22-52.png
     
  7. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,406
    Interesting find, a directional light on its own, the usual rough edges
    upload_2019-5-13_18-36-9.png

    If overlapped with a spotlight it gets smoothed out
    upload_2019-5-13_18-37-2.png
     
  8. fguinier

    fguinier

    Unity Technologies

    Joined:
    Sep 14, 2015
    Posts:
    114
    Does the same problem happens with baked light (rather than mixed) ? Also does unselecting 'compress lightmap' in the lighting window help?
     
  9. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,406
    Mixed or baked doesnt matter. Havent tried compressed but cant imagine it will make a difference since it works for spotlights and pointlights. But can try when I get to the office, thanks.

    Btw, its really easy to reproduce the problem. Just import a cube and a plane into a empty scene mark them as static, set the directional light to mixed or baked and bake it. If you want to try for yourself. Present both in 2017.4.27 and 2019.1.2
     
  10. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,406
    Compression does not cause it. But it does add to the problem a bit, but its not the root of the problem. Here with compression off
    upload_2019-5-14_18-25-31.png
     
  11. fguinier

    fguinier

    Unity Technologies

    Joined:
    Sep 14, 2015
    Posts:
    114
    I did a quick test with the repro as suggested and spot and directional seems to react the same for me? I can see artefact from linear filtering of the lightmap with high intensity light and sharp shadows however that is true for both directional and spot. I think the problem boil down to adjusting the baked shadow angle then see https://docs.unity3d.com/Manual/class-Light.html
     
  12. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,406
    Hi, I use the default settings more or less in a empty scene. Precomputed real time disabled. Sadly the angle setting does not create satisfactory results. I use intensity of 1 and indirect intensity of 1.

    I can get a screenshot on my settings when I get home but they are more or less default.

    edit: I see you have the settings in screenshot above
     
  13. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,406
  14. fguinier

    fguinier

    Unity Technologies

    Joined:
    Sep 14, 2015
    Posts:
    114
    Thanks for the repro, so the problem here (repro is using mixed mode) is the format of the shadowmask. by default when `compress lightmap` is true shadowmask are using RGBA16bits aka uncompressed 4 bits per channel. This indeed does not cope with high intensity light and smooth soft shadows (thus it would fail for the spot as well provided the spot would have an equally high intensity). The reason we use that format is because shadowmask channels represent visibility from different light source, so compression algorithms could introduce light leaks.

    However this is a very generic approach! Knowing the data and target platform you can do a few things to improve the situation here:
    - Knowing the maximum amount of mixed overlapping lights you could select texture format with fewer channels. For example if only the directional light is using mixed lighting you know that you only need one channel and can use R16 to match memory footprint of the generic compressed version but for even higher quality.
    - Knowing the platform and data you can try compressed formats, for example on PC/Mac/Linux BC7 is a really good compression algorithm that leak very little among channels. I would recommend to try it on your game if targeting those platforms.

    You can change the texture format directly on the shadowmask asset in the project folder:
    upload_2019-5-16_10-53-56.png

    upload_2019-5-16_10-53-24.png

    In the case of baked lightmap i would also investigate texture format in regard to the target platform, finally in regard to 6GB of lightmaps have you considered crunched compression? https://docs.unity3d.com/Manual/class-TextureImporter.html
     
    AndersMalmgren likes this.
  15. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,406
    Allright, thanks will have a look.

    We only have overlap between directional and 1 more mixed mode light at various, places. We only target windows at the moment, but are looking into supporting PSVR and possible the Oculus Quest later. Will look at changing compression for the shadowmask thanks. We do not turn on/off the mixed mode lights, only use it to get shadows from dynamic objects and for specularity on static/dynamic objects. We cant ommit the shadowmask entirly? Or maybe its used to correctly cast shadows? I remembered before Shadowmask mode mixed mode lights didnt work properly.
     
  16. fguinier

    fguinier

    Unity Technologies

    Joined:
    Sep 14, 2015
    Posts:
    114
  17. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,406
    Yeah I know you redid the mixed mode in 5.6 it was completly broken before that. I will experiment with it when I get to the office, thanks
     
  18. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,406
    Not much changed sadly, here is default

    upload_2019-5-16_20-47-7.png

    BC7
    upload_2019-5-16_20-47-23.png
     
unityunity