Comments and answers for "How do I manually calculate Normals for my Meshes?"
http://answers.unity.com/questions/32100/how-do-i-manually-calculate-normals-for-my-meshes.html
The latest comments and answers for the question "How do I manually calculate Normals for my Meshes?"Answer by Fehr
http://answers.unity.com/answers/1685909/view.html
Thought this thread is now nearly ten years old, I recently had to solve this problem and wanted to share an amazing explanation and solution by [Sebastian Lague][1] on his YouTube channel as part of his procedural land mass generation tutorial:
https://www.youtube.com/watch?v=NpeYTcS7n-M&list=PLFt_AvWsXl0eBW2EiBtl_sxmDtSgZBxB3&index=12
Hopefully this helps someone in the future who needs to solve the same problem one day.
[1]: https://www.youtube.com/channel/UCmtyQOKKmrMVaKuRXz02jbQFri, 20 Dec 2019 10:52:29 GMTFehrComment by MountDoomTeam on MountDoomTeam's answer
http://answers.unity.com/comments/450645/view.html
in unity vertices have their own normals. in some code, each vertex of a triangle has the same normal for all 3 points of the triangle.Sun, 05 May 2013 19:19:05 GMTMountDoomTeamAnswer by MountDoomTeam
http://answers.unity.com/answers/397148/view.html
edit
Best way i found using procedural terrains, just get 2 points near the vertex using the same info you had to get the vertex height, it ll give you 3 points to cross product normal height and smooth shadows also. if you use 4 points around the vertex it may give you better results on peaks normals. works with hi res terrain height data. seamless. better quality normals.
there are various ways to calculate normals on the edges of the tiles. The question is, which one is easier, and which one is faster.
You can use the height map/procedural data to sample the points around the edge vertices and construct a normal from that. slow method.
You can use a separate mesh that is not visible and that is larger so that the visible tiles, and then you apply all the vertex/normal calculations to the hidden tile, and then copy the normals and the vertices from the hidden tile to the visible ones. I expect this is the slowest method.
The fastest by far method, I'm not sure how accurate it is I haven't tried it it should be hundred percent accurate, is that you go through the vertices of edges, and you will find that for a 10 x 10 plane, vertex 1 is on the same point as vertex 91 for the plane next to it, because vertices 0 to 10 is the south edge, and 90 to 100 is the North edge, and all the East ones all finish with 0, and the West ones all finish with 9. So when you have to vertices on the same points you can add the normal of both and divide by 2 to average it and get the actual normal of that point which I think should be correct. it should be true for the edges and corners.
What you can also do is rotate each tile by 90 so that all the edge vertices correspond one-to-one with each other in the array indices, and generate the height map data using transform point.
...
also go through edge vertices' normals for adjoining mesh and average normals that share same vertex position.Mon, 11 Feb 2013 05:36:00 GMTMountDoomTeamComment by MountDoomTeam
http://answers.unity.com/comments/397004/view.html
I am working on this at the moment, if anyone has a solution to the edges please squawk about them now.
also, if you have procedural mesh, you can use the procedural function to calculate the normals uniformly rather than using the actual mesh. I don't know how to do that exactly also!Sun, 10 Feb 2013 23:20:43 GMTMountDoomTeamComment by Jessy on Jessy's answer
http://answers.unity.com/comments/86036/view.html
No. The normal of the triangle itself isn't used for anything, except mesh colliders, which you're not talking about. There's no reason that the normal of a vertex has to have anything to do with the triangles that surround it; it just makes sense for realistic lighting, which is their intended purpose.Sat, 30 Oct 2010 20:21:38 GMTJessyComment by Jeremy 6 on Jeremy 6's answer
http://answers.unity.com/comments/86033/view.html
Strictly speaking triangles have normals because a point in space cannot have a face (unlike a plane). However, in this context, the normals of vertices is the average of the triangle normals that share the vertex.
Thanks for the info though. Now I just have to figure out how to do the normal calculation myself.Sat, 30 Oct 2010 19:48:45 GMTJeremy 6Answer by Jessy
http://answers.unity.com/answers/32122/view.html
<p>Triangles don't have normals. Vertices do.</p>
<p><a href="http://unity3d.com/support/documentation/ScriptReference/Mesh-normals.html" rel="nofollow">http://unity3d.com/support/documentation/ScriptReference/Mesh-normals.html</a></p>Fri, 29 Oct 2010 22:20:41 GMTJessyComment by Jeremy 6 on Jeremy 6's answer
http://answers.unity.com/comments/85967/view.html
"Imported meshes sometimes don't share all vertices. For example a vertex at a uv seam will be split into two vertices. Thus the RecalculateNormals function will create normals that are not smooth at the uv seam."
This is the exact problem I'm running into. My terrain tiles are separate meshes so the vertices on the edges of the tiles don't share the same meshes. Hence "manually" updating normals.
I can retrieve the common vertices.. can I hand set the normals?Fri, 29 Oct 2010 21:00:57 GMTJeremy 6Answer by fherbst
http://answers.unity.com/answers/32101/view.html
<p>Something like <a href="http://unity3d.com/support/documentation/ScriptReference/Mesh.RecalculateNormals.html" rel="nofollow">that</a> should do it if you have a script-made mesh and want to recalculate the normals.</p>
<p>EDIT: Yes, you can <a href="http://unity3d.com/support/documentation/ScriptReference/Mesh-normals.html" rel="nofollow">edit the normals by hand</a>, too:</p>
<pre><code> function Update ()
{
var mesh : Mesh = GetComponent(MeshFilter).mesh;
var normals : Vector3[] = mesh.normals;
// do custom normal calculations
// (e.g. looking at the surrounding faces and their normals
// and interpolating them - thats the vertex normal)
for (var i = 0; i < normals.Length; i++)
normals[i] = myCustomRecalculatedNormal;
mesh.normals = normals;
}
</code></pre>
<p>I hope that helps - if you need help for the calculation itself, just comment; I will see what I can do (you could also <a href="http://www.devmaster.net/forums/showthread.php?t=414" rel="nofollow">take a look at this</a> first - does exactly what you want, I think).</p>Fri, 29 Oct 2010 19:25:34 GMTfherbst