Search Unity

double faced wall black light problem

Discussion in 'General Graphics' started by Lelon, May 21, 2016.

  1. Lelon

    Lelon

    Joined:
    May 24, 2015
    Posts:
    79
    Hi,
    So I generated a wall manually that has double sides by duplicating triangles, and I get a very dark, almost black color on the model. When I change the material of the wall to non-lit or unlit, then I see the texture, once I apply a material that involves lighting, the model turns black.
    Here is how I duplicate the triangles:
    Code (csharp):
    1.  
    2. triangles.Add (point1);
    3.         triangles.Add (point2);
    4.         triangles.Add (point3);
    5.         colours.Add(color);
    6.  
    7.         if (twoFaces) {
    8.             triangles.Add (point1);
    9.             triangles.Add (point3);
    10.             triangles.Add (point2);
    11.             colours.Add(color);
    12.         }
    13.  
    Without double facing



    With double facing
     
  2. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    I think what you are saying is....
    Your code doesn't show exactly what "triangles" get used for, or what "pointx" are. In the explanation below, I assume that point1, point2, etc. are point indices of type int, and that "triangles" are a of type List<int> that eventually gets assigned to a Mesh using something like.
    mesh.triangles = triangles.ToArray(),
    or
    mesh.SetIndices( triangles.ToArray(), MeshTopology.Triangles);

    The problem
    The problem is probably the normals of the mesh. For a normal to work well for lighting, it should have length 1 and be pointing "out" of the surface. Since you are using the same points for both sides of the surface, the normals for those points cannot do that.
    If you calculated the normals using Mesh.RecalculateNormals(), the result is probably that the normals ended up having length 0 in an attempt to compromise between the triangles on the two sides.

    In order to solve this, you either need to make separate points for each side, or make a special shader, that can turn a single-sided mesh into a double-sided one.

    Colours?
    Another note: I am not really sure what you are doing with the "colours" array. Normally, in a Mesh, you should have as many colours as you have vertices, not one per triangle?
     
  3. Lelon

    Lelon

    Joined:
    May 24, 2015
    Posts:
    79
    @cblarsen thank you, that was the problem. I solved it by creating a new points for the back.