Tessellation ShadersMike [email protected] State Universitymjb -- January 5, 2012Oregon State UniversityComputer GraphicsWhy do we need a Tessellation step right in the pipeline?• You can perform adaptive subdivision based on a variety of criteria (size, curvature, etc.)• You can provide coarser models (≈ geometric compression)• You can apply detailed displacement maps without supplying equally detailed geometry• You can adapt visual quality to the required level of detailmjb -- January 5, 2012Oregon State UniversityComputer Graphics• You can create smoother silhouettesWhat patterns can the Tessellation shaders produce?Lines Quads (subsequently broken into triangles)TrianglesThe Tessellation Shaders: Where Do they Fit in the Pipeline?mjb -- January 5, 2012Oregon State UniversityComputer Graphics= Fixed Function= ProgrammableTessellation Shader OrganizationOne call per output vertex.Consumes the entire patch.Determines how much to tessellate. One call per patch.Tessellates the curve or surface into uvwcoordinates.Transformed xyz Patch Vertices from the Vertex ShaderNew Patch Vertices in xyz, How much to tessellate,Per-vertex attributesPatch Vertices and patch Attributesmjb -- January 5, 2012Oregon State UniversityComputer Graphicssurface into uvwcoordinates.One call per generated uvwvertex. Evaluate the curve or surface. Possibly apply a displacement map.Patch Vertices and Per-patch Attributesuvw vertices for the tessellated primitivesTopologyxyz verticesTessellation Shader OrganizationThe Tessellation Control Shader (TCS) transforms the input coordinates to a regular surface representation. It also computes the required tessellation level based on distance to the eye, screen space spanning, hull curvature, or displacement roughness. There is one invocation per output vertex.The Fixed-Function Tessellation Primitive Generator (TPG) generates semi-regular u-v-w coordinates.mjb -- January 5, 2012Oregon State UniversityComputer GraphicsThe Tessellation Evaluation Shader (TES) evaluates the surface in uvwcoordinates. It interpolates attributes and applies displacements. There is one invocation per generated vertex.There is a new “Patch” primitive – it is the face and its neighborhood:glBegin( GL_PATCHES )There is no implied order – that is user-given.glBegin( GL_PATCHES );glVertex3f( … );glVertex3f( … );glEnd( );In the OpenGL ProgramGLuint tcs = glCreateShader( GL_TESS_CONTROL_SHADER );GLuint tes = glCreateShader( GL_TESS_EVALUATION_SHADER );These have no implied topology – it’s up to how your shader interprets the orderglPatchParameteri( GL_PATCH_VERTICES, num );# vertices in each patchmjb -- January 5, 2012Oregon State UniversityComputer GraphicsCheck extension: “GL_ARB_tessellation_shader”In GLSL:#version 400#ension GL_ARB_tessellation_shader : enableIf you have a TCS, you must also have a Vertex ShaderTCS Inputsgl_in[ ] is an array of structures containing:gl_Positiongl_PointSizegl_ClipDistance[ ]gl_PatchVerticesInis the number of vertices in each patch and the dimension of gl_in[ ]gl_InvocationID tells you which output vertex you are working on, This must be the index into the gl_out[ ] array.mjb -- January 5, 2012Oregon State UniversityComputer Graphics#version 400#ension GL_ARB_tesselation_shader : enablebarrier( ) causes all instances of TCS’s to wait heregl_PatchVerticesInis the number of vertices in each patch and the dimension of gl_in[ ]gl_PrimitiveID is the number of primitives since last glBegin( ) (the first one is #0)TCS Outputsgl_out[ ] is an array of structures containing:gl_Position;gl_PointSize;gl_ClipDistance[ ];mjb -- January 5, 2012Oregon State UniversityComputer Graphicsgl_TessLevelOuter[4 ] is an array containing up to 4 edges of tessellation levelsgl_TessLevelInner[2] is an array containing up to 2 edges of tessellation levelsAll invocations of the TCS have read-only access to all the output information. barrier( ) causes all instances of TCS’s to wait herelayout( vertices = n ) out; Used to specify the number of vertices output to the TPGIn the TCSUser-defined variables defined per-vertex are qualified as “out”User-defined variables defined per-patch are qualified as “patch out”Defining how many vertices this patch will output:layout( vertices = 16 ) out;mjb -- January 5, 2012Oregon State UniversityComputer GraphicsTessellation Primitive GeneratorIs “fixed-function”, i.e., you can’t change its operation except by setting parametersConsumes all vertices from the TCS and emits tessellated triangles, quads, or linesOutputs positions as coordinates in barycentric (u,v,w)All three coordinates (u,v,w) are used for trianglesJust (u,v) are used for quads and isolinesmjb -- January 5, 2012Oregon State UniversityComputer GraphicsTES InputsReads one vertex of 0 <= (u,v,w) <= 1 coordinates in variable vec3 gl_TessCoordUser-defined variables defined per-vertex are qualified as “out”User-defined variables defined per-patch are qualified as “patch out”gl_in[ ] is an array of structures coming from the TCS containing:gl_Position;gl_PointSize;gl_ClipDistance[ ];mjb -- January 5, 2012Oregon State UniversityComputer Graphicslayout( , , , point_mode ) in; trianglesquadsisolines equal_spacingfractional_even_spacingfractional_odd_spacing ccwcwTessellation Primitive Generator (TPG)• Is “fixed-function”, i.e., you can’t change its operation except by setting parameters• Consumes all vertices from the TCS and emits vertices for the triangles, quads, or isolines patterns• TPG outputs a series of vertices as coordinates in barycentric (u,v,w) parametric space• All three coordinates (u,v,w) are used for trianglesmjb -- January 5, 2012Oregon State UniversityComputer Graphics• Just (u,v) are used for quads and isolinesTriangle patternQuad patternIsoline pattern(u=1,v=1)(u=0,v=1)OL0OL2OL3IL0vTES Output Topologies: the Quad Patternmjb -- January 5, 2012Oregon State UniversityComputer Graphics(u=0,v=0) (u=1,v=0)OL1OL0OL2IL1uv(u=1,v=1)(u=0,v=1)TES Output Topologies: the Isolines PatternTop line not drawnmjb -- January 5, 2012Oregon State UniversityComputer Graphics(u=0,v=0) (u=1,v=0)OL1OL0uvOL0 == 1 implies that you just want to draw a single curve(u=0,v=1,w=0)TES Output Topologies: the Triangle Patternmjb -- January 5, 2012Oregon State UniversityComputer
View Full Document