openglglsl

GLSL Tessellation shader number of triangles/faces?


I have implemented a triangle tessellation shader as shown in the example on this website.

How can I determine the total number of faces that would be output for defined inter and outer tessellation factors? - It doesn't effect my program in any way I would just like to know my poly/face count.


Solution

  • The number of triangles for the barycentric subdivision of a single triangle (where the inner and outer subdivision is equal) can be found using a simple recursion:

    // Calculate number of triangles produced by barycentric subdivision (i.e. tessellation)
    // Where n is the level of detail lod and outer and inner level is always equal
    int calculateTriangles(int n) {
    
        if(n < 0)   return 1;                               // Stopping condition
        if(n == 0)  return 0;
        return ((2*n -2) *3) + calculateTriangles(n-2);     // Recurse
    }