GLSL Tessellation shader number of triangles/faces?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-30 14:46:13

问题


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.


回答1:


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
}



回答2:


Here is the complete answer for number of vertices or number of faces for triangles, quads and lines, based on inner level and outer level!

I needed a similar answer, the number of vertices generated given a tessellation and inner and outer levels of detail (where all LODs can be different). I solved this, and it wasn't that much further to figure out the number of faces.

So here are the answers to both, for triangle tessellations. My syntax for the LOD are IL for the inner LOD and OL0, OL1 and OL2 for the outer LOD for the three edges.

  Inner faces/triangles (based only on IL):
      if IL==1 -> inner faces = 0
      if IL odd -> inner faces = 3/2*(IL-1)(IL-3)+1
      if IL even -> inner faces = 6*(IL/2-1)^2
  Outer faces/triangles
      if IL==1 -> outer faces = (OL0+OL1+OL2 == 3) ? 1 : OL0+OL1+OL2
      else -> outer faces = 3*IL+OL0+Ol1+OL2-6
  Total = Inner + Outer faces

I know - those are pretty crazy looking equations. One thing that really helped was realizing that the sum of any monotonically increasing series such as (7+9+11+13+15+17) can be calculated as (num_elements/2*(first_element+last_element). That's where the squares end up coming from.

And if anyone cares about the number of vertices:

  Inner vertices:
      if IL==1 -> inner vertices = (OL0+OL1+OL2 == 3) ? 0 : 1
      if IL odd -> inner vertices = (IL-1)^2 * 3/4
      if IL even -> inner vertices = 3((IL/2)^2-IL/2) +1
  Outer vertices = OL0+OL1+OL2
  Total = Inner + Outer vertices (OL0+OL1+OL2)

Here's the answer for quads for number of vertices and triangle faces.

  Quad Vertices   (LOD levels are IL0, IL1, OL0, OL1, OL2, OL3)
      Inner vertices:
          if IL0==IL1==1 but OL0+OL1+OL2+OL3>4 -> inner vertices = 1
          else -> inner vertices = (IL0-1)*(IL1-1)
      Outer vertices = OL0+OL1+OL2+OL3
      Total = Inner + Outer vertices

  Quad Faces (triangles)
      Outer ring faces =
        if IL0==IL1==OL0=OL1=OL2=OL3==1 -> 1 face total
        if IL0==IL1==1 but OL0+OL1+OL2+OL3>4 -> calc as if IL0=IL1=2
        else OL0+OL1+OL2+OL3+2*IL0+2*IL1-8
      Inner faces:
        if IL0<3 and IL1<3 -> 0
        else 2*(IL0-2)*(IL1-2)
      Total = Inner + Outer
          i.e.: when IL0/IL1>2 -> OL0+OL1+OL2+OL3+2*IL0+2*IL1-8 + 2*(IL0-2)*(IL1-2)

Comparatively isolines are really simple:

  Isoline (LOD levels are OL0, OL1 - OL0 is missing top edge)
      num vertices = OL0*(OL1+1)
      num segments = OL0*OL1

Whew, that's some long equations!

Hope that's helpful!




回答3:


Well, when I was dealing with inner and outer tesselation, this helped me to understand how to count them. Very reasonable and straightforward explanation. :)

http://prideout.net/blog/?p=48

http://prideout.net/blog/?p=49



来源:https://stackoverflow.com/questions/14915705/glsl-tessellation-shader-number-of-triangles-faces

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!