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

Question I get weird seams when I bake the light

Discussion in 'General Graphics' started by Carr77, Oct 3, 2020.

  1. Carr77

    Carr77

    Joined:
    May 17, 2013
    Posts:
    7
    Hi! I've experimented plenty with this, but have not been able to solve it. I've built an environment using a modular approach. All walls etc are little "lego pieces" with non-overlapping UVs (all marked as static). When I bake I often, but not always, get seams. I've experimented plenty with the light settings, but I haven't been able to remove these. In certain areas Unity just burns in a seam into the light. What should I do? These seams look ugly. Most are subtle, but some, like the first one in the attached image, are super strong. Please help :(
    unity_bake_issue.png
     
  2. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,497
    It looks like an issue with normals to me.. drop this into an Editor folder somewhere and see that they're pointing in the right direction. You'll need to check the "Active" toggle.
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. [CustomEditor(typeof(MeshFilter), true, isFallback = true)]
    4. [CanEditMultipleObjects]
    5. public class NormalsInspector : Editor
    6. {
    7.   Color handleColor = Color.red;
    8.   float handleScale = 0.25f;
    9.   float handleThickness = 2;
    10.   public static bool active = false;
    11.   void OnSceneGUI()
    12.   {
    13.     if (!active) return;
    14.     if (target.GetType() == typeof(MeshFilter))
    15.     {
    16.       MeshFilter meshFilter = (MeshFilter)target;
    17.       Mesh mesh = meshFilter.sharedMesh;
    18.       if (mesh == null) return;
    19.  
    20.       Handles.color = handleColor;
    21.       Vector3[] normals = mesh.normals;
    22.       if (normals != null)
    23.       {
    24.         Vector3[] vertices = mesh.vertices;
    25.         for (int v = 0; v < normals.Length; v++)
    26.         {
    27.           Vector3 position = meshFilter.gameObject.transform.TransformPoint(vertices[v]);
    28.           Handles.DrawLine(position, position + (meshFilter.gameObject.transform.TransformDirection(normals[v].normalized) * HandleUtility.GetHandleSize(position) * handleScale), handleThickness);
    29.         }
    30.       }
    31.     }
    32.   }
    33.   public override void OnInspectorGUI()
    34.   {
    35.     base.OnInspectorGUI();
    36.     EditorGUILayout.BeginHorizontal();
    37.     active = GUILayout.Toggle(active, "View Normals");
    38.     handleColor = EditorGUILayout.ColorField(handleColor);
    39.     if (GUI.changed) SceneView.RepaintAll();
    40.     EditorGUILayout.EndHorizontal();
    41.   }
    42. }
    view_normals.jpg
     
  3. Carr77

    Carr77

    Joined:
    May 17, 2013
    Posts:
    7
    Hi! Thanks for your reply. I couldn't get your script to work (got errors), but I threw the assets into Maya and displayed the normals instead (attachment below). The .obj-files look clean and well to me, so as long as Unity doesn't interpret these in a weird manner all should be fine. The image features the generic floor and the generic wall I use.
    normals.png

    EDIT: Btw, I could mention that these seams are only seen when the light is baked. I think a normal problem might've been visible even without baked light (when all is realtime). But these problems only show up if I choose to go with the baked light.
     
    Last edited: Oct 3, 2020
  4. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,497
    Okay - no idea then, I don't know much about lightmaps / light probes / intricacies of baking and so on.. yet anyway. I can't even get a nice spotlight working without either washing things out with intensity or setting crazy range on it (trying to avoid that given limit on number of objects per light thing), so hopefully someone more capable has a clue what's going on here :D
     
  5. Carr77

    Carr77

    Joined:
    May 17, 2013
    Posts:
    7
    Haha, thanks for your help anyway! :)
     
    adamgolden likes this.