Search Unity

Question Gaps between quads

Discussion in 'General Graphics' started by SunnyMonster, Jun 17, 2021.

  1. SunnyMonster

    SunnyMonster

    Joined:
    Oct 25, 2020
    Posts:
    7
    I found an issue that I don't know how to fix. There are unwanted gaps appearing between two quads. The same thing happens when the quads are combined into a single mesh. And soon after I discovered that light can pass through those gaps. 2021-6-17 18.36.30.615.png
    I thought it was because of uv problems, so I disabled alpha clipping to see if the light can still pass through. And it did.
    I got rid of the gaps in a enclosed cube by extending those quads by 0.01 units, but it introduces z-fighting in other situations.

    How can I solve this problem? I'm on 2020.3.11f1
     
  2. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,639
    I think It's just because you have sharp edges in your geometry. Do you see the gaps in the geometry or just in the shadows cast? Looks like light bleeding through to me. You can create a separate, invisible quad to cast shadows in place of the cubes. Also, if this is baked light, you could probably adjust the settings.
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    This, plus normal biasing on the directional light. Normal biasing works by slightly shrinking objects based on their vertex normals to avoid shadow acne. It has the benefit of causing less peter panning artifacts (the shadow not connecting to the base on the object when it's on a surface) compared to "regular" shadow biasing. However it unfortunately also has the side effect of opening up seams in concave hard edges when rendering the shadow map, which is what you're seeing here.

    There are a few options:

    One is what @kdgalla suggested: Hand place Quad meshes set to Shadows Only in the renderer component settings. This works well enough if you have a static hand built world and the issue is rare. Not great if it's a really common issue or your world is dynamically being generated, which I'm assuming is the case here going by the minecraft-esque aesthetic.

    Another option, and the easiest, is to go to your light settings, set Normal Bias to 0.0, and adjust the Bias to be high enough to remove the shadow acne that inevitably showed up. But you might start to see smaller objects' shadows disappear entirely, or thin objects "float" as their shadows no long connect to where they sit on the ground.


    The "last" option, and the "best" in terms of quality, is to use meshes with smoothed normals. This is of course a problem if your aesthetic is cubes with big flat faces, but there are a couple of ways to accomplish this without sacrificing the look.

    1. Generate your meshes with smooth normals, and then use a shader that calculates the face normals in the fragment shader using derivatives.
    Pros: It works!
    Cons: You have to use custom shaders. It's a bit more expensive. Doesn't work on very old platforms. And unless you're very careful might not work perfectly causing surfaces to appear noisy.

    2. Use two different meshes, one with Shadows Only with smooth normals, one for visuals with hard normals and shadow casting disabled.
    Pros: No custom shaders! Works on every platform!
    Cons: Means you need two meshes for everything that has this problem.

    3. Use one mesh with two sets of normals. Smoothed normals stored in the vertex normal, and hard normal stored somewhere else (vertex color, vertex tangent, extra UV, etc.).
    Pros: Only one mesh again! Works on every platform!
    Cons: You need a custom shader again.

    4. Generate your meshes with degenerate triangles in the seams. Basically right now on all of the hard edges there are no triangles that connect the sides to each other. So when the faces move apart there's a seam. The idea is to add triangles that connect the edges and corners together. This sounds scary, but usually the main cost of a mesh is the vertex count, and you're not increasing that.
    Pros: No custom shaders, single mesh, works on all platforms!
    Cons: A little harder to generate the meshes.
     
  4. SunnyMonster

    SunnyMonster

    Joined:
    Oct 25, 2020
    Posts:
    7
    Thank you so much! The fourth option works well. My mesh generation system makes this solution very easy to implement.
     
  5. SunnyMonster

    SunnyMonster

    Joined:
    Oct 25, 2020
    Posts:
    7
    Thank you!