Difference between revisions of "Tessellation"

From OpenGL.org
Jump to: navigation, search
(Expand section.)
(Quick bit of cleanup.)
Line 10: Line 10:
  
 
Since OpenGL 4.0 the specification defines tessellation to be "a process that reads a patch primitive and generates new primitives used by subsequent pipeline stages. The generated primitives are formed by subdividing a single triangle or quad primitive[..]".  
 
Since OpenGL 4.0 the specification defines tessellation to be "a process that reads a patch primitive and generates new primitives used by subsequent pipeline stages. The generated primitives are formed by subdividing a single triangle or quad primitive[..]".  
 
== Tessellation Stages ==
 
  
 
The tessellation process is divided into three stages which form an optional part of the [[Rendering Pipeline Overview|rendering pipeline]], two of which are programmable and one which is fixed as follows (in order).
 
The tessellation process is divided into three stages which form an optional part of the [[Rendering Pipeline Overview|rendering pipeline]], two of which are programmable and one which is fixed as follows (in order).
  
=== Tessellation Control ===
+
== Tessellation control shader ==
  
 
This programmable stage executes an optional ''tessellation control shader''. If no control shader is active in the current program or program pipeline, default values are used by the subsequent stage. Values most important for the tessellation process are the so called ''inner'' and ''outer'' ''tessellation levels''. There exist two built-in 'output' arrays in the tessellation control language, {{code|gl_TessLevelInner[2]}} and {{code|gl_TessLevelOuter[4]}}, which in part control how the subsequent stage generates new primitives.
 
This programmable stage executes an optional ''tessellation control shader''. If no control shader is active in the current program or program pipeline, default values are used by the subsequent stage. Values most important for the tessellation process are the so called ''inner'' and ''outer'' ''tessellation levels''. There exist two built-in 'output' arrays in the tessellation control language, {{code|gl_TessLevelInner[2]}} and {{code|gl_TessLevelOuter[4]}}, which in part control how the subsequent stage generates new primitives.
  
=== Tessellation Primitive Generation ===
+
== Tessellation primitive generation ==
  
 
Primitive generation is a fixed-function stage responsible for creating a set of new primitives from the input patch. This stage is only executed if a ''tessellation evaluation shader'' is active in the current program or program pipeline. Primitive generation is affected by two factors:
 
Primitive generation is a fixed-function stage responsible for creating a set of new primitives from the input patch. This stage is only executed if a ''tessellation evaluation shader'' is active in the current program or program pipeline. Primitive generation is affected by two factors:
Line 28: Line 26:
 
Depending on the primitive type, the primitive generator evaluates a different number of tessellation levels and applies different tesselation algorithms. Each generated vertex is assigned a normalized position (i.e. in [0, 1]) denoted <math>(u, v, w)</math> or <math>(u, v)</math>. The coordinates are accessible using the built-in {{code|in vec3 gl_TessCoord}} during tesselation evalutation where {{code|gl_TessCoord.xyz}} is equivalent to the triple <math>(u,v,w)</math>.
 
Depending on the primitive type, the primitive generator evaluates a different number of tessellation levels and applies different tesselation algorithms. Each generated vertex is assigned a normalized position (i.e. in [0, 1]) denoted <math>(u, v, w)</math> or <math>(u, v)</math>. The coordinates are accessible using the built-in {{code|in vec3 gl_TessCoord}} during tesselation evalutation where {{code|gl_TessCoord.xyz}} is equivalent to the triple <math>(u,v,w)</math>.
  
==== Triangles ====
+
=== Triangles ===
 
The first inner tessellation level and the first three outer tessellation levels are used. The algorithm is required to produce smaller triangles. The resulting vertex positions are ''barycentric coordinates'', which specify weights of the vertices of the input triangle for which the condition <math>u + v + w = 1</math> holds.
 
The first inner tessellation level and the first three outer tessellation levels are used. The algorithm is required to produce smaller triangles. The resulting vertex positions are ''barycentric coordinates'', which specify weights of the vertices of the input triangle for which the condition <math>u + v + w = 1</math> holds.
  
==== Quads ====
+
=== Quads ===
  
 
For quads all six tessellation levels are used to subdivide the input rectangle into smaller triangles.  
 
For quads all six tessellation levels are used to subdivide the input rectangle into smaller triangles.  
  
==== Isolines ====
+
=== Isolines ===
They are only affected by the first two outer tessellation levels. The generator will create <math>n</math> independent  
+
They are only affected by the first two outer tessellation levels. The generator will create <math>n</math> independent lines, which will be subdivided into <math>m</math> segments with <math>m + 1</math> vertices, where:
lines, which will be subdivided into <math>m</math> segments with <math>m + 1</math> vertices, where
+
 
 
: <math>m\,= OuterTessLevel[0]</math>
 
: <math>m\,= OuterTessLevel[0]</math>
 
: <math>n\,\,= OuterTessLevel[1]</math>
 
: <math>n\,\,= OuterTessLevel[1]</math>
The coordinates of the vertices are determined by subdividing the line along the <math>u</math>-axis and determining a constant value along the <math>v</math>-axis for every vertex on the current line using the formula
+
 
 +
The coordinates of the vertices are determined by subdividing the line along the <math>u</math>-axis and determining a constant value along the <math>v</math>-axis for every vertex on the current line using the formula:
 +
 
 
:<math>0{,}\frac{1}{n}{,}\frac{2}{n}{,} .. {,}\frac{n-1}{n}</math>
 
:<math>0{,}\frac{1}{n}{,}\frac{2}{n}{,} .. {,}\frac{n-1}{n}</math>
 +
 
As can be seen, the the generator will not create a line at <math>v = 1</math>. During isoline tessellation, the <math>w</math>-coordinate is ignored.
 
As can be seen, the the generator will not create a line at <math>v = 1</math>. During isoline tessellation, the <math>w</math>-coordinate is ignored.
  
=== Tessellation Evaluation ===
+
== Tessellation evaluation shader ==
  
 
== Patches ==
 
== Patches ==
Tessellation stages operate on patches, a new primitive type denoted by the constant {{enum|GL_PATCHES}}, which are simply arrays of vertices and user defined per-vertex attributes written by a vertex shader. The number of vertices per patch can be defined on the application-level using  
+
Tessellation stages operate on patches, a new [[Primitive|primitive type]] denoted by the constant {{enum|GL_PATCHES}}, which are simply arrays of vertices and user defined per-vertex attributes written by a vertex shader. The number of vertices per patch can be defined on the application-level using
  void {{apifunc|glPatchParameter}}i(GLenum pname​, GLint value​);
+
 
  void {{apifunc|glPatchParameter}}fv(GLenum pname​, const GLfloat *values​);
+
  void {{apifunc|glPatchParameter|i}}(GLenum {{param|pname​}}, GLint {{param|value​}});
 +
  void {{apifunc|glPatchParameter|fv}}(GLenum {{param|pname​}}, const GLfloat *{{param|values}}​);
  
 
with {{enum|GL_PATCH_VERTICES}} as target and a value which has to be in [1, {{enum|GL_MAX_PATCH_VERTICES}}]. The maximum number of patch vertices is implementation-dependent. The default value is three.
 
with {{enum|GL_PATCH_VERTICES}} as target and a value which has to be in [1, {{enum|GL_MAX_PATCH_VERTICES}}]. The maximum number of patch vertices is implementation-dependent. The default value is three.

Revision as of 21:28, 10 October 2012

Tessellation
Core in version 4.5
Core since version 4.0
Core ARB extension ARB_tessellation_shader

Definition

Since OpenGL 4.0 the specification defines tessellation to be "a process that reads a patch primitive and generates new primitives used by subsequent pipeline stages. The generated primitives are formed by subdividing a single triangle or quad primitive[..]".

The tessellation process is divided into three stages which form an optional part of the rendering pipeline, two of which are programmable and one which is fixed as follows (in order).

Tessellation control shader

This programmable stage executes an optional tessellation control shader. If no control shader is active in the current program or program pipeline, default values are used by the subsequent stage. Values most important for the tessellation process are the so called inner and outer tessellation levels. There exist two built-in 'output' arrays in the tessellation control language, gl_TessLevelInner[2]​ and gl_TessLevelOuter[4]​, which in part control how the subsequent stage generates new primitives.

Tessellation primitive generation

Primitive generation is a fixed-function stage responsible for creating a set of new primitives from the input patch. This stage is only executed if a tessellation evaluation shader is active in the current program or program pipeline. Primitive generation is affected by two factors:

  • the input primitive type defined by the subsequent evaluation shader which may be one of triangles​, quads​ or isolines​
  • the tessellation levels, which may have been altered by a control shader in the previous stage

Depending on the primitive type, the primitive generator evaluates a different number of tessellation levels and applies different tesselation algorithms. Each generated vertex is assigned a normalized position (i.e. in [0, 1]) denoted (u,v,w) or (u,v). The coordinates are accessible using the built-in in vec3 gl_TessCoord​ during tesselation evalutation where gl_TessCoord.xyz​ is equivalent to the triple (u,v,w).

Triangles

The first inner tessellation level and the first three outer tessellation levels are used. The algorithm is required to produce smaller triangles. The resulting vertex positions are barycentric coordinates, which specify weights of the vertices of the input triangle for which the condition u+v+w=1 holds.

Quads

For quads all six tessellation levels are used to subdivide the input rectangle into smaller triangles.

Isolines

They are only affected by the first two outer tessellation levels. The generator will create n independent lines, which will be subdivided into m segments with m+1 vertices, where:

m\,=OuterTessLevel[0]
n\,\,=OuterTessLevel[1]

The coordinates of the vertices are determined by subdividing the line along the u-axis and determining a constant value along the v-axis for every vertex on the current line using the formula:

0{,}{\frac  {1}{n}}{,}{\frac  {2}{n}}{,}..{,}{\frac  {n-1}{n}}

As can be seen, the the generator will not create a line at v=1. During isoline tessellation, the w-coordinate is ignored.

Tessellation evaluation shader

Patches

Tessellation stages operate on patches, a new primitive type denoted by the constant GL_PATCHES, which are simply arrays of vertices and user defined per-vertex attributes written by a vertex shader. The number of vertices per patch can be defined on the application-level using

void glPatchParameteri(GLenum pname​​, GLint value​​);
void glPatchParameterfv(GLenum pname​​, const GLfloat *values​​);

with GL_PATCH_VERTICES as target and a value which has to be in [1, GL_MAX_PATCH_VERTICES]. The maximum number of patch vertices is implementation-dependent. The default value is three.

Examples