Search Unity

Resolved Bake Lightmaps for multiple meshes that are inside of each other

Discussion in 'Global Illumination' started by Fuzzel_, Jun 30, 2021.

  1. Fuzzel_

    Fuzzel_

    Joined:
    Nov 6, 2018
    Posts:
    11
    UPDATE: Issue is actually the baked AO and not the behaviour of the lightmapper per se, as it behaves correctly once the Backface Tolerance is set up properly. See: https://forum.unity.com/threads/dis...-meshes-with-progressive-lightmapper.1134598/

    In our game we have walls that are fading in and out depending on the player stepping into the room.
    For this we have two kinds of walls:
    • A "full" wall
    • A knee-height wall
    These two meshes are placed somewhat ontop of each other.

    Obviously we need to bake lightmaps for both in our levels, but as they are overlapping each other, when we bake our lights in our levels some parts of the knee-height walls are left in the dark/get artifacts.

    I know this is is probably some weird edge case because why would you want to bake light for something that is presumably static but is hidden behind another presumably static mesh? But because we are fading on mesh during the game the previously hidden mesh might actually be visible.

    So my question is what is the best way to bake the lightmaps of both walls when some parts of a mesh might be obstructed during build time? Is there some way to have two different passes of lightmap baking (e.g. based on physics layers) so the two walls don't interfere with each other?

    As an additional info:
    We are using the URP 10.4 on Unity 2020.3 and because we do not want real shadows in our game we have disabled Cast Shadows on our Mesh Renderers, Render Shadows on our Camera and Cast Shadows on our URP Pipeline Asset.
     
    Last edited: Jul 1, 2021
  2. kristijonas_unity

    kristijonas_unity

    Unity Technologies

    Joined:
    Feb 8, 2018
    Posts:
    1,080
    You could try one of the following:
    • Create a new Lightmap Parameters Asset, and assign it to the affected mesh (the one with the hard shadow). Set the Backface Tolerance value to 0.0 and see if that helps.
    • Alternatively, you could place those meshes into separate scenes, and bake them individually. You can later additively load said scenes in runtime.
    • If all else fails, you could try modifying lightmap .exr file in Photoshop (or similar).
     
  3. Fuzzel_

    Fuzzel_

    Joined:
    Nov 6, 2018
    Posts:
    11
    If I bake them separately in another scene they will not get affected by the GI of the surrounding area (floor, ect). I would have to have a copy of all levels. But even if I would do that, how can I delete everything afterwards except the lightmaps for my walls? Otherwise I have two sets of lightmaps that encompass the whole level.
     
  4. Fuzzel_

    Fuzzel_

    Joined:
    Nov 6, 2018
    Posts:
    11
    I tried this but it had no effect. I don't think that the issue here has the light source does not hit the backface of any mesh. The Texel Validity is also all green.

    I disabled any shadow casting and when two meshes are cleanly separated the backing actually works as the light completely goes through one mesh and hits a second mesh behind it so it's baked into both. But because the meshes (or rather their bounds) overlap, Unity somehow concludes that one mesh is (partially) inside the other so it doesn't have to be baked in certain areas regardless of any "Cast Shadow" settings.


    What exactly do you mean by that? What would I change there?
     
  5. Fuzzel_

    Fuzzel_

    Joined:
    Nov 6, 2018
    Posts:
    11
    I did some more testing and found the option "Pushoff" which if I set it to a larger value such as 0.01 made it so at least the front faces of the lower walls get their GI baked correctly, but because the "full height" wall is a lot taller than the "lower walls" I still get a dark top face.

    There was also the option "Is Transparent" which sounds exactly like the thing I want because it let's lets the rays travel through the mesh but it's part of the "Realtime GI (Deprecated)" settings which have no affect on the baking.

    From what I understood it, it's for the deprecated Enlighten, and when using Enlighten instead of Progressive CPU/GPU, it actually works! But I am unsure if we can use Enlighten. I'm only testing it with a test scene which has only 6 meshes. I fear it will take to long to bake a complete level with this. Currently the only way we can get any acceptable speed is using the Progressive GPU.
     
  6. Fuzzel_

    Fuzzel_

    Joined:
    Nov 6, 2018
    Posts:
    11
    We tried building the light with Enlighten but a lot of inconsistent results with our scene setup, so another solution would still be much appreciated.