GLSL 高级教程 – Tessellation

本文介绍了图形管线中镶嵌阶段的基本概念及其工作原理。镶嵌处理接收补丁作为输入,并生成新的基本元素,如点、线或三角形。文章详细解释了补丁的概念、如何设置顶点数量、以及镶嵌管线的三个子阶段:控制、原始生成和评估。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Tessellation is a stage in the graphics pipeline that receives patches as inputs and generates new primitives which can be points, lines, or triangles.

A patch is an array of vertices whose attributes are computed by the vertex shader. For the vertex shader it is business as usual, it receives the patch vertices as inputs and outputs new vertices. The tessellation shaders receive the array of transformed vertices, i.e. the patch, and commonly subdivided in smaller primitives.

As opposed to other OpenGL primitive types, patches have a user-defined number of vertices. FunctionglPatchParameteri is used to set this value, which remains constant in draw calls, as follows:

1
glPatchParameteri( GL_PATCH_VERTICES, verticesPerPatch );

where verticesPerPatch must be an integer in [1, GL_MAX_PATCH_VERTICES]. This constant can be queried withglGetIntegerv.

The tessellation pipeline has three sub-stages: tessellation control, primitive generation, and tessellation evaluation. The first and last sub-stages are programmable, i.e. we can write shaders for them, whereas the second stage is fixed.

The first stage, the tessellation control shader, receives an array with the vertices of the input patch, and compute the attributes for each of the vertices that make up the output patch, also stored in an array. These shaders are also responsible to write per-patch attributes, which define the subdivision degree of the patch.

There are two types of patches: triangular and quads. Note, however, that the number of vertices in a patch is not related to its type. For instance, it’s possible to have a quad patch defined with a single vertex, or 16 vertices to define a Bézier patch.

The subdivision is controlled by the tessellation levels. These can be set from 0 toGL_MAX_TESS_GEN_LEVEL, a value which can be retrieved with glGetIntegerv. This value is commonly 64.

The tessellation levels control the subdivision of each side of the patch, as well as it’s interior. Hence, we have four outer tessellations for a quad, and three for a triangular patch. There are two inner tessellations levels for a quad, for triangular patches a single inner tessellation level is required.

Note that the shader may skip setting the tessellation levels, in which case, the default tessellation levels will be used. These default values can be queried withglGetIntegerv.

The application can set, and modify, these values as follows:

1
2
glPatchParameteri( GL_PATCH_DEFAULT_OUTER_LEVEL, myDefaultOuterLevel );
glPatchParameteri( GL_PATCH_DEFAULT_INNER_LEVEL, myDefaultInnerLevel );

After the vertices have been computed, and the tessellation levels set, we’re ready to go to stage 2, the primitive generation. This stage is fixed function, and its responsible for the actual generation of new vertices inside the patch. Note however that this stage has no knowledge of OUR patch, instead it works on a template patch with coordinates as follows:

The tessellation levels are defined to influence specific areas or edges as shown above.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值