View Full Version : Triangle tessellation in GL_ARB_tessellation_shade

07-05-2010, 11:36 AM
I've been reading through http://www.opengl.org/registry/specs/ARB/tessellation_shader.txt today because I wanted to know how exactly triangles are tessellated when using a tessellation shader.

However, there's a part I found strange - maybe I don't understand if fully (math/vocabulary wise). In "Section 2.X.2.1, Triangle Tessellation" there is a part about how the vertices for inner triangles are created. Specifically:

Otherwise, for each corner of the outer
triangle, an inner triangle corner is produced at the intersection of two
lines extended perpendicular to the corner's two adjacent edges running
through the vertex of the subdivided outer edge nearest that corner.
If I understand this right, it works like illustrated in this picture (assuming an inner tessellation level of 4): http://stud4.tuwien.ac.at/~e0725517/images/tri_tess.png

However, if this was correct, it would be flawed, in that for obtuse triangles it would be possible that the inner vertices are placed outside the original triangle.

I've tested it on an NVidia card, where the tessellation clearly results in correct concentric triangles.

Thanks in advance.

07-06-2010, 12:46 AM
Ah, I've somehow overlooked the part where it says that this is for "equilateral triangles"... which is even more disturbing since then I cannot find a general description/algorithm in this text. Well I'll have the chance to test on different cards soon, so I'll see how much they differ... I hope that it's not too much :p

Hmm, thinking about it a bit more I think that the described algorithm should suffice anyway, as it should be possible to apply the same barycentric coordinates to any triangle then?

Rosario Leonardi
07-06-2010, 12:08 PM
I think there is a mistake in the description.. :-S
The right algorithm should be :
"the inner triangle corner is produced at the intersection of two lines extended parallel to the corner's two adjacent edges.."
Otherwise as you point obtuse triangles can cause problems.

Same mistake in the openGl 4.0 specification (page 104).
That's strange.

07-18-2010, 03:02 AM
Parallel would result in different vertices though. But (I think) I have found the solution anyway.
It really only needs to be done for one triangle, the one with vertices (1, 0, 0), (0, 1, 0), (0, 0, 1). Which is an equilateral triangle where the algorithm works correctly. The resulting vertices can be used as barycentric coordinates for any triangle.
So basically, for each tessellation-level parameters, the tessellation only needs to be done once, and the resulting data can be used for any other triangle.
Some shots of my software implementation in action:

(Maybe they've written it that way to confuse ATI :P seeing that the unigine engine seems to behave incorrectly at times, and/or crashes even... but only on ATI cards)