Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Material looks different on Mesh generated at runtime vs editor created mesh

Discussion in 'General Graphics' started by lmakor, Mar 30, 2022.

  1. lmakor

    lmakor

    Joined:
    Oct 31, 2016
    Posts:
    23
    So, I am trying to procedurally create my game world.
    For the beginning I started simple and just wanted to generate and texture a simple quad.
    To see whether I am doing the generation correctly, I also placed a quad using the Unity editor.
    I applied the same material to both (again, for the editor-created one in the editor and for the generated one via script).
    However, contrary to my expectation the two quads did not match completely.
    They are quite similar but, the colors are slightly off.
    Furthermore, it seems like the light/reflections would come from the wrong direction for the script/runtime created one.
    Note, all the vertex, triangle and uv data matches, they also use the same material, hence the same settings and shader are applied to both of them.

    So, I am wondering whether someone knows what the reason für this difference could be.
    Could it have something to do with pre-generated lightmaps?

    Here is a screenshot that illustrates the problem - the left quad is the script generated one:
    RuntimeMeshVsEditorMesh.PNG

    Here is a screenshot with a second editor placed quad (instead of the left, script-generated one) - to also illustrate that the material/texture actually is tileable:
    TwoAdjacentEditorMeshes.PNG
     

    Attached Files:

  2. lmakor

    lmakor

    Joined:
    Oct 31, 2016
    Posts:
    23
    Does really nobody have any idea what the problem is?
     
  3. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,616
    No idea. Maybe check the normals too. Also, did you call RcalculateTangents after generating the mesh? Also, did you check that all of the settings in the mesh renderer are the same too? Shadows, light probes. etc.?

    I think it could. If you're generating a mesh at runtime then it's real-time lit so it could look different than anything lightmapped.
     
    Last edited: Apr 4, 2022
  4. lmakor

    lmakor

    Joined:
    Oct 31, 2016
    Posts:
    23
    So, I spent a few hours yesterday to continue debugging and it turned out that the problem was that I didn't call RecalculateTangents on the generated Mesh.

    So, thanks kdgalla, you were on the right track and if I hadn't debugged another 3 hours yesterday, you would have solved the problem for me!