1
$\begingroup$

In my procedurally generated mesh in Unity, not all vertices are vertexes of all neighbouring triangles - essentially, it's a grid with cells of varying sizes. This is messing up the calculation of normals however, making the lightning not smooth. How should I account for this? This is a part of the mesh to illustrate what I mean, in shaded wireframe and shaded mode:

$\endgroup$
  • 1
    $\begingroup$ "it's a grid with cells of varying sizes" Then fix that. You only get guarantees of seamless rendering if the triangles have binary-identical shared vertex positions. The way you're building your meshes, it is very possible that you can get gaps in your rendering, small dots between the "neighboring" triangles that show the background. $\endgroup$ – Nicol Bolas Nov 2 '19 at 22:30
  • $\begingroup$ @NicolBolas the varying cell sizes are only at a certain distance from the camera, so I don't worry much about those gaps $\endgroup$ – Jonan Nov 2 '19 at 22:36
  • 1
    $\begingroup$ These gaps can occur at any distance. Even if know the edges are parallel because the interpolation from both edges have different start and end points we cannot guarantee the edges along the same scanline are exactly at the same pixel. $\endgroup$ – PaulHK Nov 4 '19 at 3:18
  • $\begingroup$ Just to add to @PaulHK 's comment: there is a description on the problems of T-Junctions in this thread computergraphics.stackexchange.com/a/1464/209 $\endgroup$ – Simon F Nov 5 '19 at 11:26
3
$\begingroup$

For the shading to match, the normals (and any other vertex attributes) of the small triangles' verts would have to match the linear interpolation along the large triangle edge that they adjoin to.

For example: all the vertices in the green box below would need to be set by interpolating between the two blue vertices, based on their position along that edge.

As Nicol alluded to however, you may not get perfectly watertight rendering—or a perfect match in the shading—when constructing a mesh with T-junctions like this.

wireframe marked with vertices]

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.