# Why do T-junctions in meshes result in cracks?

I have heard from many sources that having T-junctions in 3D meshes is a bad idea because it could result in cracks during rendering. Can someone explain why that happens, and what one can do to avoid them?

• – lhf
Sep 9, 2015 at 1:35

lhf's answer is good from the perspective of tessellation, but these can occur with simpler triangle mesh use cases.

Take this trivial example of three, screen-space triangles, ABC, ADE and DBE...

Although point E was, mathematically, intended to be exactly on the line segment AB, the pipeline won't be using fully precise values, such as rational numbers (e.g. https://gmplib.org/). Instead, it will likely be using floats, and so some approximation/error will be introduced. The result is probably going to be something like:

Note that all of the vertices may have inaccuracies. Although the example above shows a crack, the T-junction may instead result in overlap along the edge causing pixels to be drawn twice. This might not seem as bad, but it can cause problems with transparency or stencil operations.

You might then think that with floating-point the error introduced will be insignificant, but in a renderer, the screen-space vertex (X,Y) values are nearly always represented by fixed-point numbers and so the displacement from the ideal location will usually be much greater. Further, as the rendering hardware "interpolates" the line segment pixel-by-pixel with its own internal precision, there is even more chance it will diverge from the rounded location of E.

If the T-junction is "removed" by, say, also dividing triangle ABC into two, i.e. AEC and EBC, the problem will go away as the shifts introduced by the errors will all be consistent.

Now, you might ask why do renderers (especially HW) use fixed-point maths for the vertex XY coordinates? Why don't they use floating-point in order to reduce the problem? Although some did (e.g. Sega's Dreamcast) it can lead to another problem where the triangle set-up maths becomes catastrophically inaccurate, particularly for long-thin triangles, and they change size in unpleasant ways.

• When you say "vertex (X,Y) values are nearly always represented by fixed-point numbers", I'm guessing you mean the screen-space vertex coordinates in the rasterizer, right? Not the original model-space vertices. Sep 9, 2015 at 20:17
• @NathanReed Yes. Just the screen-space X&Y (and, perhaps on some GPUs the Z). I'll edit it to make that clearer. Sep 10, 2015 at 5:41

When modeling parametric surfaces with a mesh in the parameter domain, T-junctions will most probably appear as discontinuities in the surface. These will show up as gaps in the rendering. See below.

More generally, T-junctions in triangle meshes will probably result in discontinuities of interpolated attributes, such as color and normals.

• – lhf
Sep 9, 2015 at 1:48

Floating-point rounding error.

After you transform the T junction and the point in the T can get rounded away from the edge.

Then it can happen that a fragment that gets sampled for a pixel lies in the gap between the 2 surfaces.

This can be fixed by not having a T-junction in the first place.

The simple way to avoid this is to ensure that all your vertices are welded

You issue is that you have cuts along edges with a vertex, but you do not have a corresponding vertex on the adjacent edge to weld/connect it to, if you think of it like a button on a shirt, you've sown on a button to the edge, but haven't given it a hole so the fabric is open.

In the picture below, the red dots represent correctly welded vertices, the blue dots all need an additional vertex to be cut in to the adjacent edge.

Generally speaking it is good practice to keep your modelling in quad's & tri's, this helps to alleviate this issue as you should always have a corresponding vertex to weld too. It also helps to keep to quads if you plan to use any subdivision methods on the mesh.