【问题标题】:GLSL Tessellation shader number of triangles/faces?GLSL Tessellation 着色器的三角形/面数?
【发布时间】:2013-02-16 22:13:59
【问题描述】:

我已经实现了一个三角形镶嵌着色器,如this 网站上的示例所示。

如何确定定义的interouter 镶嵌因子输出的面总数? - 它不会以任何方式影响我的程序,我只想知道我的多边形/面数。

【问题讨论】:

  • 我现在实际上有一个 C 实现。但是,我不会在作业被标记之前发布它。
  • 您介意分享您的解决方案吗?我真的可以使用它:)

标签: opengl glsl


【解决方案1】:

可以使用简单的递归找到单个三角形的重心细分(其中内部和外部细分相等)的三角形数量:

// 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】:

    这里是三角形、四边形和直线的顶点数或面数的完整答案,基于内层和外层!

    我需要一个类似的答案,即在给定细分和内部和外部细节级别(所有 LOD 可以不同)的情况下生成的顶点数量。我解决了这个问题,并没有进一步计算出面孔的数量。

    因此,对于三角形镶嵌,这里是两者的答案。我对 LOD 的语法是 IL 表示内部 LOD,OL0、OL1 和 OL2 表示三个边缘的外部 LOD。

      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
    

    我知道——那些看起来很疯狂的方程式。真正有帮助的一件事是意识到 any 单调递增序列的总和,例如 (7+9+11+13+15+17) 可以计算为 (num_elements/2*(first_element+last_element) )。这就是方块的最终来源。

    如果有人关心顶点的数量:

      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)
    

    这是顶点数和三角形面数的四边形的答案。

      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)
    

    等值线比较简单:

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

    哇,那是一些很长的方程式!

    希望对你有帮助!

    【讨论】:

      【解决方案3】:

      嗯,当我处理内部和外部镶嵌时,这有助于我了解如何计算它们。非常合理和直接的解释。 :)

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

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

      【讨论】:

      • 不幸的是,我仍然没有更聪明。在发布之前我确实阅读了这个网站。还是谢谢。
      • 如果你知道如何计算它们,你能解释一下吗?
      • 很难说,因为有 3 到 4 个外部细分级别,以及 1-2 个独立的内部细分级别,具体取决于它是四边形还是三角形。那么您对哪种情况感兴趣?
      • 很抱歉应该说它是一个三角形(如指南中所示)。其中内层 = a 外层 = b
      猜你喜欢
      • 2018-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-02
      • 1970-01-01
      • 1970-01-01
      • 2017-01-02
      • 2016-09-12
      相关资源
      最近更新 更多