Difference between revisions of "Tessellation"
(Tessellation done.) 
(Upgrade.) 

Line 7:  Line 7:  
}}  }}  
−  +  '''Tessellation''' is the stage in the OpenGL rendering pipeline where patches of vertex data are subdivided into smaller [[Primitive]]s. This process is governed by two shader stages and a fixedfunction stage.  
+  
+  {{stub}}  
== Overview ==  == Overview ==  
Line 16:  Line 18:  
{{mainTessellation Control Shader}}  {{mainTessellation Control Shader}}  
−  +  The first step of tessellation is the invocation of an optional tessellation control shader (TCS). The purpose of this stage is to do any special transformation on the patch and to determine how much tessellation the particular patch should have.  
+  
+  The TCS is optional. If no TCS is active in the current program or program pipeline, then the patch data is passed directly from the [[Vertex Shader]] invocations to the [[#Tessellation primitive generationtessellation primitive generation]] step. The amount of tessellation done in this case is taken from default values set into the context. These are defined by the following function:  
+  
+  void {{apifuncglPatchParameterfv}}(GLenum {{parampname}}, const GLfloat *{{paramvalues}});  
+  
+  When {{parampname}} is {{enumGL_PATCH_DEFAULT_OUTER_LEVEL}}, {{paramvalues}} is a 4element array of floats defining the four outer tessellation levels. When {{parampname}} is {{enumGL_PATCH_DEFAULT_INNER_LEVEL}}, {{paramvalues}} is a 2element array of floats defining the two inner tessellation levels.  
+  
+  These default values correspond to the TCS perpatch output variables {{codegl_TessLevelOuter[4]}} and {{codegl_TessLevelInner[2]}}.  
== Tessellation primitive generation ==  == Tessellation primitive generation ==  
−  Primitive generation is a fixedfunction stage responsible for creating a set of new primitives from the input patch. This stage is only executed if a  +  Primitive generation is a fixedfunction stage responsible for creating a set of new primitives from the input patch. This stage is only executed if a [#Tessellation evaluation shadertessellation evaluation shader]] (TES) is active in the current program or program pipeline. Primitive generation is affected by two factors: 
−  * the input primitive type defined by the subsequent  +  * the input primitive type defined by the subsequent TES which may be one of {{codetriangles}}, {{codequads}} or {{codeisolines}} 
−  * the tessellation levels,  +  * the tessellation levels, provided either by the TCS or the default values, as stated above. 
−  Depending on the primitive type, the primitive generator evaluates a different number of tessellation levels and applies different  +  Depending on the primitive type, the primitive generator evaluates a different number of tessellation levels and applies different tessellation 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 builtin {{codein vec3 gl_TessCoord}} during tesselation evalutation where {{codegl_TessCoord.xyz}} is equivalent to the triple (u,v,w). 
=== 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  +  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 [http://en.wikipedia.org/wiki/Barycentric_coordinates_%28mathematics%29#Barycentric_coordinates_on_triangles barycentric coordinates], which specify weights of the vertices of the input triangle for which the condition u + v + w = 1 holds. 
=== Quads ===  === Quads ===  
Line 35:  Line 45:  
=== Isolines ===  === Isolines ===  
−  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  +  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 m segments with m + 1 vertices, where: 
: <math>m\,= OuterTessLevel[0]</math>  : <math>m\,= OuterTessLevel[0]</math>  
Line 44:  Line 54:  
:<math>0{,}\frac{1}{n}{,}\frac{2}{n}{,} .. {,}\frac{n1}{n}</math>  :<math>0{,}\frac{1}{n}{,}\frac{2}{n}{,} .. {,}\frac{n1}{n}</math>  
−  As can be seen, the the generator will not create a line at  +  As can be seen, the the generator will not create a line at v = 1. During isoline tessellation, the wcoordinate is undefined. 
== Tessellation evaluation shader ==  == Tessellation evaluation shader ==  
{{Tessellation Evaluation Shader}}  {{Tessellation Evaluation Shader}}  
−  +  The tessellation primitive generator takes a primitive and tessellates it. However, it has no idea of the algorithm that you intend to use to compute the new positions/normals/texture coordinates/etc. It's a purely fixedfunction system.  
−  +  
−  +  The burden on computing the final position of all of the vertices in the tessellated patch falls to the tessellation evaluation shader (TES). Each TES invocation takes a coordinate representing where that vertex is within the tessellated patch, and each TES invocation can access every vertex output by the TCS as well as any perpatch data. The purpose of the TES is to actually do the hard part of tessellation: computing the position, texture coordinates, normals, and so forth, of all of the resultant vertices.  
−  +  The TES is rather like a vertex shader, in that each invocation operates on a distinct vertex within the tessellated patch. Also, the TES cannot cull vertices or in any way modify them.  
−  +  A TES is required to have tessellation at all.  
−  +  == Patches ==  
+  Tessellation stages operate on patches, a [[Primitiveprimitive type]] denoted by the constant {{enumGL_PATCHES}}. These are arrays of vertices and user defined pervertex attributes written by a vertex shader. The number of vertices per patch can be defined on the applicationlevel using:  
−  +  void {{apifuncglPatchParameteri}}(GLenum {{parampname}}, GLint {{paramvalue}});  
+  
+  with {{enumGL_PATCH_VERTICES}} as target and a value which has is on the halfopen range [1, {{enumGL_MAX_PATCH_VERTICES}}]. The maximum number of patch vertices is implementationdependent, but will never be less than 3.  
== Examples ==  == Examples ==  
−  
−  
[[Category:OpenGL Shading Language]]  [[Category:OpenGL Shading Language]]  
[[Category:Shaders]]  [[Category:Shaders]] 
Revision as of 20:40, 7 November 2012


OpenGL Rendering Pipeline

Tessellation is the stage in the OpenGL rendering pipeline where patches of vertex data are subdivided into smaller Primitives. This process is governed by two shader stages and a fixedfunction stage.
This article is a stub. You can help the OpenGL Wiki by expanding it. 
Contents
Overview
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
The first step of tessellation is the invocation of an optional tessellation control shader (TCS). The purpose of this stage is to do any special transformation on the patch and to determine how much tessellation the particular patch should have.
The TCS is optional. If no TCS is active in the current program or program pipeline, then the patch data is passed directly from the Vertex Shader invocations to the tessellation primitive generation step. The amount of tessellation done in this case is taken from default values set into the context. These are defined by the following function:
void glPatchParameterfv(GLenum pname, const GLfloat *values);
When pname is GL_PATCH_DEFAULT_OUTER_LEVEL, values is a 4element array of floats defining the four outer tessellation levels. When pname is GL_PATCH_DEFAULT_INNER_LEVEL, values is a 2element array of floats defining the two inner tessellation levels.
These default values correspond to the TCS perpatch output variables gl_TessLevelOuter[4] and gl_TessLevelInner[2].
Tessellation primitive generation
Primitive generation is a fixedfunction stage responsible for creating a set of new primitives from the input patch. This stage is only executed if a [#Tessellation evaluation shadertessellation evaluation shader]] (TES) is active in the current program or program pipeline. Primitive generation is affected by two factors:
 the input primitive type defined by the subsequent TES which may be one of triangles, quads or isolines
 the tessellation levels, provided either by the TCS or the default values, as stated above.
Depending on the primitive type, the primitive generator evaluates a different number of tessellation levels and applies different tessellation 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 builtin 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 independent lines, which will be subdivided into m segments with m + 1 vertices, where:
The coordinates of the vertices are determined by subdividing the line along the axis and determining a constant value along the axis for every vertex on the current line using the formula:
As can be seen, the the generator will not create a line at v = 1. During isoline tessellation, the wcoordinate is undefined.
Tessellation evaluation shader
Template:Tessellation Evaluation Shader
The tessellation primitive generator takes a primitive and tessellates it. However, it has no idea of the algorithm that you intend to use to compute the new positions/normals/texture coordinates/etc. It's a purely fixedfunction system.
The burden on computing the final position of all of the vertices in the tessellated patch falls to the tessellation evaluation shader (TES). Each TES invocation takes a coordinate representing where that vertex is within the tessellated patch, and each TES invocation can access every vertex output by the TCS as well as any perpatch data. The purpose of the TES is to actually do the hard part of tessellation: computing the position, texture coordinates, normals, and so forth, of all of the resultant vertices.
The TES is rather like a vertex shader, in that each invocation operates on a distinct vertex within the tessellated patch. Also, the TES cannot cull vertices or in any way modify them.
A TES is required to have tessellation at all.
Patches
Tessellation stages operate on patches, a primitive type denoted by the constant GL_PATCHES. These are arrays of vertices and user defined pervertex attributes written by a vertex shader. The number of vertices per patch can be defined on the applicationlevel using:
void glPatchParameteri(GLenum pname, GLint value);
with GL_PATCH_VERTICES as target and a value which has is on the halfopen range [1, GL_MAX_PATCH_VERTICES]. The maximum number of patch vertices is implementationdependent, but will never be less than 3.