Search Unity

Jagged shadow edges on Low Poly models using URP Baked Lighting

Discussion in 'Global Illumination' started by AlienBoyGames, Nov 11, 2020.

  1. AlienBoyGames

    AlienBoyGames

    Joined:
    Feb 12, 2020
    Posts:
    17
    I experienced a lot of problems in the past months using Unity's Lightmapping for my big open world scene.
    The models are low poly and UV unwrapped by hand(had to because there were problems with automatic UV no matter what the settings were).

    The main problem is that the edges where the shadow changes are very, very jagged/blocky. The only way to sort of mask it is by increasing the Lightmap Resolution, but this increases the texture size a lot and that's a problem since I am targeting mobile devices.

    This is a 2015 post with a similar problem https://forum.unity.com/threads/jagged-shadows-in-baked-lightmaps-unity-5.317150/

    Screenshot 2020-11-11 164217.png Screenshot 2020-11-11 164238.png





    Screenshot 2020-11-11 164453.png Screenshot 2020-11-11 164532.png


    You can check out 1 more example here https://imgur.com/a/DboLsX9.
    I couldn't post them here. There is a 5 images limit per post.




    This is another problem. I was left with the white smudges today after changing a lot of values trying to solve the problem. Tried reverting to the old settings but now they are here to stay I guess. Welp!!
    Screenshot 2020-11-11 164432.png



    I am using a directional lighting with: Intensity = 2.96, Indirect Multiplier = 2, Shadow Type = Soft,
    Baked Shadow Angle = 5

    My Unity version is 2020.1.12f1


    Please help. Thank's in advance.
     
  2. AlienBoyGames

    AlienBoyGames

    Joined:
    Feb 12, 2020
    Posts:
    17
    UPDATE: The white lines come from the AO. I still need to figure out how to fix this so I can have AO.
     
  3. kristijonas_unity

    kristijonas_unity

    Unity Technologies

    Joined:
    Feb 8, 2018
    Posts:
    1,080
    Try switching to Advanced filtering mode. Disable gaussian filtering and enable denoising instead. See if that makes the edges smoother.

    Alternatively, you could make a custom lightmap parameters asset with a higher AA value. But I doubt it's going to help much in this case.
     
  4. AlienBoyGames

    AlienBoyGames

    Joined:
    Feb 12, 2020
    Posts:
    17
    For the jagged edges the only thing that helped was scaling down the whole scene in half. Now I get a lot better shadows with the lightmap resolution even at 5. I wonder if there is some math I can do to figure out what is the perfect scale.

    But the AO white seams still persists. No info on internet and I don't know what to do.
     
  5. AlienBoyGames

    AlienBoyGames

    Joined:
    Feb 12, 2020
    Posts:
    17
    @kristijonas_unity Changing the lightmap padding both on model import and lighting settings doesn't help. Same result between 2 and 32 texels.
     
  6. rasmusn

    rasmusn

    Unity Technologies

    Joined:
    Nov 23, 2017
    Posts:
    103
    @AlienBoyGames Thanks for you post. I think that the jaggies that you are seeing are due to sub-optimal UV unwraps. My guess is that your object is authored in such a way that the two faces on either side of the jagged edge points to the same charts/island in the UV unwrap. This is a problem because that means pixels being shaded near that edge will potentially sample from both sides of the light/shadow part of the island/chart in the baked lightmap. Therefore shadow/light bleeds across the edge even though that is not what you want

    I'd say that the best way to solve this is to make sure that faces which ought to looked faceted have their own separate chart/island in the UV unwrap of the object. In the clip below I show how you can achieve this using Unity's built-in auto unwrapper:
    jaggies.gif

    By setting "Hard Angle" to a small value, you ask the unwrapper to treat most faces as having a sharp edge. This is typically what you want in low-poly style games. Of course, you don't have to use Unity's unwrapper to achieve this.

    Another solution to your problem is to not bake direct light into your lightmap. The reason the jaggies are so significant is because you have very bright direct light on one side of the edge and relatively weak indirect light on the other. If you only bake indirect light (and apply direct light with realtime techniques instead), then you would not have that problem. I show this solution in this clip:
    jaggies2.gif

    As you can see in the video, the problem becomes much less significant by not having direct light in the lightmap.
    Note that this is not a perfect solution since there is still some "texel bleeding" across the edge. It is just less visible because it is "only" indirect light. Therefore, I'd recommend the first solution that I mentioned above over this second solution.

    Regarding the "white smudges" that you see I am less certain of what is going on. I suspect this is due to texel bleeding across separate lightmap charts. Are you getting "There are X objects in the Scene with overlapping UV's." warnings in the console? If so you can solve this by increasing the resolution _or_ increasing the spacing between your charts as explained here. Generally, I recommend you use Unity's unwrapper's new feature Auto Pack Margin.
     
    Last edited: Nov 17, 2020
    Nastomeya and CosmoM like this.
  7. AlienBoyGames

    AlienBoyGames

    Joined:
    Feb 12, 2020
    Posts:
    17


    Ok this makes a lot of sense. So the jagged edges happens because texel for blending was put right on the seam which is ok for normal models with smooth geometry.


    This is my current progression.

    I ditched the unity generate lightmap uv's because the uv faces were still connected. So I went to blender and marked all edges as seams and did a uv unwrap. That left me with some ugly bleeding between all the faces but no more jagged edges. Then tried Lightmap Pack, same thing happened. Increased the margin. Same thing.
    Deactivated the denoiser and everything got fixed. No more jagged edges and even the AO worked perfectly but I was left with some horrible noise.

    This is where I am stuck right now. I don't have any uv overlap and a few texels between each uv chart. Screenshot 2020-11-17 182601.png Screenshot 2020-11-17 182813.png Screenshot 2020-11-17 182759.png
     
  8. rasmusn

    rasmusn

    Unity Technologies

    Joined:
    Nov 23, 2017
    Posts:
    103
    AlienBoyGames: I am slightly confused. You say that when disabling the denoiser "everything got fixed", except now you have horrible noise. However, in the images you posted I don't see any noise. Instead, I see suspicious "bands" near geometry edges. Therefore it is not clear to me what your current problem actually is (is it noise or it edge artifacts?). Can you elaborate?
     
  9. AlienBoyGames

    AlienBoyGames

    Joined:
    Feb 12, 2020
    Posts:
    17
    :)) Sorry, sometimes I get really tired. Last night I had an revelation and decided to switch the art style from low poly to stylized so these problems might not happen again.

    But I will explain in case anyone has these problem or I will face it again.
    I didn't post any photos with the noise. The 3 pictures are from the same bake in which I used the denoiser. The second pic shows the highest bleeding and the first in the first one you can see a zoomed in picture of it's uv's.

    In the third photo you can see what usually happens, on most 3D models, slight bleeding but noticeable.

    I baked the whole scene with the denoiser off and you can see the pictures from the same angles as before so you can compare.

    It's hard for me to tell if there is still some bleeding happen because of the huge amount of noise. I doesn't look like it on direct lighting.

    Thank you.
    Screenshot 2020-11-18 114454.png Screenshot 2020-11-18 114404.png Screenshot 2020-11-18 114424.png
     
  10. rasmusn

    rasmusn

    Unity Technologies

    Joined:
    Nov 23, 2017
    Posts:
    103
    Thanks for the clarification. It sounds weird that denoising is causing the bleeding issues given how far your charts are from each other.

    Can you share a screenshot of your filtering/denoising settings? Perhaps you are using a very large blur radius for filtering?

    Another thing you could try is to set filtering to "Advanced" and then disable everything (set all denoising/filtering settings to None). Then you can reenable the denoising/filtering settings one at a time and bake in between to inspect the results. That should give you a clue about what may be causing this.

    You may also consider to only enable filtering and disable denoising. This works well for some projects.

    PS: Perhaps you already know this, but currently there's way too much space between the charts. You are wasting precious lightmap texel :).
     
  11. pradotech

    pradotech

    Joined:
    Oct 17, 2019
    Posts:
    35
    I know this is an old topic, but I was struggling with this the last days. I messed around with a lot of settings, until I got to filtering. I was using Optix for Denoiser, and after changing to "None" the issue was solved, but AO got very noisy. So I found a middle ground using OpenImageDenoise and setting Gaussian to something around 2 texels for each one. I hope this helps someone out there.
     
    kalinixk3 likes this.