Skip to content

Latest commit

 

History

History
175 lines (140 loc) · 5.97 KB

lecture07_tesselationShaders.asciidoc

File metadata and controls

175 lines (140 loc) · 5.97 KB

Tesselation Shaders

What are Tesselation Shaders?

  • Tessellation shaders allows us to subdivide a mesh into more a more detailed/dense mesh

  • Extra [OPTIONAL] stages in the pipeline

  • Advantages include:

    • simple/small representation in RAM can be amplified

      • GPU RAM in limited and is frequently a cause of delays

      • Generally, memory on modern hardware (CPU or GPU) is a restriction

      • both in terms of speed (bottleneck)

      • also in terms of size (limited RAM)

    • amount of detail of a mesh can be changed dynamically

      • for example, a sphere far away could be represented by around 12 vertices, but close up 10,000 vertices

      • always using 10,000 vertices would be expensive and inefficent

    • amount of detail can be changed semi-continuously

      • reduced popping

    • small representation in persistent storage (files/network)

      • smaller amounts of data sent from CPU→GPUs

Tesselation Shaders - examples

tessellated displacement
screenshot Fri Oct 03 17 35 49 2014 1914

Tesselation Shaders in OpenGL

  • Tesselation shaders are a relatively new feature in core OpenGL

    • introduced to core in OpenGL 4.x

    • prior to 4.x available as ARB extensions to OpenGL 3.2

  • We’ll need to get a higher version context

    • or use extensions (the harder way)

  • Our hardware will have to support this version, or the extension

  • We’ll have to move our GLSL to the new version

Tesselation outside of OpenGL

  • Tesseleation has a longer history than as part of OpenGL

  • We’ve always been able to write code to take a small set of vertices or triangles, and create more detailed geometry

  • For example:

    1. take a tetrahedron

    2. for each face (triangle), find the mid point of the 3 vertices

    3. move it away from a fixed "centre", to be a fixed distance from that centre (definition of a sphere)

    4. make 3 new (replacement triangles) from each pair of original vertices and the new one

    5. repeat for all the new triangles, until some limit

      • you can do this from a triangle, to create a circle, also

Tesselation Shaders in the OpenGL Pipeline

+------------------+
|  Vertex Shader   |
+--------+---------+
         |
+--------v----------------------+
|  Tesselation Control Shader   |    OPTIONAL (T)
+--------+----------------------+
         |
+--------v---------+
|  Tesselator      | fixed-function  OPTIONAL (T)
+--------+---------+
         |
+--------v-----------------------+
|  Tesselation Evaluation Shader |   OPTIONAL (T)
+--------+-----------------------+
         |
+--------v---------+
|  Geometry Shader |     OPTIONAL (G)
+--------+---------+
         |
+--------v---------+
|  Clipping        |
+--------+---------+
         |
+--------v---------+
|  Rasterisation   |
+--------+---------+
         |
+--------v---------+
|  Fragment Shader |
+--------+---------+
         |
+--------v---------+  +--------v---------+
|  Blending        >--|  Frame Buffer    |
+------------------+  +------------------+

GeomPatches

  • Tesselation shaders take in a new kind of primitive

    • Geometry Patches - GL_PATCHES

    • rather than triangles, lines, or points

    • e.g. glDrawArrays(GL_PATCHES, firstVert, vertCount);

  • We also have to tell OpenGL how many vertices belong to each patch

    • `glPatchParameteri(GL_PATCH_VERTICES, 16); `

Tesselation Control Shader

  • OPTIONAL - we haven’t had one until now

  • Executes once per incoming vertex

  • Transforms just that vertex

  • Programmable

  • Controls which points to subdivide

  • Controls How many times to subdivide each part of the patch

  • i.e. Controls the next (fixed-function) stage - the Tesselator

gl_TessLevelInner and gl_TessLevelOuter

gl_TessLevelInner

the number of “nested” primitives the

gl_TessLevelOuter

number of times to subdivide each edge

  • For both, a value of 1 means no subdivision

    • useful for testing your setup

gl_TessLevelInner and gl_TessLevelOuter table

Tessellation Level Table
Icosahedron to Sphere

Tesselator

  • Must have a Tesselation Evaluation Shader in our current (GLSL) program for this to run

  • Fixed-function

    • we can control it from the TCS and the TES

    • we can’t directly program it

Tesselation Evaluation Shader

  • What to do with the tessellated vertices

  • Receives more vertices than we had (in RAM, or in the Tesselation Control Shader)

  • Computes the interpolated positions and other per-vertex data from them

  • Programmable