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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Mesh triangles have weird lighting

Discussion in 'General Graphics' started by Dustin27, Jul 27, 2020.

  1. Dustin27

    Dustin27

    Joined:
    Nov 12, 2018
    Posts:
    15
    I need to create three dimensional objects from two dimensional pointlists (so the input for my example here is a triangle pointlist) and want to use meshes. I was able to create the mesh but there is one problem:
    The triangles on the sides have weird lighting behaviour (e.g. at the top): The areas should look the same especially as it is partly the same triangle. But as you can see the top side has two different bright zones. Rotating the objects changes the lighting behaviour btw.

    upload_2020-7-27_18-40-21.png

    What did not work:
    - Changing shader or any property of the material
    - Trying other UV coordinates (although I think the given are correct)
    - Disabling directional lighting (the transitions get softer..)
    - Calling mesh.RecalculateNormals(), mesh.RecalculateTangents() and mesh.RecalculateBounds() are not doing the work

    Maybe this could be interesting:
    mesh.vertices
    upload_2020-7-27_18-22-36.png
    mesh.triangles
    upload_2020-7-27_18-24-11.png
    mesh.uv
    upload_2020-7-27_18-24-44.png

    I'm grateful for any help!
     
  2. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,505
    You could try mesh.RecalculateNormals(), mesh.RecalculateTangents()
     
  3. Dustin27

    Dustin27

    Joined:
    Nov 12, 2018
    Posts:
    15
    I found an article explaining exactly my problem (https://polycount.com/discussion/154664/a-short-explanation-about-custom-vertex-normals-tutorial). The normales for the vertices created by mesh.RecalculateNormals() are not correct because they represent an average of all sides. So to have correct lighting, I need to split each vertex into 3 vertices with each another normal so that each area has its own correct normals.

    Edit: I solved this by creating an own mesh for each side, doing mesh.RecalculateNormals() for each and then combining the meshes with CombineInstance.
     
    Last edited: Jul 28, 2020