Lab 9: Subdivision

Description

In this lab, you will use the OpenGL Tessellation Shader to perform subdivison on a coarse surface mesh.  This mesh will be composed of triangle primitives.  You will begin with starter code that comes with some basic shaders and generates a mesh composed of a single triangle.  Play with this code to learn how to use the tessellation shader to subdivide the single triangle mesh into a mesh composed of smaller triangles.  From there, you will need to create your own surface mesh for a cube centered at the origin.  The points in this mesh will also be points on the surface of a sphere centered at the origin.  Once you have the cube, you will edit the tessellation shaders in order to produce a smoother mesh whose points interpolate the surface of the sphere.  

Starter Code Download Here

Tips

  1. Make sure to read the documentation in the first reference.  Understand the different parts of the Tessellation Shader, their input/outputs, and how they are connected.
  2. The starter code will include comments to help direct what you might need to change or add in the cpp file.
  3. You will need to edit the Tessellation Control Shader and the Tessellation Evaluation Shader.  The following variables will be useful:
  1. TCS: Here you will set how much subdivision occurs on the edges and inside the triangle. Tessellation Inner and Outer levels:  There is one inner level for triangles and three outer levels.  These can be changed directly in the shader or using uniforms in your cpp file.
  2. TES: Here you will set the final positions of the new vertices generated by the primitive generator.  gl_in.[x]gl_position refers to the coordinate position of the original vertices. gl_TessCords refers to the barycentric coordinates of the new vertex.  gl_position is used to set the coordinate position of the new vertex.
  1. The normalize function will come in handy in your shader when interpolating your newly subdivided points onto the surface of the sphere.  Normalizing any point will move it to the surface of the sphere that is centered at the origin with radius 1.  Only normalize the spatial coordinates; not the w coordinate.  Set the w coordinate to 1 in this exercise.
  2. The skeleton code comes with no vertex transformations so you will need to specify your positions in clip coordinates or implement your own transformation.

References

  1. Tessellation Shader Documentation
  2. Tessellation Shader Tutorial
  3. Second Tessellation Shader Tutorial
  4. Subdivision Surfaces on Wikipedia

Cube Surface Mesh Vertices

Use these to create your cube surface mesh.  Modify them to fit within your coordinate system and don’t forget to change the glVertexAttribPointer call in lab9.cpp to adjust to the change from 2 coordinates per vertex to 3:

            -1.0f,-1.0f,-1.0f, // triangle 1 : begin

            -1.0f,-1.0f, 1.0f,

            -1.0f, 1.0f, 1.0f, // triangle 1 : end

            1.0f, 1.0f,-1.0f, // triangle 2 : begin

            -1.0f,-1.0f,-1.0f,

            -1.0f, 1.0f,-1.0f, // triangle 2 : end

            1.0f,-1.0f, 1.0f,

            -1.0f,-1.0f,-1.0f,

            1.0f,-1.0f,-1.0f,

            1.0f, 1.0f,-1.0f,

            1.0f,-1.0f,-1.0f,

            -1.0f,-1.0f,-1.0f,

            -1.0f,-1.0f,-1.0f,

            -1.0f, 1.0f, 1.0f,

            -1.0f, 1.0f,-1.0f,

            1.0f,-1.0f, 1.0f,

            -1.0f,-1.0f, 1.0f,

            -1.0f,-1.0f,-1.0f,

            -1.0f, 1.0f, 1.0f,

            -1.0f,-1.0f, 1.0f,

            1.0f,-1.0f, 1.0f,

            1.0f, 1.0f, 1.0f,

            1.0f,-1.0f,-1.0f,

            1.0f, 1.0f,-1.0f,

            1.0f,-1.0f,-1.0f,

            1.0f, 1.0f, 1.0f,

            1.0f,-1.0f, 1.0f,

            1.0f, 1.0f, 1.0f,

            1.0f, 1.0f,-1.0f,

            -1.0f, 1.0f,-1.0f,

            1.0f, 1.0f, 1.0f,

            -1.0f, 1.0f,-1.0f,

            -1.0f, 1.0f, 1.0f,

            1.0f, 1.0f, 1.0f,

            -1.0f, 1.0f, 1.0f,

            1.0f,-1.0f, 1.0f