Each vertex belongs to one or more faces (usually triangles, sometimes squares - I will use triangles in this answer).
A triangle that is not tied to other triangles cannot be βsmoothedβ. He is even. Only when a person has neighbors can you reason about smoothing them.
For a vertex where there are several faces, we calculate the normals for each of these faces. The cross product of two vectors returns the perpendicular (normal) vector we want.
A
Be careful to calculate these vectors sequentially on all faces, otherwise your normal one may be in the negative direction to what you need.
So, at the vertex where several faces meet, we summarize the normals of the faces, normalize the resulting vector and apply it to the vertex.
Sometimes you have a grid where some parts of it need to be smoothed and others not. An example of a simple illustration is a cylinder of triangles. The round surface of the cylinder will burn well, but if you look at triangles from the flat ends at the vertices around a sharp ridge, it will look strange. To avoid this, you can introduce a rule that ignores the normals from individuals who deviate too far from the normal of the person for whom you are counting.
EDIT there is a really good video showing the technique for calculating Gurad's shading , although he does not discuss the actual algorithm.
You may like the source from Three.js. In particular, the computeVertexNormals function. It does not support the maintenance of sharp edges. The effectiveness of your algorithm depends to a large extent on how you model your primitives.
source share