GLSL Core tutorial–tessellation

Source: Internet
Author: User

Original: http://www.lighthouse3d.com/tutorials/glsl-core-tutorial/glsl-core-tutorial-tessellation/

Subdivision surfaces are a phase of a graphical pipeline that accepts patches as input, producing elements that can be points, lines, and triangles. A patch is a set of vertices that are computed at the vertex shader. Subdivision shader receives a set of transformed vertices. Patches, for example, are usually subdivided into smaller entities. Patches has a user-defined number of vertices compared to other OpenGL primitive types. Use the function Glpatchparameteri to set this value, which is used as a constant in the draw command.

Glpatchparameteri (Gl_patch_vertices, Verticesperpatch);

The Verticesperpatch must be an integer between the [1, GL_MAX_PATCH_VERTICES ] range. This constant value can be obtained with Glgetintergerv. Subdivision Surface pipeline has three sub-stages: Subdivision control, Tu Yuanshong, subdivision evaluation. The end-to-end stage is programmable. For example, we can write shader for them, and the second phase is fixed.

In the first stage, the subdivision control shader accepts a patch's vertex array as input, computes its attribute value for each vertex that generates the patch, and the result is stored in an array. Shader also needs to write the property values for each patch, which defines how much the patch is subdivided.

There are two types of patches: triangles and quads. However, it is important to note that the number of vertices of a patch is irrelevant to its type. For example, you can define a quad patch with a single vertex or a Bezier patch with 16 vertices. The degree of subdivision is controlled by the tessellation level. It can be set to 0 to a value that can be obtained with Glgetintergerv: Gl_max_tess_gen_level, this value is usually 64. The tessellation level controls the degree of subdivision of each patch edge and its interior, so the Quad patch has four external subdivisions, and the triangle patch has three. Similarly, the Quadrilateral has two internal subdivision values, and the triangles have one.

It is important to note that shader may ignore the set subdivision value, which, in this case, will use the default subdivision value, which can be obtained by the Glgetintegerv function. Degree of application The following function settings can be used to change these subdivision values.

Glpatchparameteri (Gl_patch_default_outer_level, Mydefaultouterlevel); Glpatchparameteri (GL_PATCH_DEFAULT_INNER_ level, mydefaultinnerlevel);

After the vertex property calculation and subdivision values are set, we are ready to go to the second stage: the generation of the entities. This phase is fixed, and its work is really to generate new vertices in patches. However, it is important to note that this stage does not know our patch, it acts on a temporary patch, its coordinates are as follows:

PS: In the first figure, Ol0-ol3 represents four external subdivisions of the quadrilateral, Il0-il1 is two internal subdivision values, and the right side is the same.

GLSL Core tutorial–tessellation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.